コード例 #1
0
int main() 
{

	double a[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
	 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0,
	 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0};

	double b[39];
	double c[39];
	double d[39];
	//printf("%f \n", computeScalarSum(a, 1, 38));

//	 computeSquareVec(a, b, 1, 32);

//	 computeDiffVec(a, b, c, 1, 32);

	scalarDiffVec(&a[1], 1.0, &b[1], 34);

	for(int i = 0; i < 39; i++) {
		printf(" a %f b%f  \n", a[i], b[i]);
	}
	printf("\nNEXT\n");
	divByScalarVec(b, 2.0,25);
	initVec(c, 0.0, 39);
	initVec(&d[1], 4.0, 38);
	initVec(c, 1.0, 5);
	for(int i = 0; i < 39; i++) {
		printf(" a %f b%f c %f d %f  \n", a[i], b[i], c[i], d[i]);
	}
}
コード例 #2
0
ファイル: esfinder.cpp プロジェクト: avitase/rabi
double ESFinder::calcES(std::shared_ptr<const Arena> arena, vec &psi, const std::vector<vec> &outprj, std::size_t &counter, const bool initVector) {
  if (initVector) {
    initVec(psi, *arena);
  }

  const ITP itp(arena);
  double diff = 0.;
  double energy = 0.;
  counter = 0;
  do {
    counter += 1;
    assert(counter < 1e3);

    itp.propagate(psi);
    if (outprj.size() > 0) {
      const double dx = arena->getStepSizeX();
      VecTools::projectOut(psi, outprj, dx);
    }

    double energy2 = itp.calcEnergy(psi);
    diff = std::abs(energy - energy2);
    energy = energy2;
  } while (diff > 1e-10);

  return energy;
}
コード例 #3
0
void AdaptiveManifoldFilterN::computeClusters(Mat1b& cluster, Mat1b& cluster_minus, Mat1b& cluster_plus)
{
    Mat difEtaSrc;
    {
        vector<Mat> eta_difCn(jointCnNum);
        for (int i = 0; i < jointCnNum; i++)
            subtract(jointCn[i], etaFull[i], eta_difCn[i]);

        merge(eta_difCn, difEtaSrc);
        difEtaSrc = difEtaSrc.reshape(1, (int)difEtaSrc.total());
        CV_DbgAssert(difEtaSrc.cols == jointCnNum);
    }

    Mat1f initVec(1, jointCnNum);
    if (useRNG)
    {
        rnd.fill(initVec, RNG::UNIFORM, -0.5, 0.5);
    }
    else
    {
        for (int i = 0; i < (int)initVec.total(); i++)
            initVec(0, i) = (i % 2 == 0) ? 0.5f : -0.5f;
    }

    Mat1f eigenVec(1, jointCnNum);
    computeEigenVector(difEtaSrc, cluster, eigenVec, num_pca_iterations_, initVec);

    Mat1f difOreientation;
    gemm(difEtaSrc, eigenVec, 1, noArray(), 0, difOreientation, GEMM_2_T);
    difOreientation = difOreientation.reshape(1, srcSize.height);
    CV_DbgAssert(difOreientation.size() == srcSize);

    compare(difOreientation, 0, cluster_minus, CMP_LT);
    bitwise_and(cluster_minus, cluster, cluster_minus);

    compare(difOreientation, 0, cluster_plus, CMP_GE);
    bitwise_and(cluster_plus, cluster, cluster_plus);
}
コード例 #4
0
void AdaptiveManifoldFilterN::computeClusters(Mat1b& cluster, Mat1b& cluster_minus, Mat1b& cluster_plus)
{
    
    Mat1f difOreientation;
    if (jointCnNum > 1)
    {
        Mat1f initVec(1, jointCnNum);
        if (useRNG)
        {
            rnd.fill(initVec, RNG::UNIFORM, -0.5, 0.5);
        }
        else
        {
            for (int i = 0; i < (int)initVec.total(); i++)
                initVec(0, i) = (i % 2 == 0) ? 0.5f : -0.5f;
        }

        vector<Mat> difEtaSrc(jointCnNum);
        for (int i = 0; i < jointCnNum; i++)
            subtract(jointCn[i], etaFull[i], difEtaSrc[i]);

        Mat1f eigenVec(1, jointCnNum);
        computeEigenVector(difEtaSrc, cluster, eigenVec, num_pca_iterations_, initVec);

        computeOrientation(difEtaSrc, eigenVec, difOreientation);
        CV_DbgAssert(difOreientation.size() == srcSize);
    }
    else
    {
        subtract(jointCn[0], etaFull[0], difOreientation);
    }

    compare(difOreientation, 0, cluster_minus, CMP_LT);
    bitwise_and(cluster_minus, cluster, cluster_minus);

    compare(difOreientation, 0, cluster_plus, CMP_GE);
    bitwise_and(cluster_plus, cluster, cluster_plus);
}
コード例 #5
0
ファイル: fv_displaywalltv.c プロジェクト: Jheengut/gmerlin
static int start(effect * e)
  {
  displaywalltv_t * priv = e->priv;
  priv->state = 1;
  
  priv->cx = e->video_width / 2;
  priv->cy = e->video_height / 2;
  
  priv->vecx = malloc(sizeof(int) * e->video_area);
  priv->vecy = malloc(sizeof(int) * e->video_area);

  if(priv->vecx == NULL || priv->vecy == NULL)
    return -1;

  initVec(e);

  return 0;
  }
コード例 #6
0
ファイル: PhysicalObject.cpp プロジェクト: JERlabs/JERonimo
    const SUCCESS PhysicalObject::collided(PhysicalObject &object, const Radians angle)
    {
        Vector initVec(getVelocity()-object.getVelocity());
        Mag_t<double> initVel(initVec.mag());
        Radians initTheta(initVec.theta());
        
		if(fabs(getX(initVel, initTheta-angle)) < REST_THRESHOLD)
        {
			setVelocity(getVelocity()+initVec/2.0);
			object.setVelocity(object.getVelocity()-initVec/2.0);
            antigravitate(object);
            object.antigravitate(*this);
			return SUCCEEDED;
		}
		
        // Frame of reference with the object at rest with this approaching it with an angle of 0
        Point<double> p2(Vector(Mag_t<double>(2.0*getMass()*getX(initVel, initTheta-angle)/(getMass()+object.getMass())), initTheta-angle));  // Gets the velocity of 2 based on elastic collision equation
        Point<double> p1((initVel*getMass()-p2.x()*object.getMass())/getMass(), -p2.y()*object.getMass()/getMass());   // Gets the velocity of 1 based off of elastic collision rulez
        
        if(fabs(p1.x()) < REST_THRESHOLD && fabs(p2.x()) < REST_THRESHOLD)
        {
            p1.x(0.0);
            p2.x(0.0);
        }
        
        Vector v1(p1);
        Vector v2(p2);
        
        v1.theta(-v1.theta()+initTheta);
        v2.theta(angle);
        
        v1 += object.getVelocity();
        v2 += object.getVelocity();
        
        Point<double> dif(object.getPosition()-*position);
        while(getCollider()->collides(*object.getCollider()))
            acceleration.set(*position-dif/pythagoras<double>(dif));
        
        setVelocity(v1);
        object.setVelocity(v2);
        
        return SUCCEEDED;
    }
コード例 #7
0
void TestClusteringPopulationAnalyzer::testEvaluatePopulationTwoThreads(void)
{
    Graph graph;
    // Initialize graph
    graph.addVertex(Vertex(0));
    graph.addVertex(Vertex(1));
    graph.addVertex(Vertex(2));
    graph.addVertex(Vertex(3));
    graph.addVertex(Vertex(4));
    graph.addVertex(Vertex(5));
    graph.addVertex(Vertex(6));
    graph.addVertex(Vertex(7));

    graph.addEdge(Vertex(0), Vertex(1), 0.2);
    graph.addEdge(Vertex(1), Vertex(2), 0.3);
    graph.addEdge(Vertex(1), Vertex(3), 0.5);
    graph.addEdge(Vertex(2), Vertex(3), 0.4);
    graph.addEdge(Vertex(3), Vertex(4), 0.2);
    graph.addEdge(Vertex(4), Vertex(5), 0.5);
    graph.addEdge(Vertex(4), Vertex(6), 0.6);
    graph.addEdge(Vertex(5), Vertex(6), 0.7);
    graph.addEdge(Vertex(6), Vertex(7), 0.1);

    IntegerEncodingInitializer initVec(&graph);
    std::vector<PopulationMember<IntegerVectorEncoding, double>> vecPop;
    for (size_t i = 0; i < populationSize; i++)
    {
        PopulationMember<IntegerVectorEncoding, double> member;
        member.fitnessValue = 0.0;
        member.modified = true;
        member.populationEncoding = initVec.getRandomSolution();
        vecPop.push_back(member);
    }

    ClusteringPopulationAnalyzer<FitnessAnalyzer, std::vector<PopulationMember<IntegerVectorEncoding, double>>> analyzer(&graph, &vecPop, 2);
    analyzer.evaluatePopulation();
    FitnessAnalyzer singleAnalyzer;
    for (auto& e : vecPop)
    {
        CPPUNIT_ASSERT(singleAnalyzer.analyze(&e.populationEncoding, &graph) == e.fitnessValue);
    }
}