fork download
  1. void run_test_pairs_subforest( CPairForest & rf, const HyperParameters & hp ){
  2.  
  3. FileData testData(hp.testData, hp.testLabels);
  4. testData.readData();
  5. testData.readLabels();
  6.  
  7. // testData.decreaseLabelsByOne();
  8. testData.setNumClassesFromLabels();
  9.  
  10. testData.dumpStatistics();
  11.  
  12. std::vector<CPairForest> vForest;
  13. vForest.resize(hp.nNumForests);
  14.  
  15. std::vector<CPairTree> vTrees;
  16. std::vector<int> vTreesTest;
  17. std::vector<int> vTreeIDs;
  18.  
  19. double overallAcc = 0, overallCatAcc = 0;
  20. double tmpAcc = 0, tmpCatAcc = 0;
  21.  
  22. matrix<float> mAvgConfMat;
  23. mAvgConfMat = zero_matrix<float>(hp.numClasses, hp.numClasses);
  24.  
  25. for(int i=0; i < hp.nNumForests; i++){
  26. std::cout << "\n#Forest: " << i << std::endl;
  27. timeIt(1);
  28. rf.getRandomTrees(hp.nNumTreesPerForest, vTrees);
  29. //rf.getRandomTrees(hp.nNumTreesPerForest, vTreesTest);
  30.  
  31. vForest[i] = CPairForest(hp, vTrees, hp.nNumTreesPerForest);
  32. vForest[i].eval(testData.getData(), testData.getLabels());
  33. vForest[i].computeStatistics();
  34. vForest[i].getTreeIDs(vTreeIDs);
  35.  
  36. tmpCatAcc = vForest[i].getMeanCategoryAcc();
  37. tmpAcc = vForest[i].getOverallAcc();
  38. std::cout << "Mean Category Accuracy: " << tmpCatAcc << "\n";
  39. std::cout << "Overall Accuracy: " << tmpAcc << "\n";
  40. std::cout << "\tTest time = " << timeIt(0) << " seconds\n\n";
  41.  
  42. mAvgConfMat += vForest[i].getConfMatrix();
  43.  
  44. if (hp.bSaveStats) {
  45. std::string strPredOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.predOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
  46. vForest[i].writePredictions(strPredOutputFilename);
  47.  
  48. std::string strConfOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.confOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
  49. vForest[i].writeConfidences(strConfOutputFilename);
  50.  
  51. std::string strStatsOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.statsOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
  52. vForest[i].writeStatistics(strStatsOutputFilename);
  53.  
  54. std::string strConfmatrixOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.strConfMatrixFilename) + "_pairforest_" + convertToString(i) + ".txt";
  55. vForest[i].saveConfMatrixLatex(strConfmatrixOutputFilename);
  56.  
  57. std::string strTreeOutputFilename = hp.savePath + "/" + "pairforest_" + convertToString(i) + "_trees_idx" + ".txt";
  58. writeVector( vTreeIDs, strTreeOutputFilename );
  59. }
  60.  
  61. overallCatAcc += tmpCatAcc;
  62. overallAcc += tmpAcc;
  63. vTrees.clear();
  64. vTreeIDs.clear();
  65. }
  66.  
  67. overallCatAcc *= 1.0/(hp.nNumForests);
  68. overallAcc *= 1.0/(hp.nNumForests);
  69. mAvgConfMat *= 1.0/(hp.nNumForests);
  70.  
  71. std::cout << "Final Results Multiple-Forest:\n";
  72. std::cout << "NumForest: " << hp.nNumForests << "\n";
  73. std::cout << "Num. Trees in each Forest: " << hp.nNumTreesPerForest << "\n";
  74. std::cout << "Overal Per Category Accuracy: " << overallCatAcc << "\n";
  75. std::cout << "Overal Accuracy: " << overallAcc << "\n\n";
  76.  
  77. rf.eval(testData.getData(), testData.getLabels());
  78. rf.computeStatistics();
  79. rf.getTreeIDs(vTreeIDs);
  80.  
  81. std::cout << "Final Results Single-Forest: " << "\n";
  82. std::cout << "Num. Trees in Forest: " << hp.numTrees << "\n";
  83. std::cout << "Mean Category Accuracy: " << rf.getMeanCategoryAcc() << "\n";
  84. std::cout << "Overall Accuracy: " << rf.getOverallAcc() << "\n";
  85.  
  86. if (hp.bSaveStats) {
  87. std::string strPredOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.predOutputFilename) + "_pairforest_global" + ".txt";
  88. rf.writePredictions(strPredOutputFilename);
  89.  
  90. std::string strConfOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.confOutputFilename) + "_pairforest_global" + ".txt";
  91. rf.writeConfidences(strConfOutputFilename);
  92.  
  93. std::string strStatsOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.statsOutputFilename) + "_pairforest_global" + ".txt";
  94. rf.writeStatistics(strStatsOutputFilename);
  95.  
  96. std::string strConfmatrixOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.strConfMatrixFilename) + "_pairforest_global" + ".txt";
  97. rf.saveConfMatrixLatex(strConfmatrixOutputFilename);
  98.  
  99. std::string strTreeOutputFilename = hp.savePath + "/" + "pairforest_global" + "_trees_idx" + ".txt";
  100. writeVector( vTreeIDs, strTreeOutputFilename );
  101.  
  102. std::string strConfavgMatOutputFilename = hp.savePath + "/" + "pairforest_avgconfmatrix" + ".txt";
  103. writeMatrixLatex( mAvgConfMat, strConfavgMatOutputFilename );
  104. }
  105. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:32: error: variable or field 'run_test_pairs_subforest' declared void
prog.cpp:1:32: error: 'CPairForest' was not declared in this scope
prog.cpp:1:46: error: 'rf' was not declared in this scope
prog.cpp:1:50: error: expected primary-expression before 'const'
stdout
Standard output is empty