Example #1
0
void runTest()
{
	NeuralGasNetwork* myNet = new NeuralGasNetwork(
        2,
		NODE_CHANGE_RATE,
		NODE_NEIGHBOR_CHANGE_RATE,
		LOCAL_DECREASE_RATE,
		GLOBAL_DECREASE_RATE,
		AGE_MAX,
		TIME_BETWEEN_ADDING_NODES);

	int i = 0;
	while (myNet->nodes.size() < 100 && i < 15000)
	{
		if (i%500 == 0)
            cout << "Iteration " << i << endl;

		myNet->iterate(generateTestData());
		++i;
	}

	LabelGraphNodes(myNet);

    //Now train the perceptron classifer
	PerceptronClassifier* myClassifier = new PerceptronClassifier(myNet,
		2,
		2);

	for (unsigned int i = 0; i != 100; ++i)
	{
		vector<double> testData = generateTestData();
		if (testData[0] > 0.5)
			myClassifier->train_GNG_Perceptron(testData, 1);
		else
			myClassifier->train_GNG_Perceptron(testData, 0);
	}

	while (1)
	{
		double t1;
		double t2;
		cin >> t1 >> t2;
		vector<double> testVec = { t1, t2 };
		int k = myNet->findNearest(testVec);
		cout << "GNG Classifcation: " << myNet->nodes[k]->classification << endl;
		cout << "GNG Error: " << myNet->nodes[k]->getEuclidianDistance(testVec) << endl;
		myClassifier->printOutput(testVec);
		
	}
}
    virtual void SetUp()
    {
        // generate a pointcloud
        generateTestData();
        // setup ROS
        ros::NodeHandle n("~");
        pub_cloud_ = n.advertise<sensor_msgs::PointCloud2>("output", 1);
        pub_even_indices_ = n.advertise<pcl_msgs::PointIndices>("output/even_indices", 1);
        pub_odd_indices_ = n.advertise<pcl_msgs::PointIndices>("output/odd_indices", 1);
        sub_even_result_ = n.subscribe("input/even_result", 1, &ExtractIndicesTest::evenCallback, this);
        sub_odd_result_ = n.subscribe("input/odd_result", 1, &ExtractIndicesTest::oddCallback, this);
        sub_even_organized_result_ = n.subscribe("input/even_organized_result", 1,
                                     &ExtractIndicesTest::evenOrganizedCallback, this);
        sub_odd_organized_result_ = n.subscribe("input/odd_organized_result",
                                                1, &ExtractIndicesTest::oddOrganizedCallback, this);

        // wait until
        ros::Time start_time = ros::Time::now();
        while (!isReady()) {
            publishData();
            ros::spinOnce();
            ros::Duration(0.5).sleep();
        }
        ros::Time end_time = ros::Time::now();
        ROS_INFO("took %f sec to retrieve result", (end_time - start_time).toSec());
    }
Example #3
0
 double doExec() {
     
     if (!loadTestData()) {
         std::cerr << "Failed to load test data" << std::endl;
         return -1;
     }
     
     //
     // Start solution testing
     //
     double score = 0, sse;
     int scenario = 0;
     for (int i = 0; i < subsetsNum; i++) {
         scenario = i % 3;
         generateTestData(scenario, i);
         VD res = test->predict(0, scenario, DTrain, DTest);
         
         Assert(groundTruth.size() == res.size(), "Expected results count not equal to found. Expected: %lu, but found: %lu", groundTruth.size(), res.size());
         sse = 0;
         for (int j = 0; j < res.size(); j++) {
             double e = res[j] - groundTruth[j];
             sse += e * e;
         }
         // calculate score
         double s = 1000000 * fmax(0, 1.0 - sse/sse0);
         Printf("%i.) Score = %f, sse: %f, sse0: %f\n", i, s, sse, sse0);
         score += s;
     }
     return score / subsetsNum;
 }
Example #4
0
OCL_TEST_P(FastNlMeansDenoising_hsep, Mat)
{
    for (int j = 0; j < test_loop_times; j++)
    {
        generateTestData();

        OCL_OFF(cv::fastNlMeansDenoising(src_roi, dst_roi, h, templateWindowSize, searchWindowSize, normType));
        OCL_ON(cv::fastNlMeansDenoising(usrc_roi, udst_roi, h, templateWindowSize, searchWindowSize, normType));

        OCL_EXPECT_MATS_NEAR(dst, 1);
    }
}
Example #5
0
    void performTest(int channelsIn, int channelsOut, int code, double threshold = 1e-3)
    {
        for (int j = 0; j < test_loop_times; j++)
        {
            generateTestData(channelsIn, channelsOut);

            OCL_OFF(cv::cvtColor(src_roi, dst_roi, code, channelsOut));
            OCL_ON(cv::cvtColor(usrc_roi, udst_roi, code, channelsOut));

            Near(threshold);
        }
    }
//================================================================================================================================================================
int main()
{
	auto elements = generateTestData(std::pow(10, 4));
	size_t key    = -1; // an element which is never found

	std::unique_ptr<basicsearching::ISearch> linearSearch = std::make_unique<basicsearching::LinearSearch>();
	std::unique_ptr<basicsearching::ISearch> binarySearch = std::make_unique<basicsearching::BinarySearch>();

	testSearchAlgorithm("LinearSearch", linearSearch, elements, key);
	std::cout << std::endl << "-----------";
	testSearchAlgorithm("BinarySearch", binarySearch, elements, key);


	std::cout << std::endl;
	return 0;
}
Example #7
0
void runTest()
{

    //Get the platforms
    std::vector<cl::Platform> platforms;
    cl::Platform::get(&platforms);

    //Create a context
    cl_context_properties cps[3] = {CL_CONTEXT_PLATFORM,
        (cl_context_properties)(*platforms.begin())(), 0};
    cl::Context context = cl::Context(CL_DEVICE_TYPE_GPU, cps);

    //Create and build the program
    cl::Program opencl_gngNetworkProgram;
    opencl_gngNetworkProgram = createProgram(context, "opencl_gng_network.cl");

    //Create the command queue from the first device in context
    cl::CommandQueue queue;
    queue = cl::CommandQueue(context, context.getInfo<CL_CONTEXT_DEVICES>()[0], CL_QUEUE_PROFILING_ENABLE);


    GPU_parallel_gng::NeuralGasNetworkHost* myNet = new GPU_parallel_gng::NeuralGasNetworkHost(
        2,
        NODE_CHANGE_RATE,
        NODE_NEIGHBOR_CHANGE_RATE,
        LOCAL_DECREASE_RATE,
        GLOBAL_DECREASE_RATE,
        AGE_MAX,
        TIME_BETWEEN_ADDING_NODES,
        context,
        opencl_gngNetworkProgram,
        queue);

    for (int i = 0; i != 50000; ++i)
    {
        if (i%500 == 0)
            cout << "iteration: " << i << endl;
        vector<float> dataPoint = generateTestData();
        myNet->iterateNetwork(dataPoint, queue);
    }
    myNet->foo(queue);
    CPU_serial_gng::NeuralGasNetwork* cpuNet = convert_to_cpu_gng(*myNet->gngNetwork);

    CPU_serial_gng::LabelGraphNodes(cpuNet);

}
Example #8
0
OCL_TEST_F(SphericalWarperTest, Mat)
{
    for (int j = 0; j < test_loop_times; j++)
    {
        generateTestData();

        Ptr<WarperCreator> creator = makePtr<SphericalWarper>();
        Ptr<detail::RotationWarper> warper = creator->create(2.0);

        OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));
        OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));

        OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));
        OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));

        Near(1e-4);
    }
}
Example #9
0
void testCMarginBuffer()
{
  const int64_t cols     = 23;
  const int64_t rows        = 54;
  const int64_t numPixels   = cols * rows;
  const int64_t numElements = (cols + 2 * margin) * (rows + 2 * margin);

  CMarginBuffer2D<margin> buffer1(cols, rows);

  EXPECT_EQ(cols, buffer1.cols());
  EXPECT_EQ(rows, buffer1.rows());
  EXPECT_EQ(numPixels, buffer1.numPixels());
  EXPECT_EQ(numElements, buffer1.numElements());

  // generate test data
  generateTestData(buffer1);

  // check the data in the buffer
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)),
                buffer1.pixel(x, y));
    }
  }

  // create a compatible buffer
  auto buffer2 = buffer1.createCompatibleBuffer();

  EXPECT_EQ(cols, buffer1.cols());
  EXPECT_EQ(rows, buffer2.rows());
  EXPECT_EQ(numPixels, buffer2.numPixels());
  EXPECT_EQ(numElements, buffer2.numElements());
  EXPECT_TRUE(buffer1.compatible(buffer2));
  EXPECT_TRUE(buffer2.compatible(buffer1));

  // copy the data in the new buffer
  buffer2.assign(buffer1);

  // clear the first buffer
  const Complex clearValue(42.0, -8.0);
  buffer1.setValue(clearValue);

  // check the data in the first buffer
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(clearValue, buffer1.pixel(x, y));

  // check the data in the second buffer
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
       EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)), static_cast<Real>(x)),
                 buffer2.pixel(x, y));
    }
  }

  // test addAssign
  buffer1.setValue(Complex(1.0, -1.0));
  generateTestData(buffer2);
  buffer1 += buffer2;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + R(1.0),
                        static_cast<Real>(x) - R(1.0)),
                        buffer1.pixel(x, y));
    }
  }

  // test multiplyAssign(CMarginBuffer)
  buffer1.setValue(Complex(1.0, -1.0));
  generateTestData(buffer2);
  buffer1 *= buffer2;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x),
                        -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)),
                        buffer1.pixel(x, y));
     }
  }

  // test multiplyAssign(Complex)
  generateTestData(buffer1);
  buffer1 *= Complex(1.0, -1.0);
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) + static_cast<Real>(x),
                        -std::sin(static_cast<Real>(y)) + static_cast<Real>(x)),
                        buffer1.pixel(x, y));
     }
  }

  // test multiplyAssign(Real)
  generateTestData(buffer1);
  buffer1 *= 5.0;
  for (int64_t y = 0; y < rows; ++y)
  {
    for (int64_t x = 0; x < cols; ++x)
    {
      EXPECT_EQ(Complex(std::sin(static_cast<Real>(y)) * R(5.0),
                        static_cast<Real>(x) * R(5.0)),
                        buffer1.pixel(x, y));
     }
  }

  // create a third buffer
  const Complex initialValue(-49.0, 7.0);
  CMarginBuffer2D<margin> buffer3(cols + 1, rows, initialValue);
  EXPECT_FALSE(buffer3.compatible(buffer1));
  EXPECT_FALSE(buffer1.compatible(buffer3));

  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(initialValue, buffer3.pixel(x, y));

  std::mt19937 generator;
  std::uniform_real_distribution<Real> distribution(0.0, Math::twoPi);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols + 1; ++x)
      buffer3.pixel(x, y) = fromArg(distribution(generator));

  EXPECT_EQ(buffer3.numPixels(), buffer3.absSqrReduce());

  // todo: test multiplyAssign
  // todo: test info
}
Example #10
0
/*********************************************
		per-frame logic goes here
**********************************************/
void App::updateMain(){

	//Get the mouse pointer pos in screen space
	SDL_GetMouseState(&iMouseX, &iMouseY); 
	
	//Throw away any bad frames
	if(fTimeScale == infinity || fTimeScale == 0.0f){
		return;
	}
	
	float fCamSpeed = fTimeScale * 10.0f;
	float fDragScale = 0.05f;

	if (!this->bGlobalDisableKeyMovement) {

		//Right button means we reset rotation and such
		//NOTE: I did have this as 'both left and right at once', which seemed
		//to make more sense, but it doesn't work great on systems that map this
		//to middle-mouse		
		if(mouseDown(3)){
			resetCam();
		}

		//Rotation for the wall
		/*
		float camTime = fUptime * 0.1f;

		float fRotateSpeed = fCamSpeed;
		fRot[1] += fRotateSpeed;
		fRot[0] = (sinf(camTime) * 5);
		fCameraY = cosf(camTime) * 5;
		
		fZoom = (sinf(camTime) * 15) + 27;
		*/
			
		//LOG("%f, %f\n", fRot[1], fZoom);
		
		//fZoom = -10;
		
		//Keyboard rotation
		if(keyDown(SDLK_RSHIFT) || keyDown(SDLK_LSHIFT)){
			fCamSpeed *= 10;
		}
		
		if(keyDown(SDLK_LEFT))	fRot[1] -= fCamSpeed;
		if(keyDown(SDLK_RIGHT))	fRot[1] += fCamSpeed;
		if(keyDown(SDLK_UP))	fRot[0] -= fCamSpeed;
		if(keyDown(SDLK_DOWN))	fRot[0] += fCamSpeed;

		if(keyDown(SDLK_w)) {
			fCameraZ -= fCamSpeed; 
			//fRot[0] = 0.0; fRot[1] = 0.0; fRot[2] = 0.0;
			fLookZ -= fCamSpeed;
		}
		
		if(keyDown(SDLK_s)) {
			fCameraZ += fCamSpeed; 
			//fRot[0] = 0.0; fRot[1] = 0.0; fRot[2] = 0.0;
			fLookZ += fCamSpeed;
		}
		if(keyDown(SDLK_a)) {
			fCameraX -= fCamSpeed;
			fLookX -= fCamSpeed;
		}
		if(keyDown(SDLK_d)) {
			fCameraX += fCamSpeed;
			fLookX += fCamSpeed;
		}
		
		if(keyDown(SDLK_SPACE))	resetCam();
		
		//If we're actively dragging with the mouse
		if(bDrag){
			
			//Figure out the drag vectors and stuff
			Vector2 drag = getMouse();
			Vector2 diff = (dragStart - drag) * fDragScale;
					
			//Left mouse button means we modify the rotation
			if(mouseDown(1)){
				fRot[1] -= diff.x;
				fRot[0] -= diff.y;			
			}
			
			//Middle mouse means we modify the zoom
			else if(mouseDown(2)){
				fZoom += diff.y;
			}
			
			dragVel = diff;
			dragStart = getMouse();
			
			
			
		}else{
			//fRot[1] -= dragVel.x;
			//fRot[0] -= dragVel.y;
		}
	}	

	updateSocket();
	
	//Hack! The shader system doesn't really play nice with the banner, so
	//we disable it here.
	if(!isConnected()){
		if(ps()->getType() <= PARTICLE_SYSTEM_POINTSPRITES)
			generateTestData();
		else
			fGUITimeout = 1.0f;
	}
	
	mParticleSystem->update();	
}