示例#1
0
文件: naomngt.cpp 项目: no-ox/IMAR-C
/**
 * \fn void trainBdd(std::string bddName, int dim, int maxPts, int k)
 * \brief Trains the specified BDD.
 *
 * \param[in] bddName The name of the BDD.
 * \param[in] dim The dimension of the STIPs.
 * \param[in] maxPts The maximum number of points we want to compute.
 * \param[in] k The number of cluster (means).
 */
void im_train_bdd(std::string bddName, int k){
  std::string path2bdd("bdd/" + bddName);
  std::string KMeansFile(path2bdd + "/" + "training.means");
  
  //std::cout << path2bdd << std::endl;
  //int desc = getDescID(path2bdd);
  //int dim = getDim(desc);
  // Loading the DenseTrack settings
  
  // Loading BDD
  IMbdd bdd(bddName,path2bdd);
  bdd.load_bdd_configuration(path2bdd.c_str(),"imconfig.xml");
  
  // In im_train_bdd all the people are the training people !!
  std::vector<std::string> trainingPeople = bdd.getPeople();
  
  // Loading activities
  std::vector<std::string> activities = bdd.getActivities();
  int nrActivities = activities.size();
  int labels[nrActivities];
  int index = 0;
  for(std::vector<std::string>::iterator activity = activities.begin();
      activity != activities.end();
      ++activity){
    labels[index] = index + 1;
    index++;
  }
  if(k%nrActivities != 0){
    std::cerr << "k is not divisible by nrActivities !" << std::endl;
    exit(EXIT_FAILURE);
  }
  
  // Saving KMeans settings
  bdd.changeKMSettings("specifical",
		       k,
		       "training.means");
  im_create_specifics_training_means(bdd, trainingPeople);
  
  // SVM train
  MatrixC trainMC = MatrixC(nrActivities,labels);
  std::vector<std::string> testingPeople;
  MatrixC testMC = MatrixC(nrActivities, labels);
  double crossValidationAccuracy = im_svm_train(bdd,
						trainingPeople, trainMC,
						testingPeople, testMC);
  trainMC.calculFrequence();
  trainMC.exportMC(path2bdd,"training_confusion_matrix.txt");
  bdd.write_bdd_configuration(path2bdd.c_str(),"imconfig.xml");
  
  std::cout << "Resume of the training phase:" << std::endl;
  bdd.show_bdd_configuration();
  std::cout << "Train recognition rate:" << std::endl;
  std::cout << "\t cross validation accuracy=" << crossValidationAccuracy << std::endl;
  std::cout << "\t tau_train=" << trainMC.recognitionRate*100 << "%" << std::endl;
  std::cout << "\t total number of train BOWs=" << trainMC.nrTest << std::endl;
}
示例#2
0
文件: main.cpp 项目: utzms/siwir
//claimed function for calling the program, only due to the assignment tasks
static void matrixmult(const int M, const int N, const int K, double * A, const int lda, double * B, int ldb, double * C, int ldc)
{
		
	Matrix MatrixA(M,K,A,lda);
	Matrix MatrixB(K,N,B,ldb);
	Matrix MatrixC(M,N);
	
	//for matrices with dimensions to the power of two strassen is used  		
	if(Matrix::checkIfPowerOfTwo(M,K))
	{	
		if(Matrix::checkIfPowerOfTwo(K,N))
		{
			Matrix::matmult(MatrixA,MatrixB,MatrixC);
		}
	}
	else
	{
	//otherwise native matrix multiplication
		MatrixC = MatrixA*MatrixB;
	}
	for(size_t i = 0; i< MatrixC.getMdim() ; ++i)
	{	
		for(size_t j = 0; j<MatrixC.getNdim() ; ++j)
		{
			C[i*ldc + j] = MatrixC.getValueAt(i,j);
		}
	}
}
int main()
{
  long start_time; //Used for execution time (Start of execution)
  long stop_time; //Used for execution end time (End of execution)

  Matrix MatrixA("DataMatrixA.txt");//Input File data goes to Matrix A
  Matrix MatrixB("DataMatrixB.txt");// Input File data goes to Matrix B
  Matrix MatrixC(MatrixA.getRow(),MatrixB.getColumn());//Matrix C result gets rows of A and columns of B
  
  start_time=clock();//Starts timer 
  HorizontalMultiply(MatrixA, MatrixB,MatrixC);//Computing Multiplication
  stop_time=clock();//End timer
  
  double Horizontal_Time= (stop_time-start_time)/(double)(CLOCKS_PER_SEC); //Execution time
  
  MatrixC.print(); //Print result of Matrix C
  
  cout << endl;
  cout << "________________________________________________________________ " << endl;
  cout << "Divide Horizontal Time: (Core Count in System): " << Horizontal_Time << " seconds" << endl;
  cout << "________________________________________________________________ " << endl;

  long start_time2; //Timer for twice the core count
  long stop_time2;//End timer for twice the core count
  
  Matrix MatrixC2(MatrixA.getRow(),MatrixB.getColumn()); //MatrixC2 gets A rows and B cols
  start_time2= clock();//Start timer for function for twice core count
  HorizontalMultiply2(MatrixA, MatrixB, MatrixC2);//Twice core count multipling
  stop_time2 = clock();//End timer for function for twice core count
  
  double Horizontal_Time2 = (stop_time2-start_time2)/(double)(CLOCKS_PER_SEC); //Total execution time of twice core count Multiply
  
  MatrixC2.print();//Print Matrix C 
  
  cout << endl;
  cout << "_______________________________________________________________"<< endl;
  cout << "Divide Horizontal Time: (Twice amount of Cores in a system): " << Horizontal_Time2 << " seconds " << endl;
  cout << "_______________________________________________________________" << endl;
  
  return 0;
}
示例#4
0
文件: naomngt.cpp 项目: no-ox/IMAR-C
void im_leave_one_out(std::string bddName,
		      int k){
  std::string path2bdd("bdd/" + bddName);
  std::string KMeansFile(path2bdd + "/" + "training.means");
  
  //  std::cout << path2bdd << std::endl;
  // Loading BDD
  IMbdd bdd(bddName,path2bdd);
  bdd.load_bdd_configuration(path2bdd.c_str(),"imconfig.xml");
  
  // Saving KMeans settings
  bdd.changeKMSettings("specifical", k, "training.means");
  
  // Loading feature points settings
  std::string descriptor = bdd.getDescriptor();
  
  // Loading activities
  std::vector<std::string> activities = bdd.getActivities();
  int nrActivities = activities.size();
  int labels[nrActivities];
  int index = 0;
  for(std::vector<std::string>::iterator activity = activities.begin();
      activity != activities.end();
      ++activity){
    labels[index] = index + 1;
    index++;
  }
  if(k%nrActivities != 0){
    std::cerr << "k is not divisible by nrActivities !" << std::endl;
    exit(EXIT_FAILURE);
  }
  
  MatrixC trainMC = MatrixC(nrActivities,labels);
  MatrixC testMC = MatrixC(nrActivities,labels);
  double crossValidationAccuracy = 0;
  std::vector<std::string> people = bdd.getPeople();
  // Leave One Person Out 
  for(std::vector<std::string>::iterator person = people.begin() ;
      person != people.end();
      ++person){
    std::vector<std::string> testingPeople;
    std::vector<std::string> trainingPeople;
    testingPeople.push_back(*person);
    // Filling trainingPeople
    for(std::vector<std::string>::iterator trainingPerson = people.begin() ;
	trainingPerson != people.end();
	++trainingPerson){
      if((*trainingPerson).compare(*person) != 0)
	trainingPeople.push_back(*trainingPerson);
    }
    std::cout << "Testing" << *person << std::endl;
    im_create_specifics_training_means(bdd, trainingPeople);
    crossValidationAccuracy += im_svm_train(bdd,
					    trainingPeople, trainMC,
					    testingPeople, testMC);
    std::cout << "Test " << *person << " ok!" << std::endl;
  }
  crossValidationAccuracy /= people.size();
  
  trainMC.calculFrequence();
  trainMC.exportMC(path2bdd,"training_confusion_matrix.txt");
  trainMC.output();
  testMC.calculFrequence();
  testMC.exportMC(path2bdd,"testing_confusion_matrix.txt");
  testMC.output();
  
  std::cout << "#######################################" << std::endl;
  std::cout << "######## RESUME OF THE TEST ###########" << std::endl;
  std::cout << "#######################################" << std::endl;
  std::cout << "Number of people: " << people.size() << std::endl;
  std::cout << "Descriptor ID: " << descriptor << std::endl;
  std::cout << "Number of means: " << k << std::endl;
  std::cout << "Train recognition rate:" << std::endl;
  std::cout << "\t cross validation accuracy=" << crossValidationAccuracy << std::endl;
  std::cout << "\t tau_train=" << trainMC.recognitionRate*100 << "%" << std::endl;
  std::cout << "\t total number of train BOWs=" << trainMC.nrTest << std::endl;
  std::cout << "Test recognition rate:" << std::endl;
  std::cout << "\t tau_test=" << testMC.recognitionRate*100 << "%" << std::endl;
  std::cout << "\t total number of test BOWs=" << testMC.nrTest << std::endl;
}