コード例 #1
0
ファイル: cdftools2.cpp プロジェクト: jarpon/epitraits
int CDFTools<T>::rank(
  const Vector<T>& x,
  const Matrix<T>& distributionSamples,
  const Vector<T>& xEvals,
  const Vector<T>& distributionAverage) const
{
  const int numSamples = distributionSamples.getSize1();
  Vector<T> maxDifferences( 1+numSamples );
  Vector<T> maxDiffBuffer;
  Vector<T> ignored1, ignored2;
  T xMaxDiff;

  differences( x, cdf(x), xEvals, distributionAverage, maxDiffBuffer, ignored1, ignored2 );
  xMaxDiff = maxDifferences[0] = maxDiffBuffer[1];
  for (int i = 0; i < numSamples; ++i)
  {
    differences(
      distributionSamples[i], cdf(distributionSamples[i]),
      xEvals, distributionAverage,
      maxDiffBuffer, ignored1, ignored2 );
    maxDifferences[i+1] = maxDiffBuffer[1];
  }
  maxDifferences.sort();

  int r = 0;
  while ( maxDifferences[r] != xMaxDiff )
  {
    ++r;
  }

  return r;
}
コード例 #2
0
	void SplineCurve::regeneratePath(double step) {
		path.clear();
		double step2 = step  * step;
		double step3 = step2 * step;

		auto coordinates = this->coordinates();
		int nCurves = coordinates.size() - 3; // number of curves defined on the spline

		for(int curve = 0; curve < nCurves; curve++) {
			auto c1 = coordinates[curve];
			auto c2 = coordinates[curve + 1];
			auto c3 = coordinates[curve + 2];
			auto c4 = coordinates[curve + 3];

			double Ax, Bx, Cx, Dx, deltaX, delta2X, delta3X;
			coefficients(c1.x, c2.x, c3.x, c4.x, Ax, Bx, Cx, Dx);
			differences(Ax, Bx, Cx, Dx, step, step2, step3, deltaX, delta2X, delta3X);

			double Ay, By, Cy, Dy, deltaY, delta2Y, delta3Y;
			coefficients(c1.y, c2.y, c3.y, c4.y, Ay, By, Cy, Dy);
			differences(Ay, By, Cy, Dy, step, step2, step3, deltaY, delta2Y, delta3Y);

			double Az, Bz, Cz, Dz, deltaZ, delta2Z, delta3Z;
			coefficients(c1.z, c2.z, c3.z, c4.z, Az, Bz, Cz, Dz);
			differences(Az, Bz, Cz, Dz, step, step2, step3, deltaZ, delta2Z, delta3Z);

			Coordinate oldCoord(Dx, Dy, Dz);
			path.push_back(oldCoord);

			for (double t = 0.0; t <= 1; t += step) {
				Coordinate newCoord = oldCoord;
				newCoord.x += deltaX;
				newCoord.y += deltaY;
				newCoord.z += deltaZ;

				deltaX += delta2X;
				delta2X += delta3X;

				deltaY += delta2Y;
				delta2Y += delta3Y;

				deltaZ += delta2Z;
				delta2Z += delta3Z;

				path.push_back(newCoord);
				oldCoord = newCoord;
			}
		}
	}
コード例 #3
0
ファイル: cdftools2.cpp プロジェクト: jarpon/epitraits
void CDFTools<T>::differences(const Vector<T>& cdf1, const Vector<T>& cdf2, Vector<T>& maxDiff) const
{
  Vector<T> maxDiffAbove;
  Vector<T> maxDiffBelow;

  differences( cdf1, cdf2, maxDiff, maxDiffAbove, maxDiffBelow );
}
コード例 #4
0
ファイル: congruence.hpp プロジェクト: akubera/dimitri_lib
 void congruence_t<Expr,Args,Same_symbol,Num_args>::set_congruent
   (expr_t e1, expr_t e2)
 {
   auto diffs = differences(e1,e2);
   for (auto e: diffs) {
     size_t c1 = get_or_gen_canonical(e.first);
     size_t c2 = get_or_gen_canonical(e.second);
     // oi. I really need a permission based type system.
     if (!sets.in_same_set(c1,c2))
       sets.union_sets(c1,c2);
   }
 }
コード例 #5
0
/*Performs the 'difference' set operator*/
VehicleRegistry VehicleRegistry::Split(const VehicleRegistry& vr) const
{
	VehicleRegistry differences(*this);

	//Go through the vr list and use the find function with union as the calling object, if we do find it in the union list then we remove the vehicle from the union list
	for (int i = 0; i < vr.numvehicles; i++)
	{
		if (differences.Find(Vehicle(vr.vehicles[i].GetPlate(), "", "", "")) != -1)
		{
			differences.Remove(Vehicle(vr.vehicles[i].GetPlate(), vr.vehicles[i].GetMake(), vr.vehicles[i].GetModel(), vr.vehicles[i].GetColour()));
		}
	}

	return differences;

}
    void PredicateVolumeExplorer::updatePredicateHistogramFromScribbles() {
        std::vector<int> yesHistogram = computeBitHistogram(_yesScribbles);
        std::vector<int> noHistogram = computeBitHistogram(_noScribbles);
        std::vector<float> differences(yesHistogram.size());

        // compute differences, their sum and their absolute sum
        int diffSumAbs = 0;
        std::transform(
            yesHistogram.begin(), yesHistogram.end(), noHistogram.begin(), differences.begin(), 
            [&] (int a, int b) -> int { diffSumAbs += std::abs(a - b); return a - b; });

        if (diffSumAbs == 0)
            return;

        // compute 
        float quantile = .25f / static_cast<float>(diffSumAbs);
        std::for_each(differences.begin(), differences.end(), [&] (float& f) { f *= quantile; });
        p_histogram.adjustImportances(differences, p_histogram.getCurrentHistogramDistribution());

        invalidate(INVALID_RESULT);
    }
コード例 #7
0
/**
  * processing update step including resampling if possible
  */
void BFilterCUDA::update(fvec measurement) {

    float neff=0.0;
    fmat virtualMeasurementOfParticles;
    fmat differences = zeros<fmat>(particles.samples.n_rows,particles.samples.n_cols);
    fvec evals;

    // generate simulated measurements
    virtualMeasurementOfParticles = process->hfun(&particles.samples);

    // calculate differences
    //differences = virtualMeasurementOfParticles - inputMatrix;
    for (unsigned int i=0; i< virtualMeasurementOfParticles.n_cols; ++i)
    {
        for(unsigned int j=0; j<virtualMeasurementOfParticles.n_rows; ++j)
        {
            differences(j,i) = virtualMeasurementOfParticles(j,i) - measurement(j);
        }
    }

    // evaluation of particles
    evals = process->eval(&differences);
    // calculating new particle weights
    particles.weights = particles.weights * evals;

    normalizeWeights();

    neff=calculateNeff();
    if (neff <= nthr) {
        // Neff is too low so all particles are weighted with standard values
#ifdef VERBOSE
        printf("too few particles. 1/N for all particles\n");
#endif
        standardWeighting();
    }
    else {
        // Neff is high enough to resample particles
        particles = resampler->resample(&particles);
    }
}
コード例 #8
0
ファイル: tile_junction.cpp プロジェクト: gc-ant/digiholo2D
float tile_junction::calc_junction_variance() {
   /* Do not check if variance has been calculated before, this has to be done
    * by user before calling this method ... */
   boost::shared_ptr<tile> t1 = this->first.lock();
   boost::shared_ptr<tile> t2 = this->second.lock();
   boost::shared_ptr<std::vector<float> > differences(new std::vector<float>);

   long H = t1->get_height();
   long W = t1->get_width();

   switch (this->second_to_first) {
      case tile::UP:
      { //[t2]
         for (long i = 0; i < W; i++) { //[t1]
            differences->push_back(t1->get_raw_value_at(i, 0) - t2->get_raw_value_at(i, H - 1));
         }
         break;
      }
      case tile::DOWN:
      { //[t1]
         for (long i = 0; i < W; i++) { //[t2]
            differences->push_back(t1->get_raw_value_at(i, H - 1) - t2->get_raw_value_at(i, 0));
         }
         break;
      }
      case tile::LEFT:
      { //[t2][t1]
         for (long i = 0; i < H; i++) {
            differences->push_back(t1->get_raw_value_at(0, i) - t2->get_raw_value_at(W - 1, i));
         }
         break;
      }
      case tile::RIGHT:
      {//[t1][t2]
         for (long i = 0; i < H; i++) {
            differences->push_back(t1->get_raw_value_at(W - 1, i) - t2->get_raw_value_at(0, i));
         }
         break;
      }
      default:
         DEBUG_PRINTLN("Error in tile_junction::calc_junction_variance: Switch-Case hit default: No legal position committed");
         return -1.0f;
   }
   /* Calculate the median START */
   float mean = 0.0f;
   float N = differences->size();
   for (std::vector<float>::iterator it = differences->begin(); it != differences->end(); ++it) {
      mean += (*it);
   }
   mean /= N; //Divide through #
   /* Calculate the median END */

   /* Calculate the variance START */
   float variance = 0.0f;

   for (std::vector<float>::iterator it = differences->begin(); it != differences->end(); ++it) {
      variance += std::pow((*it) - mean, 2.0); //variance = sum of[(x - µ)^2]
   }
   variance /= N;
   this->variance = variance;
   this->has_variance_calculated = true;
   /* Calculate the variance END */
   return variance;
}
コード例 #9
0
int main (int argc, char *argv[])
{
    long rowsA, colsA;          /* Dimensiones de la imagen A */
    long rowsB, colsB;          /* Dimensiones de la imagen B */
    unsigned char **imageA;     /* Array 2D para la imagen A */
    unsigned char **imageB;     /* Array 2D para la imagen B */
    unsigned char **imageC;     /* Array 2D para la imagen C */
    int readOK, writeOK;        /* Controlan la E/S de disco */
    long i;

    /* Comprobamos el número de parametros */
    if (argc!=4)
    {
        printf("\nUso: %s <in_filenameA> <in_filenameB> <out_filenameC>.",argv[0]);
        printf("\n\nin_filenameA = Image PGM.");
        printf("\nin_filenameB = Image PGM.");
        printf("\nout_filenameC = Image PGM.\n\n.");
        exit(0);
    }

    /* Reservamos memoria dinámica para la imagen */
    imageA = ( unsigned char** )malloc( MAXROWS*sizeof( unsigned char* ) );
     
    /* Reservamos memoria para cada fila */
    for(i = 0; i < MAXROWS; i++) 
    {
        imageA[i] = ( unsigned char* )malloc( MAXCOLS*sizeof( unsigned char ) );
    }

    /* Reservamos memoria dinámica para la imagen */
    imageB = ( unsigned char** )malloc( MAXROWS*sizeof( unsigned char* ) );
     
    /* Reservamos memoria para cada fila */
    for(i = 0; i < MAXROWS; i++) 
    {
        imageB[i] = ( unsigned char* )malloc( MAXCOLS*sizeof( unsigned char ) );
    }

    /* Reservamos memoria dinámica para la imagen */
    imageC = ( unsigned char** )malloc( MAXROWS*sizeof( unsigned char* ) );
     
    /* Reservamos memoria para cada fila */
    for(i = 0; i < MAXROWS; i++) 
    {
        imageC[i] = ( unsigned char* )malloc( MAXCOLS*sizeof( unsigned char ) );
    }
      
    /* Leemos la imagen A de disco */
    readOK = pgmRead (argv[1],&rowsA,&colsA,imageA);
    if (!readOK)
    {
        printf("\nError al abrir la imagen: %s.\n",argv[1]);
        exit(1);
    }

    /* Leemos la imagen B de disco */
    readOK = pgmRead (argv[2],&rowsB,&colsB,imageB);
    if (!readOK)
    {
        printf("\nError al abrir la imagen: %s.\n",argv[2]);
        exit(1);
    }

    /* Comprobamos que las dos imágenes tienen las mismas dimensiones */
    if (rowsA==rowsB && colsA==colsB)
    {
        /* Generamos la imagen C con las diferencias de A - B */
        differences(imageA,imageB,imageC,rowsA,colsA);

        /* Guardamos la imagen residuo en disco */
        writeOK = pgmWrite(argv[3],rowsA,colsA,imageC,NULL);
        if (writeOK) 
        {
            printf("\nEl archivo: %s, con la imagen residuo se ha creado con éxito.\n\n",argv[3]);
        }
        else
        {
            printf("\nError al crear la imagen residuo: %s.\n\n",argv[3]);
        }
    }
    else
    {
        printf("\nLas imágenes no tienen las mismas dimensiones.\n");
    }

    return 0;
}
コード例 #10
0
int main()
{
    cout << "Think of a number between 1 and 100.\n";
    cout << "For every guess, enter if your number is\n";
    cout << "(l)arger or (s)maller than the one shown.\n";
    cout << "Enter 'c' (for 'correct') if the number shown is yours.\n";

    int guess = 50;
    vector<int> differences(6);
    differences[0] = 25;
    differences[1] = 13;
    differences[2] = 6;
    differences[3] = 3;
    differences[4] = 2;
    differences[5] = 1;
    int counter = 0;
    char answer = ' ';

    while (answer != 'c') {
        cout << "My guess: " << guess << endl;
        ++counter;
        cout << "Correct, larger or smaller (c, l, s)? ";
        cin >> answer;
        switch (answer) {
        case 'c':
            // do nothing, simply fall out of the loop
            break;
        case 'l':
            // increase by next difference or one
            if (counter<=differences.size())
                guess += differences[counter-1];
            else
                ++guess;
            break;
        case 's':
            // decrease by next difference
            if (counter<=differences.size())
                guess -= differences[counter-1];
            else
                --guess;
            break;
        default:
            // invalid answer, reduce counter because guess does not count
            cout << "This is not a valid answer, use 'c', 'l' or 's'\n";
            --counter;
            break;
        }
        if (guess>100 || guess<1) {
            cout << "Your number must be between 1 and 100!\n";
            return 0;
        }
        if (counter==7 && answer!='c')
        {
            cout << "Super fishy, dude. I should have your number by now.\n";
            return 0;
        }
    }

    string s_try;
    if (counter==1)
        s_try = " try ";
    else
        s_try = " tries ";
    cout << "It took me " << counter << s_try << "to find your number, " << guess << ".\n";
}