Example #1
0
	void SceneModeler::calculateClasses(){
		setProgressText("calculate classes");
		
		this->means = new vector<double>;
		double min = 0;
		double max = 0;
		
		for(unsigned int i = 0; i < this->sceneLimits->size();i++){
			int next = (i != this->sceneLimits->size()-1) ? (*this->sceneLimits)[i+1]-1 : Ub(this->m_ptrData->getTrace());
			
			this->means->push_back(_double(this->m_ptrData->getMeanSlice((*this->sceneLimits)[i],next)));
			min = ((*this->means)[i] < min || min == 0) ? (*this->means)[i] : min;
			max = ((*this->means)[i] > max) ? (*this->means)[i] : max;
			setProgressValue(26 + (int)( (double)( 10.0 / this->sceneLimits->size()) * i));
		}
		this->numClasses = (int) floor((max - min) / _double(this->m_ptrData->getStandardDeviation()));
		double step = ((double)max - (double)min) / this->numClasses;
		
		this->classes = new vector< vector<int> >(this->numClasses);
		
		for(unsigned int i = 0; i < this->means->size();i++){
			if((*this->means)[i] != max){
				(*this->classes)[(int) floor(((*this->means)[i] - (double)min) / step)].push_back(i);
			}
			else{
				(*this->classes)[(int) floor(((*this->means)[i] - (double)min) / step)-1].push_back(i);
			}
			setProgressValue(36 + (int)( (double) ( 15.0 / this->means->size()) * i));
		}
	}
Example #2
0
cvector FFT::ifft(const cvector &vector)
{
	const int N = VecLen(vector);
	
	fftw_complex *in, *out;
    fftw_plan p;
    
    in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    for(int i = Lb(vector); i<=Ub(vector); ++i)
    {
    	in[i-Lb(vector)][0] = _double(Re(vector[i]));
    	in[i-Lb(vector)][1] = _double(Im(vector[i]));
    }
    p = fftw_plan_dft_1d(N, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
    
    fftw_execute(p); /* repeat as needed */
    
    fftw_destroy_plan(p);
    cvector ret(0, N-1);
    const cxsc::complex n(1.0/N, 0.0);
    for(int i = 0; i<N; ++i)
    {
    	ret[i] = cxsc::complex(out[i][0], out[i][1]) * n;
    }
    fftw_free(in); fftw_free(out);
    return ret;
}
Example #3
0
	int SceneModeler::getStateFromTrace(Trace &_data,real value){
		if(_data.getMinimum() == value) { return 0; }
		
		real range = _data.getMaximum() - _data.getMinimum();
		int num = (int) floor(_double(range) / _double(_data.getStandardDeviation()));
		real stepSize = range / num;
		
		return (int) _double(( value - _data.getMinimum() ) / stepSize);
	}
void GeneticFrameModelerWidget::updateGUI()
{
	// Copy values from model to GUI fields
	ComputationParameters params = modeler->getParameters();
	numstatesEdit->setValue(params.getInt(GeneticFrameModeler::PARAM_NUMSTATES));
	numdstepsEdit->setValue(params.getInt(GeneticFrameModeler::PARAM_NUMDSTEPS));
	numautocEdit->setValue(params.getInt(GeneticFrameModeler::PARAM_AUTOC));
	numiterationsEdit->setValue(params.getInt(GeneticFrameModeler::PARAM_NUMITERATIONS));
	numpoolEdit->setValue(params.getInt(GeneticFrameModeler::PARAM_NUMPOOLSIZE));
	mutBlock->setValue( _double( params.getReal( GeneticFrameModeler::PARAM_MUTBLOCK) ) );
	mutInverse->setValue( _double( params.getReal( GeneticFrameModeler::PARAM_MUTINVERSE) ) );
	mutShuffle->setValue( _double( params.getReal( GeneticModeler::PARAM_MUTSHUFFLE) ) );
	mutSwap->setValue( _double( params.getReal( GeneticFrameModeler::PARAM_MUTSWAP) ) );
	mutCrossover->setValue( _double( params.getReal( GeneticFrameModeler::PARAM_MUTCROSSOVER) ) );
	framelevel->setValue( params.getInt(GeneticFrameModeler::PARAM_FRAMELEVEL));
}
void StochasticProcessWidget::updateAutocorrelationCurve() {
	if (!process) {
		return;
	}

	int newLength = upToSpin->value();
	rvector autoCorrelation =
			process->getAutocorrelation(newLength);

	int size = Ub(autoCorrelation)
			- Lb(autoCorrelation) + 1;
	double *xValues = new double[size];
	double *yValues = new double[size];

	int i = 0;
	for (int j = Lb(autoCorrelation); j
			<= Ub(autoCorrelation); j++) {
		xValues[i] = j;
		yValues[i] = _double(autoCorrelation[j]);
		i++;
	}

	if (correlationCurve) {
		correlationCurve->detach();
		delete correlationCurve;
	}

	correlationCurve = new QwtPlotCurve("Autocorrelation");
	correlationCurve->setData(xValues, yValues, size);
	correlationCurve->attach(autocorrelationPlot);
	autocorrelationPlot->replot();

	delete[] xValues;
	delete[] yValues;
}
void StochasticProcessWidget::updateTransitionColors() {
	int distCount = distGraphTable->columnCount() - 1;
	QColor cellColor;

	int rowLb = Lb(transitionMatrix, 1);
	int colLb = Lb(transitionMatrix, 2);

	for (int i = 0; i < distCount; i++) {
		for (int j = 0; j
				< transitionTable->columnCount(); j++) {
			QTableWidgetItem *item =
					transitionTable->item(i, j);
			if (!item) {
				continue;
			}

			double
					value =
							_double(mid(transitionMatrix[rowLb + i][colLb + j]));
			int hueValue = (int)round(255.0
					/ ((double)distCount / (double)i));
			cellColor.setHsv(hueValue, (int)floor(90.0
					* sqrt(value)), 255);
			item->setBackgroundColor(cellColor);
		}
	}
}
void StochasticProcessWidget::setupDistributionTable(
		const imatrix & distributionMatrix) {
	const int distLb = Lb(distributionMatrix, 1);
	const int distUb = Ub(distributionMatrix, 1);
	const int valueLb = Lb(distributionMatrix, 2);
	const int valueUb = Ub(distributionMatrix, 2);
	const int distCount = distUb - distLb + 1;
	const int valueCount = valueUb - valueLb + 1;

	distTable->setRowCount(valueCount);
	distTable->setColumnCount(distCount);

	QStringList columnHeaders;
	for (int i = distLb; i <= distUb; i++) {
		columnHeaders << QString("S%1").arg(i);
	}

	distTable->setHorizontalHeaderLabels(columnHeaders);

	QStringList rowHeaders;
	for (int i = valueLb; i <= valueUb; i++) {
		rowHeaders << QString("%1").arg(i);
	}

	distTable->setVerticalHeaderLabels(rowHeaders);

	for (int r = distLb; r <= distUb; r++) {
		for (int c = valueLb; c <= valueUb; c++) {
			double
					inf =
							_double(Inf(distributionMatrix[r][c]));
			double
					sup =
							_double(Sup(distributionMatrix[r][c]));

			QString itemText = QString("%1\n%2").arg(sup).arg(inf);

			QTableWidgetItem *newItem =
					new QTableWidgetItem(itemText);
			distTable->setItem(c - valueLb, r - distLb,
					newItem);
		}
	}
}
void GeneticFrameModelerWidget::loadModel()
{
	ComputationParameters params;

	params.setInt(GeneticFrameModeler::PARAM_NUMDSTEPS, loadInt(GeneticFrameModeler::PARAM_NUMDSTEPS));
	numdstepsEdit->setValue(loadInt(GeneticFrameModeler::PARAM_NUMDSTEPS));

	params.setInt(GeneticFrameModeler::PARAM_NUMSTATES, loadInt(GeneticFrameModeler::PARAM_NUMSTATES));
	numstatesEdit->setValue(loadInt(GeneticFrameModeler::PARAM_NUMSTATES));

	params.setInt(GeneticFrameModeler::PARAM_AUTOC, loadInt(GeneticFrameModeler::PARAM_AUTOC));
	numautocEdit->setValue(loadInt(GeneticFrameModeler::PARAM_AUTOC));

	params.setInt(GeneticFrameModeler::PARAM_NUMITERATIONS, loadInt(GeneticFrameModeler::PARAM_NUMITERATIONS));
	numiterationsEdit->setValue(loadInt(GeneticFrameModeler::PARAM_NUMITERATIONS));

	params.setInt(GeneticFrameModeler::PARAM_NUMPOOLSIZE, loadInt(GeneticFrameModeler::PARAM_NUMPOOLSIZE));
	numpoolEdit->setValue(loadInt(GeneticFrameModeler::PARAM_NUMPOOLSIZE));

	params.setReal(GeneticFrameModeler::PARAM_MUTBLOCK, loadReal(GeneticFrameModeler::PARAM_MUTBLOCK));
	mutBlock->setValue(_double ( loadReal(GeneticFrameModeler::PARAM_MUTBLOCK) ));

	params.setReal(GeneticFrameModeler::PARAM_MUTINVERSE, loadReal(GeneticFrameModeler::PARAM_MUTINVERSE));
	mutInverse->setValue(_double ( loadReal(GeneticFrameModeler::PARAM_MUTINVERSE) ));

	params.setReal(GeneticFrameModeler::PARAM_MUTSHUFFLE, loadReal(GeneticFrameModeler::PARAM_MUTSHUFFLE));
	mutShuffle->setValue(_double ( loadReal(GeneticFrameModeler::PARAM_MUTSHUFFLE) ));

	params.setReal(GeneticFrameModeler::PARAM_MUTSWAP, loadReal(GeneticFrameModeler::PARAM_MUTSWAP));
	mutSwap->setValue(_double ( loadReal(GeneticFrameModeler::PARAM_MUTSWAP) ));

	params.setReal(GeneticFrameModeler::PARAM_MUTCROSSOVER, loadReal(GeneticFrameModeler::PARAM_MUTCROSSOVER));
	mutCrossover->setValue(_double ( loadReal(GeneticFrameModeler::PARAM_MUTCROSSOVER) ));

	params.setInt( GeneticFrameModeler::PARAM_FRAMELEVEL, loadInt(GeneticFrameModeler::PARAM_FRAMELEVEL));
	framelevel->setValue( loadInt( GeneticFrameModeler::PARAM_FRAMELEVEL ) );

	modeler->setParameters(params);
}
Example #9
0
real Cut26(const real& x){
    // y = Cut26(x) liefert ein y, das mit den ersten 26 Mantissenbits
    // von x übereinstimmt, das hidden bit ist dabei mitgezählt!
    // Die restlichen 53-26=27 Mantissenbits werden auf Null gesetzt.
  help_real y;
  y.f = _double(x);
#if INTEL
  y.intern[3] &= 248;
  y.intern[0] = y.intern[1] = y.intern[2] = 0;
#else
  y.intern[4] &= 248;
  y.intern[7] = y.intern[6] = y.intern[5] = 0;
#endif
  return real(y.f);
}
Example #10
0
	SSMProcess* AutoSMPModeler::computeModel(int n_states){
		const rvector &trace = m_ptrData->getTrace();
		const real minValue = m_ptrData->getMinimum();
		const real maxValue = m_ptrData->getMaximum();
		const int numStates = n_states;
		const real stepWidth = (maxValue - minValue) / real(numStates); 
		
		// construct index sequence
		intvector index(Lb(trace), Ub(trace));
		for(int i = Lb(trace); i<=Ub(trace); ++i)
		{
			const real value = trace[i];
			index[i] = (int)_double((value - minValue)/stepWidth);
			if(index[i] == 0) index[i] = numStates + 1;
		}
		this->indexSequence = index;
		return modelFromIndexSequence(index);
	}
void WorkloadDistributionWidget::updateDistributionGraph(){
	const rvector workloadDistribution = mid( this->workloads->getWorkloadVector() );

	int size = Ub( workloadDistribution ) - Lb( workloadDistribution ) + 1;
	double *xValues = new double[size];
	double *yValues = new double[size];

	int i = 0;
	for (int j = Lb( workloadDistribution ); j <= Ub( workloadDistribution ); j++) {
		xValues[i] = j;
		yValues[i] = _double( workloadDistribution[j] );
		i++;
	}

	distributionCurve = new QwtPlotCurve( "Workload Distribution" );
	distributionCurve->setData(xValues, yValues, size);
	distributionCurve->attach(distGraph);
	distGraph->replot();

	delete[] xValues;
	delete[] yValues;
}
Example #12
0
static const xreal xeta(const xcomplex &z)
{
  return _double(cxsc::Epsilon);
}
Example #13
0
static const xreal xnorm(const xcomplex &newz)
{
  return _double(abs2(newz));
}
Example #14
0
static const xreal xabs(const xcomplex &newz)
{
  return _double(abs(newz));
}
Example #15
0
	void SceneModeler::computeIndexSequence(){
		setProgressText("compute index sequence");
		rvector rawData(m_ptrData->getTrace());
		int menge = 0;
		for(unsigned int i = 0;i < this->classes->size(); i++){
			if((*this->classes)[i].size() != 0){ menge += 1; }
		}
		
		this->classTraces = new vector< Trace* >;
		this->classData = new vector< vector <double>* >(menge);
		
		this->transitionDataClasses = new vector< int >(Ub(this->m_ptrData->getTrace())+1);
		this->numStates = new int[this->numClasses];
		this->classMap = new int[this->numClasses];
		unsigned int count = 0;
		
		/*creating vectors containing:
			-a map that compensates the empty classes(this->classMap)
			-the specific class for each datapoint(this->transitionDataClasses)*/
		
		for(unsigned int i = 0;i < this->classes->size(); i++){
			
			if((*this->classes)[i].size() != 0){
				this->classMap[i] = i-count;
				(*this->classData)[this->classMap[i]] = new vector<double>;
				
				for(unsigned int n = 0; n < (*this->classes)[i].size(); n++){
					int ende = ((unsigned int) (*this->classes)[i][n] != this->sceneLimits->size()-1) ? ((int) (*this->sceneLimits)[((int) (*this->classes)[i][n])+1]) -1 : Ub(this->m_ptrData->getTrace());;
					for(int x = (*this->sceneLimits)[(*this->classes)[i][n]]; x <= ende; x++){
						(*this->classData)[this->classMap[i]]->push_back(_double(rawData[x]));
						(*this->transitionDataClasses)[x] = i;
					}
				}
				
				double max = 0;
				double min = 0;
				
				for(unsigned int n = 0; n < (*this->classData)[this->classMap[i]]->size();n++){
					min = (n == 0 || min > (*(*this->classData)[this->classMap[i]])[n]) ? (*(*this->classData)[this->classMap[i]])[n] : min;
					max = (max < (*(*this->classData)[this->classMap[i]])[n]) ? (*(*this->classData)[this->classMap[i]])[n] : max;
				}
				
				rvector dump(0,(*this->classData)[this->classMap[i]]->size()-1);
				for(unsigned int n=0;n< (*this->classData)[this->classMap[i]]->size();n++){
					dump[n] = (*(*this->classData)[this->classMap[i]])[n];
				}
				this->classTraces->push_back(new Trace(dump));
				
				if( _double(this->classTraces->back()->getStandardDeviation()) == 0 ){
					this->numStates[i] = 1;
				}
				else{
					this->numStates[i] = (int) floor((max - min) /	_double(this->classTraces->back()->getStandardDeviation()));
				}
					
				
			}
			else{
				this->numStates[i] = 0;
				this->classMap[i] = -1;
				count++;
			}
			setProgressValue(41+ (int)( (double) (20.0 / this->classes->size()) * i));
		}
		
		/*creating vector containing empty states*/
		this->strippedStates = new vector< vector <int>* >(this->classes->size());
		
		for(unsigned int i=0; i < this->classes->size();i++){
			(*this->strippedStates)[i] = new vector<int>;
			
			if(this->classMap[i] != -1){
				intvector intvec(0,Ub((*this->classTraces)[this->classMap[i]]->getTrace()));
				
				for(int c=0;c <= Ub(intvec);c++){
					intvec[c] = this->getStateFromTrace((*(*this->classTraces)[this->classMap[i]]),(*this->classTraces)[this->classMap[i]]->getTrace()[c]);
				}
				
				rmatrix* tmp = new rmatrix(AbstractDiscreteSSMPModeler::computeTransition(intvec));
				
				for(int n=0;n < this->numStates[i];n++){
					real sum=0;
					for(int x=0;x < this->numStates[i];x++){
						sum += (*tmp)[cxsc::Row(n)][x];
					}
					if(((int) cxsc::_double(sum)) != 1){ (*this->strippedStates)[this->classMap[i]]->push_back(n); }
				}
				
				delete tmp;
			}
			setProgressValue(61 + (int)( (double) (20.0 / this->classes->size()) * i));
		}
		
		/*creating intvector containing states for each datapoint*/
		this->transitionDataStates = new intvector(0,Ub(m_ptrData->getTrace()));
		
		for(int i=0; i <= Ub(m_ptrData->getTrace());i++){
			int stateBuff=0;
			for(int n=0;n < (*this->transitionDataClasses)[i];n++){
				stateBuff += this->numStates[n]-(*this->strippedStates)[n]->size();
			}
			
			(*this->transitionDataStates)[i] = (stateBuff+ this->getStateFromTrace( ((*(*this->classTraces)[this->classMap[(*this->transitionDataClasses)[i]]])) , m_ptrData->getTrace()[i] ) );
			setProgressValue(81 + (int)( (double) ( 15.0 / Ub( m_ptrData->getTrace() )) * i));
		}
	}
bool StochasticProcessWidget::addIntervalDistributionToGraph(
		QString title, ivector values) {
	rvector inf = Inf(values);
	rvector sup = Sup(values);

	intervalDists.push_back(values);

	////////////////////////////////////////////
	// Update distribution graph
	////////////////////////////////////////////
	QwtPlotCurve *infCurve =
			PlotUtil::constructCurveFromRVector(inf);
	QwtPlotCurve *supCurve =
			PlotUtil::constructCurveFromRVector(sup);

	infCurve->attach(distGraph);
	supCurve->attach(distGraph);

	infCurves.push_back(infCurve);
	supCurves.push_back(supCurve);

	int columnIndex = distGraphTable->columnCount() - 1;
	distGraphTable->setColumnCount(columnIndex + 2);

	for (int i = 0; i <= 5; i++) {
		distGraphTable->setItem(
				i,
				columnIndex + 1,
				distGraphTable->takeItem(i, columnIndex));
	}

	QTableWidgetItem *valueItem = new QTableWidgetItem(QString("%1").arg(columnIndex+1));
	valueItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	valueItem->setCheckState(Qt::Checked);
	valueItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(0, columnIndex, valueItem);

	double
			average =
					_double(CompUtil::getExpectationValue(values));

	QwtPlotMarker *avgMarker = new QwtPlotMarker();
	avgMarker->setLineStyle(QwtPlotMarker::VLine);
	avgMarker->setXValue(average);
	avgMarker->attach(distGraph);
	avgMarkers.push_back(avgMarker);

	QTableWidgetItem *avgItem = new QTableWidgetItem(QString("%1").arg(average));
	avgItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	avgItem->setCheckState(Qt::Checked);
	avgItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(1, columnIndex, avgItem);

	distGraphTable->resizeRowsToContents();

	double
			stdDev =
					_double(CompUtil::getDistributionStandardDeviation(values));

	QwtPlotMarker *lowerStdDevMarker =
			new QwtPlotMarker();
	lowerStdDevMarker->setLineStyle(QwtPlotMarker::VLine);
	lowerStdDevMarker->setXValue(average - stdDev);
	lowerStdDevMarker->attach(distGraph);

	QwtPlotMarker *upperStdDevMarker =
			new QwtPlotMarker();
	upperStdDevMarker->setLineStyle(QwtPlotMarker::VLine);
	upperStdDevMarker->setXValue(average + stdDev);
	upperStdDevMarker->attach(distGraph);

	stdDevMarkers.push_back(PlotMarkerPair(
			lowerStdDevMarker, upperStdDevMarker));

	QTableWidgetItem *stdDevItem =
			new QTableWidgetItem(QString("%1").arg(stdDev));
	stdDevItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	stdDevItem->setCheckState(Qt::Checked);
	stdDevItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(2, columnIndex, stdDevItem);

	QTableWidgetItem
			*statProbItem =
					new QTableWidgetItem(QString("%1").arg(_double(statProbs[columnIndex + Lb(statProbs)])));
	statProbItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(3, columnIndex,
			statProbItem);

	QTableWidgetItem *rangeItem = new QTableWidgetItem(QString("%1 - %2").arg(Lb(values)).arg(Ub(values)));
	rangeItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(4, columnIndex, rangeItem);

	QTableWidgetItem *selectAllItem =
			new QTableWidgetItem(tr("Show All"));
	selectAllItem->setFlags(Qt::ItemIsUserCheckable
			| Qt::ItemIsEnabled);
	selectAllItem->setCheckState(Qt::Checked);
	selectAllItem->setTextAlignment(Qt::AlignCenter);
	distGraphTable->setItem(5, columnIndex,
			selectAllItem);

	////////////////////////////////////////////
	// Update distribution table
	////////////////////////////////////////////
	int lb = Lb(values);
	int ub = Ub(values);
	int vectorSize = ub - lb + 1;
	int newDistRowCount = (int)_double(max(
			distTable->rowCount(), vectorSize + lb));
	distTable->setRowCount(newDistRowCount);
	for (int i = 0; i < newDistRowCount; i++) {
		distTable->setVerticalHeaderItem(i,
				new QTableWidgetItem(QString("%1").arg(i)));
	}

	columnIndex = distTable->columnCount();
	distTable->setColumnCount(columnIndex + 1);

	for (int i = lb; i <= ub; i++) {
		QTableWidgetItem
				*newItem =
						new QTableWidgetItem(QString("%1\n%2").arg(_double(sup[i - lb])).arg(_double(inf[i - lb])));
		distTable->setItem(i, columnIndex, newItem);
	}

	return true;
}