Exemplo n.º 1
0
	void test_conlitron_learner_3d()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readOffFile(P, "../data/cup.off");
		readOffFile(Q, "../data/spoon.off");

		P->ComputeRadius();
		Q->ComputeRadius();

		ContactSpaceR3 contactspace(P, Q, 0.05 * (P->radius + Q->radius));
		std::vector<ContactSpaceSampleData> contactspace_samples = contactspace.uniform_sample(10000);

		std::ofstream out("space_test_3d.txt");
		asciiWriter(out, contactspace_samples);

		DataVector w(3);
		w[0] = 1; w[1] = 1; w[2] = 1;
		MulticonlitronLearner learner(w, 0.01);
		///////////////////////////////////////
		learner.use_approximate_dist = false;
		///////////////////////////////////////

		tools::Profiler::Begin("learn without approximate knn");
		learner.learn(contactspace_samples, 3);
		tools::Profiler::End("learn without approximate knn");

		std::cout << learner.model.numOfHyperPlanes() << std::endl;

		std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner) << " " << errorRatioOnGrid(contactspace, learner, 50) << std::endl;

		delete P;
		delete Q;
	}
	void test_svm_learner_3d_rotation()
	{

		{
			C2A_Model* P = NULL;
			C2A_Model* Q = NULL;
			readOffFile(P, "../data/cup.off");
			readOffFile(Q, "../data/spoon.off");

			P->ComputeRadius();
			Q->ComputeRadius();

			tools::Profiler::Begin("learner");
			ContactSpaceSE3Euler contactspace(P, Q, 0.05 * (P->radius + Q->radius));
			std::vector<ContactSpaceSampleData> contactspace_samples = contactspace.uniform_sample(10000);
			tools::Profiler::End("learner");
				
			std::ofstream out("space_test_3d_rotation.txt");
			asciiWriter(out, contactspace_samples);
			
			SVMLearner learner;
			learner.setC(50);
			learner.setProbability(true);
			learner.setScaler(contactspace.getScaler());
			learner.setUseScaler(true);
			learner.setGamma(50); 


			std::ofstream scaler_file("scaler_3d_rotation.txt");
			scaler_file << contactspace.getScaler() << std::endl;
			
			tools::Profiler::Begin("learner");
			learner.learn(contactspace_samples, contactspace.active_data_dim());
			tools::Profiler::End("learner");
			learner.save("model_3d_rotation.txt");

			std::cout << "model saved" << std::endl;


			std::vector<ContactSpaceSampleData> test_samples = contactspace.uniform_sample(10000);
			std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner) << " " << empiricalErrorRatio(test_samples, learner) << std::endl;

		    //std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner) << " " <<  errorRatioOnGrid(contactspace, learner, 5) << " ";

			//for(std::size_t i = 0; i < contactspace_samples.size(); ++i)
			//	std::cout << "(" << results[i].label << "," << contactspace_samples[i].col << ")";
			//std::cout << std::endl;

			delete P;
			delete Q;
		}

	}
Exemplo n.º 3
0
void Mesh::read(std::istream& is, const char* fileExtension) {
  bool loaded=false;
  if(!strcmp(fileExtension, "obj")) { readObjFile(is); loaded=true; }
  if(!strcmp(fileExtension, "off")) { readOffFile(is); loaded=true; }
  if(!strcmp(fileExtension, "ply")) { readPlyFile(is); loaded=true; }
  if(!strcmp(fileExtension, "tri")) { readTriFile(is); loaded=true; }
  if(!strcmp(fileExtension, "stl")) { readStlFile(is); loaded=true; }
  if(!loaded) HALT("can't read fileExtension '" <<fileExtension <<"'");
}
	void test_conlitron_learner_3d_rotation_approximate_knn()
	{
		C2A_Model* P = NULL;
		C2A_Model* Q = NULL;
		readOffFile(P, "../data/cup.off");
		readOffFile(Q, "../data/spoon.off");

		P->ComputeRadius();
		Q->ComputeRadius();

		ContactSpaceSE3Euler2 contactspace(P, Q, 0.05 * (P->radius + Q->radius));
		std::vector<ContactSpaceSampleData> contactspace_samples = contactspace.uniform_sample(10000);

		std::ofstream out("space_test_3d_rotation.txt");
		asciiWriter(out, contactspace_samples);

		DataVector w(6);
		w[0] = 1; w[1] = 1; w[2] = 1; w[3] = 1; w[4] = 1; w[5] = 1;
		MulticonlitronLearner learner(w, 0.01);
		///////////////////////////////////////
		learner.use_approximate_dist = true;
		///////////////////////////////////////

		tools::Profiler::Begin("learn with approximate knn");
		learner.learn(contactspace_samples, 6);
		tools::Profiler::End("learn with approximate knn");

		std::cout << learner.model.numOfHyperPlanes() << std::endl;

		std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner) << " " << errorRatioOnGrid(contactspace, learner, 5) << std::endl;





		MulticonlitronLearner learner2(w, 0.01, 1, 1);
		///////////////////////////////////////
		learner2.use_approximate_dist = true;
		///////////////////////////////////////

		tools::Profiler::Begin("learn with approximate knn");
		learner2.learn(contactspace_samples, 6);
		tools::Profiler::End("learn with approximate knn");

		std::cout << learner2.model.numOfHyperPlanes() << std::endl;

		std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner2) << " " << errorRatioOnGrid(contactspace, learner2, 5) << std::endl;




		MulticonlitronLearner learner3(w, 0.01, 5, 5);
		///////////////////////////////////////
		learner3.use_approximate_dist = true;
		///////////////////////////////////////

		tools::Profiler::Begin("learn with approximate knn");
		learner3.learn(contactspace_samples, 6);
		tools::Profiler::End("learn with approximate knn");

		std::cout << learner3.model.numOfHyperPlanes() << std::endl;

		std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner3) << " " << errorRatioOnGrid(contactspace, learner3, 5) << std::endl;


		MulticonlitronLearner learner4(w, 0.01, 10, 10);
		///////////////////////////////////////
		learner4.use_approximate_dist = true;
		///////////////////////////////////////

		tools::Profiler::Begin("learn with approximate knn");
		learner4.learn(contactspace_samples, 6);
		tools::Profiler::End("learn with approximate knn");

		std::cout << learner4.model.numOfHyperPlanes() << std::endl;

		std::cout << contactspace_samples.size() << ": " << empiricalErrorRatio(contactspace_samples, learner4) << " " << errorRatioOnGrid(contactspace, learner4, 5) << std::endl;

		delete P;
		delete Q;

	}