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);
		}
	}
}
Beispiel #3
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;
}
 ECDataInputPolicy(unsigned long L_rec,
                   const typename EC_Dscr::aEC & EC,
                   Hash::Hash_Type Hash_type)
     : StaticDataInputPolicy(L_rec,
                             (Lb(EC.getOrder()) / 8) - L_rec,
                             Lb(EC.getOrder()) / 8,
                             Hash_type)
     {}
Beispiel #5
0
cvector FFT::ifft(cvector vector, const int size)
{
	const int end = Ub(vector);
	cxsc::Resize(vector, Lb(vector), Lb(vector)+size-1);
	for(int i = end+1; i<=Ub(vector); ++i)
		vector[i] = cxsc::complex(0.0, 0.0);
	return ifft(vector);
}
Beispiel #6
0
ivector Blow ( const ivector& x, real eps )                     // Epsilon deflation
{   //------------------
    int     i;
    ivector h(Lb(x),Ub(x));

    for (i = Lb(x); i <= Ub(x); i++) h[i] = Blow(x[i],eps);
    return h;
}
Beispiel #7
0
extern double
clampf(			/* histogram clamping function */
	double	Lw
)
{
	double	bLw, ratio;

	bLw = BLw(Lw);		/* apply current brightness map */
	ratio = what2do&DO_HSENS ? htcontrs(Lb(bLw))/htcontrs(Lw) : Lb(bLw)/Lw;
	return(ratio/(Lb1(bLw)*(Bldmax-Bldmin)*Bl1(Lw)));
}
Beispiel #8
0
	void accumulate(const M &op1, const M &op2)
	{
		// Multiply matrices
		for(int i = Lb(op1,1); i<=Ub(op1,1); ++i)
		{
			for(int j = Lb(op2,1); j<=Ub(op2,1); ++j)
			{
				P& dotaccu = m_accu[i-m_lb1][j-m_lb2];
				cxsc::accumulate(dotaccu, op1[i], op2[Col(j)]);
			}
		}
	}
Beispiel #9
0
rmatrix mid ( imatrix& A )                              // Matrix of midpoints
{                                                       //--------------------
  int i,j;
  int lbi = Lb(A,1), ubi = Ub(A,1);
  int lbj = Lb(A,2), ubj = Ub(A,2);
  rmatrix B(lbi,ubi,lbj,ubj);

  for (i = lbi; i <= ubi; i++)
    for (j = lbj; j <= ubj; j++)
      B[i][j] = mid(A[i][j]);
  return B;
}
Beispiel #10
0
imatrix Id ( imatrix& A )                          // Interval identity matrix
{                                                  //-------------------------
  int i,j;
  int lbi = Lb(A,1), ubi = Ub(A,1);
  int lbj = Lb(A,2), ubj = Ub(A,2);
  imatrix B(lbi,ubi,lbj,ubj);

  for (i = lbi; i <= ubi; i++)
    for (j = lbj; j <= ubj; j++)
      B[i][j] = _interval( (i==j) ? 1.0 : 0.0 );
  return B;
}
Beispiel #11
0
	void PronyMethod::setMuMatrix(){
		this->mu = new rvector(RMatrixUtils::eigLR(mid(this->smp_->getTransitionMatrix()),0.000005));
		
		this->imat = new imatrix( 0, this->states-1, 0, this->states-1 );
		for(int i = Lb((*this->imat),1); i <= Ub((*this->imat),1); i++){
			for(int c = Lb((*this->imat),2); c <= Ub((*this->imat),2); c++){
				if(i==0)
					(*this->imat)[i][c] = interval(1.0,1.0);
				else
					(*this->imat)[i][c] = interval( RealUtils::rPow( (*this->mu)[c] , i ) , RealUtils::rPow( (*this->mu)[c] , i ) );
			}
		}
	}
Beispiel #12
0
	void PronyMethod::verifyResult(){
		ivector rightside(0,this->states-1);
		for(int i = Lb( rightside ); i <= Ub( rightside ); i++){
			rightside[i] = interval( (*this->a)[i], (*this->a)[i] );
		}
		
		this->coeff = new ivector(0,this->states-1);
		for(int i = Lb( (*this->coeff) ); i <= Ub( (*this->coeff) ) ; i++){
			(*this->coeff)[i] = interval( 0.0 , 0.0 );
		}
		
		ILinSys l;
		l.ILinSolve(*this->imat,rightside,*this->coeff,this->err);
	}
Beispiel #13
0
cvector FFT::fconv(const cvector &a, const cvector &b)
{
	const int neededSize= VecLen(a) + VecLen(b) -1;
	int size = 1;
	while( size <= neededSize) size *= 2;
	
	cvector af = FFT::fft(a, size);
	cvector bf = FFT::fft(b, size);
	cvector cf(Lb(af), Ub(af));
	for(int i = Lb(cf); i<=Ub(cf); ++i)
		cf[i] = af[i] * bf[i];
	cvector result = FFT::ifft(cf);
	cxsc::Resize(result, Lb(result)+1, Lb(result) + neededSize-1);
	return result;
}
ivector ISMPWHWorkload::computeLI( IMatrixPolynomial ll)
{
	const int m = Ub(ll[0],1) - Lb(ll[0],1) +1;
    ivector rechte_seite(1, m ), ergebnis(1, m );
    imatrix linke_seite( 1, m, 1, m ), inverse(1, m, 1, m );
	imatrix l = ll.sum();
    for (int i = 1; i < m; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (i == j)
                linke_seite[i][j] = l[i][j] - 1.0;
            else
                linke_seite[i][j] = l[j][i];
        }
        
    }
    for(int i = 1; i<=m ; ++i)
    	linke_seite[m][i] = 1.0;

    inverse = IMatrixUtils::invert(linke_seite);
    for ( int i = 1; i < m; i++ ) rechte_seite[i] = 0.0;
    rechte_seite[m] = 1.0;
    ergebnis = inverse * rechte_seite;

    return ergebnis;

}
void WorkloadDistributionWidget::setupDistributionTable(){
	const ivector wlvector = this->workloads->getWorkloadVector();
	const int distLb = Lb( wlvector );
	const int distUb = Ub( wlvector );
	const int distCount = distUb - distLb + 1;

	distTable->setRowCount(distCount);

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

	distTable->setVerticalHeaderLabels(rowHeaders);

	for (int i = distLb; i <= distUb; i++) {
			stringstream strStr;
			strStr << Scientific << SetPrecision(15,16) << Sup(wlvector[i]) << endl
					<< Scientific << SetPrecision(15,16) << Inf(wlvector[i]);

			QString itemText = QString::fromStdString(strStr.str());
			QTableWidgetItem *newItem =	new QTableWidgetItem(itemText);
			distTable->setItem(i , 0 , newItem);
	}

	distTable->resizeRowsToContents();
}
Beispiel #16
0
	interval PronyMethod::computeAutocorrelation(int x){
		interval ret( 0.0, 0.0 );
		for(int i = Lb( (*this->coeff) ); i <= Ub( (*this->coeff) ); i++){
			ret += (*this->coeff)[i] * RealUtils::rPow( (*this->mu)[i-1] , x) ;
		}
		return ret;
	}
Beispiel #17
0
static void
check2do(void)		/* check histogram to see what isn't worth doing */
{
	double	sum;
	double	b, l;
	register int	i;

					/* check for within display range */
	if (bwmax - bwmin <= Bldmax - Bldmin)
		what2do |= DO_LINEAR;
					/* determine if veiling significant */
	if (bwmax - bwmin < 4.5)		/* heuristic */
		what2do &= ~DO_VEIL;

	if (!(what2do & (DO_ACUITY|DO_COLOR)))
		return;
					/* find 5th percentile */
	sum = histot*0.05;
	for (i = 0; i < HISTRES; i++)
		if ((sum -= bwhist[i]) <= 0)
			break;
	b = (i+.5)*(bwmax-bwmin)/HISTRES + bwmin;
	l = Lb(b);
					/* determine if acuity adj. useful */
	if (what2do&DO_ACUITY &&
			hacuity(l) >= (inpres.xr/sqrt(ourview.hn2) +
			inpres.yr/sqrt(ourview.vn2))/(2.*180./PI))
		what2do &= ~DO_ACUITY;
					/* color sensitivity loss? */
	if (l >= TopMesopic)
		what2do &= ~DO_COLOR;
}
Beispiel #18
0
//----------------------------------------------------------------------------
// Checks if the diameter of the interval vector 'v' is less or equal to 'n'
// ulps. Ulp is an abbreviation for: units in the last place of the mantissa.
//----------------------------------------------------------------------------
int UlpAcc ( ivector& v, int n )
{
    int k, upper;

    for (k = Lb(v), upper = Ub(v); (k < upper) && UlpAcc(v[k],n); k++);
    return UlpAcc(v[k],n);
}
Beispiel #19
0
interval FLevy2D::operator () (const LabBox & X) const
{
  n_interval_calls++;

  ivector Box = X.Box;
  int a = Lb (Box), z = Ub (Box);
  interval isum, jsum, hh;
  isum = 0.0;
  jsum = 0.0;
  for (int i = 1; i <= 5; i++)
  {
    isum = isum + double(i) * cos (double(i - 1) * Box[a] + double(i));
    jsum = jsum + double(i) * cos (double(i + 1) * Box[z] + double(i));
  }

                    // Avoid real con-
  hh = isum * jsum + sqr (Box[a] + Center1) +
                    // version error
    sqr (Box[z] + Center2);
    hh += GlobalMax;  
  // TEMPERATURE = 1, 4, 40, 400, 4000
  interval result = exp (-hh / Temperature);

  return (UsingLogDensity) ? ln (result) : result;
}
Beispiel #20
0
interval FLevy2D_Lkl_Tfrom1data::operator () (const interval & X) const
{
  int a = Lb (Data), z = Ub (Data);
  interval isum, jsum, hh;
  isum = 0.0;
  jsum = 0.0;
  for (int i = 1; i <= 5; i++)
  {
    isum =
      isum + double (i) * cos (double (i - 1) * Data[a] + double (i));
    jsum =
      jsum + double (i) * cos (double (i + 1) * Data[z] + double (i));
  }
                    // Avoid real con-
  hh = isum * jsum + sqr (Data[a] + Center1) +
                    // version error
    sqr (Data[z] + Center2);
  hh += GlobalMax;

   // TEMPERATURE = 1, 4, 40, 400, 4000
  interval result = exp (-hh / X);

  result /= sqr (X);
  //result /= X;
  return (UsingLogDensity) ? ln (result) : result;
}
Beispiel #21
0
real FLevy2D_Lkl_Tfrom1data::operator () (const real & X) const
{
  int a = Lb (Data), z = Ub (Data);
  // here we simply take the mid-point of the data to get thin data
  rvector realData = mid (Data);
  real isum, jsum, hh;
  isum = 0.0;
  jsum = 0.0;
  for (int i = 1; i <= 5; i++)
  {
    isum =
      isum + double (i) * cos (double (i - 1) * realData[a] +
      double (i));
    jsum =
      jsum + double (i) * cos (double (i + 1) * realData[z] +
      double (i));
  }

                    // Avoid real con-
  hh = isum * jsum + sqr (realData[a] + Center1) +
                    // version error
    sqr (realData[z] + Center2);
  hh += GlobalMax;

  // TEMPERATURE = 1, 4, 40, 400, 4000
  real result = exp (-hh / X);
  result /= sqr (X);
  return (UsingLogDensity) ? ln (result) : result;
}
Beispiel #22
0
real FLevy2D::operator () (const LabPnt & X) const
{
  n_real_calls++;
  rvector Pnt = X.Pnt;
  int a = Lb (Pnt), z = Ub (Pnt);
  real isum, jsum, hh;
  isum = 0.0;
  jsum = 0.0;

  for (int i = 1; i <= 5; i++)
  {
    isum = isum + double (i) * cos (double (i - 1) * Pnt[a] + double (i));
    jsum = jsum + double (i) * cos (double (i + 1) * Pnt[z] + double (i));
  }
  // Avoid real conversion error
  hh = isum * jsum + sqr (Pnt[a] + Center1) +
       sqr (Pnt[z] + Center2);
  hh += GlobalMax;

  // TEMPERATURE = 1, 4, 40, 400, 4000
  real result = exp (-hh / Temperature);
  //result /= sqrt(Temperature);
  //result /= Temperature;
  assert (result < 1.0);
  return (UsingLogDensity) ? ln (result) : result;
}
Beispiel #23
0
extern int
mkbrmap(void)			/* make dynamic range map */
{
	double	Tdb, b, s;
	double	ceiling, trimmings;
	register int	i;
					/* copy initial histogram */
	memcpy((void *)modhist, (void *)bwhist, sizeof(modhist));
	s = (bwmax - bwmin)/HISTRES;	/* s is delta b */
					/* loop until satisfactory */
	do {
		mkcumf();			/* sync brightness mapping */
		if (mhistot <= histot*CVRATIO)
			return(-1);		/* no compression needed! */
		Tdb = mhistot * s;
		trimmings = 0.;			/* clip to envelope */
		for (i = 0, b = bwmin + .5*s; i < HISTRES; i++, b += s) {
			ceiling = Tdb*clampf(Lb(b));
			if (modhist[i] > ceiling) {
				trimmings += modhist[i] - ceiling;
				modhist[i] = ceiling;
			}
		}
	} while (trimmings > histot*CVRATIO);

#if ADJ_VEIL
	mkcrfimage();			/* contrast reduction image */
#endif

	return(0);			/* we got it */
}
Beispiel #24
0
int Disjoint ( ivector& a, ivector& b )             // Test for disjointedness
{   //------------------------
    int al = Lb(a), au = Ub(a), bl = Lb(b);
    int disjointed, i, d;

    d = bl - al;

    i = al;
    disjointed = 0;
    do {
        if (Disjoint(a[i],b[i+d]))
            disjointed = 1;
        else
            i++;
    } while ( !(disjointed || i > au) );
    return disjointed;
}
Beispiel #25
0
extern double
crfactor(			/* contrast reduction factor */
	double	Lw
)
{
	int	i = HISTRES*(Bl(Lw) - bwmin)/(bwmax - bwmin);
	double	bLw, ratio, Tdb;

	if (i <= 0)
		return(1.0);
	if (i >= HISTRES)
		return(1.0);
	bLw = BLw(Lw);
	ratio = what2do&DO_HSENS ? htcontrs(Lb(bLw))/htcontrs(Lw) : Lb(bLw)/Lw;
	Tdb = mhistot * (bwmax - bwmin) / HISTRES;
	return(modhist[i]*Lb1(bLw)*(Bldmax-Bldmin)*Bl1(Lw)/(Tdb*ratio));
}
Beispiel #26
0
	SSMProcess* SceneModeler::compute(){
		setProgressText("starting computation");
		setProgressMax(100);
		setProgressValue(1);
		this->captureSceneLimits();
		this->calculateClasses();
		this->computeIndexSequence();
		for(int i = Lb(*this->transitionDataStates); i <= Ub(*this->transitionDataStates); i++){
			(*this->transitionDataStates)[i] += 1;
		}
		
		intvector rv(Lb(*this->transitionDataStates) , Ub(*this->transitionDataStates) );
		for(int i = Lb(rv) ; i <= Ub(rv) ; i++){
			rv[i] = (*this->transitionDataStates)[i];
		}
		setProgressText("creating model");
		return modelFromIndexSequence(rv);
	}
Beispiel #27
0
rvector mid ( ivector& v )                              // Vector of midpoints
{   //--------------------
    int i;
    int l = Lb(v), u = Ub(v);
    rvector w(l,u);

    for (i = l; i <= u; i++) w[i] = mid(v[i]);
    return w;
}
	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 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);
		}
	}
}
Beispiel #30
0
real MaxRelDiam ( const imatrix_subv& v )                    // Maximum relative diameter
{                                                 //--------------------------
  real r;
  int  i, l=Lb(v), u=Ub(v);

  r = 0.0;
  for (i = l; i <= u; i++)
    if (RelDiam(v[i]) > r) r = RelDiam(v[i]);
  return r;
}