void run_test_pairs_subforest( CPairForest & rf, const HyperParameters & hp ){
FileData testData(hp.testData, hp.testLabels);
testData.readData();
testData.readLabels();
// testData.decreaseLabelsByOne();
testData.setNumClassesFromLabels();
testData.dumpStatistics();
std::vector<CPairForest> vForest;
vForest.resize(hp.nNumForests);
std::vector<CPairTree> vTrees;
std::vector<int> vTreesTest;
std::vector<int> vTreeIDs;
double overallAcc = 0, overallCatAcc = 0;
double tmpAcc = 0, tmpCatAcc = 0;
matrix<float> mAvgConfMat;
mAvgConfMat = zero_matrix<float>(hp.numClasses, hp.numClasses);
for(int i=0; i < hp.nNumForests; i++){
std::cout << "\n#Forest: " << i << std::endl;
timeIt(1);
rf.getRandomTrees(hp.nNumTreesPerForest, vTrees);
//rf.getRandomTrees(hp.nNumTreesPerForest, vTreesTest);
vForest[i] = CPairForest(hp, vTrees, hp.nNumTreesPerForest);
vForest[i].eval(testData.getData(), testData.getLabels());
vForest[i].computeStatistics();
vForest[i].getTreeIDs(vTreeIDs);
tmpCatAcc = vForest[i].getMeanCategoryAcc();
tmpAcc = vForest[i].getOverallAcc();
std::cout << "Mean Category Accuracy: " << tmpCatAcc << "\n";
std::cout << "Overall Accuracy: " << tmpAcc << "\n";
std::cout << "\tTest time = " << timeIt(0) << " seconds\n\n";
mAvgConfMat += vForest[i].getConfMatrix();
if (hp.bSaveStats) {
std::string strPredOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.predOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
vForest[i].writePredictions(strPredOutputFilename);
std::string strConfOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.confOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
vForest[i].writeConfidences(strConfOutputFilename);
std::string strStatsOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.statsOutputFilename) + "_pairforest_" + convertToString(i) + ".txt";
vForest[i].writeStatistics(strStatsOutputFilename);
std::string strConfmatrixOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.strConfMatrixFilename) + "_pairforest_" + convertToString(i) + ".txt";
vForest[i].saveConfMatrixLatex(strConfmatrixOutputFilename);
std::string strTreeOutputFilename = hp.savePath + "/" + "pairforest_" + convertToString(i) + "_trees_idx" + ".txt";
writeVector( vTreeIDs, strTreeOutputFilename );
}
overallCatAcc += tmpCatAcc;
overallAcc += tmpAcc;
vTrees.clear();
vTreeIDs.clear();
}
overallCatAcc *= 1.0/(hp.nNumForests);
overallAcc *= 1.0/(hp.nNumForests);
mAvgConfMat *= 1.0/(hp.nNumForests);
std::cout << "Final Results Multiple-Forest:\n";
std::cout << "NumForest: " << hp.nNumForests << "\n";
std::cout << "Num. Trees in each Forest: " << hp.nNumTreesPerForest << "\n";
std::cout << "Overal Per Category Accuracy: " << overallCatAcc << "\n";
std::cout << "Overal Accuracy: " << overallAcc << "\n\n";
rf.eval(testData.getData(), testData.getLabels());
rf.computeStatistics();
rf.getTreeIDs(vTreeIDs);
std::cout << "Final Results Single-Forest: " << "\n";
std::cout << "Num. Trees in Forest: " << hp.numTrees << "\n";
std::cout << "Mean Category Accuracy: " << rf.getMeanCategoryAcc() << "\n";
std::cout << "Overall Accuracy: " << rf.getOverallAcc() << "\n";
if (hp.bSaveStats) {
std::string strPredOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.predOutputFilename) + "_pairforest_global" + ".txt";
rf.writePredictions(strPredOutputFilename);
std::string strConfOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.confOutputFilename) + "_pairforest_global" + ".txt";
rf.writeConfidences(strConfOutputFilename);
std::string strStatsOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.statsOutputFilename) + "_pairforest_global" + ".txt";
rf.writeStatistics(strStatsOutputFilename);
std::string strConfmatrixOutputFilename = hp.savePath + "/" + getFilenameWithoutExtension(hp.strConfMatrixFilename) + "_pairforest_global" + ".txt";
rf.saveConfMatrixLatex(strConfmatrixOutputFilename);
std::string strTreeOutputFilename = hp.savePath + "/" + "pairforest_global" + "_trees_idx" + ".txt";
writeVector( vTreeIDs, strTreeOutputFilename );
std::string strConfavgMatOutputFilename = hp.savePath + "/" + "pairforest_avgconfmatrix" + ".txt";
writeMatrixLatex( mAvgConfMat, strConfavgMatOutputFilename );
}
}