|
@@ -17,6 +17,7 @@
|
|
|
|
|
|
// gp-hik-core includes
|
|
|
#include "gp-hik-core/GPHIKClassifier.h"
|
|
|
+#include "gp-hik-core/GPHIKRawClassifier.h"
|
|
|
|
|
|
#include "TestGPHIKOnlineLearnable.h"
|
|
|
|
|
@@ -116,6 +117,33 @@ void evaluateClassifier ( NICE::Matrix & confusionMatrix,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void evaluateClassifierRaw ( NICE::Matrix & confusionMatrix,
|
|
|
+ const NICE::GPHIKRawClassifier * classifier,
|
|
|
+ const NICE::Matrix & data,
|
|
|
+ const NICE::Vector & yMulti,
|
|
|
+ const std::map< uint,uint > & mapClNoToIdxTrain,
|
|
|
+ const std::map< uint,uint > & mapClNoToIdxTest
|
|
|
+ )
|
|
|
+{
|
|
|
+ int i_loopEnd ( (int)data.rows() );
|
|
|
+
|
|
|
+ for (int i = 0; i < i_loopEnd ; i++)
|
|
|
+ {
|
|
|
+ NICE::Vector example_nonsparse ( data.getRow(i) );
|
|
|
+ NICE::SparseVector example (example_nonsparse);
|
|
|
+ NICE::SparseVector scores;
|
|
|
+ uint result;
|
|
|
+
|
|
|
+ // classify with incrementally trained classifier
|
|
|
+ classifier->classify( &example, result, scores );
|
|
|
+
|
|
|
+ uint gtlabel = mapClNoToIdxTest.find(yMulti[i])->second;
|
|
|
+ uint predlabel = mapClNoToIdxTrain.find(result)->second;
|
|
|
+ confusionMatrix( gtlabel, predlabel ) += 1.0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
void compareClassifierOutputs ( const NICE::GPHIKClassifier * classifier,
|
|
|
const NICE::GPHIKClassifier * classifierScratch,
|
|
|
const NICE::Matrix & data
|
|
@@ -279,6 +307,7 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
|
|
|
|
|
|
conf.sB ( "GPHIKClassifier", "eig_verbose", false);
|
|
|
conf.sS ( "GPHIKClassifier", "optimization_method", "downhillsimplex");
|
|
|
+ conf.sB ( "GPHIKClassifier", "verbose", true);
|
|
|
|
|
|
std::string s_trainData = conf.gS( "main", "trainData", "toyExampleSmallScaleTrain.data" );
|
|
|
|
|
@@ -335,6 +364,8 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
|
|
|
NICE::GPHIKClassifier * classifierScratch = new NICE::GPHIKClassifier ( &conf );
|
|
|
classifierScratch->train ( examplesTrain, yBinTrain );
|
|
|
|
|
|
+ NICE::GPHIKRawClassifier * classifierScratchRaw = new NICE::GPHIKRawClassifier ( &conf );
|
|
|
+ classifierScratchRaw->train ( examplesTrain, yBinTrain );
|
|
|
|
|
|
// TEST both classifiers to produce equal results
|
|
|
|
|
@@ -363,17 +394,19 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
|
|
|
|
|
|
NICE::Matrix confusionMatrix ( mapClNoToIdxTrain.size(), mapClNoToIdxTest.size(), 0.0);
|
|
|
NICE::Matrix confusionMatrixScratch ( mapClNoToIdxTrain.size(), mapClNoToIdxTest.size(), 0.0);
|
|
|
-
|
|
|
+ NICE::Matrix confusionMatrixScratchRaw ( mapClNoToIdxTrain.size(), mapClNoToIdxTest.size(), 0.0);
|
|
|
|
|
|
// ------------------------------------------
|
|
|
// ------------- CLASSIFICATION --------------
|
|
|
// ------------------------------------------
|
|
|
evaluateClassifier ( confusionMatrix, classifier, dataTest, yBinTest,
|
|
|
- mapClNoToIdxTrain,mapClNoToIdxTest );
|
|
|
+ mapClNoToIdxTrain, mapClNoToIdxTest );
|
|
|
|
|
|
evaluateClassifier ( confusionMatrixScratch, classifierScratch, dataTest, yBinTest,
|
|
|
- mapClNoToIdxTrain,mapClNoToIdxTest );
|
|
|
+ mapClNoToIdxTrain, mapClNoToIdxTest );
|
|
|
|
|
|
+ evaluateClassifierRaw ( confusionMatrixScratchRaw, classifierScratchRaw, dataTest, yBinTest,
|
|
|
+ mapClNoToIdxTrain, mapClNoToIdxTest );
|
|
|
|
|
|
// post-process confusion matrices
|
|
|
confusionMatrix.normalizeColumnsL1();
|
|
@@ -382,20 +415,26 @@ void TestGPHIKOnlineLearnable::testOnlineLearningOCCtoBinary()
|
|
|
confusionMatrixScratch.normalizeColumnsL1();
|
|
|
double arrScratch ( confusionMatrixScratch.trace()/confusionMatrixScratch.cols() );
|
|
|
|
|
|
+ confusionMatrixScratchRaw.normalizeColumnsL1();
|
|
|
+ double arrScratchRaw ( confusionMatrixScratchRaw.trace()/confusionMatrixScratchRaw.cols() );
|
|
|
|
|
|
if ( verbose )
|
|
|
{
|
|
|
std::cerr << "confusionMatrix: " << confusionMatrix << std::endl;
|
|
|
|
|
|
std::cerr << "confusionMatrixScratch: " << confusionMatrixScratch << std::endl;
|
|
|
+
|
|
|
+ std::cerr << "confusionMatrixScratchRaw: " << confusionMatrixScratchRaw << std::endl;
|
|
|
}
|
|
|
|
|
|
CPPUNIT_ASSERT_DOUBLES_EQUAL( arr, arrScratch, 1e-8);
|
|
|
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( arrScratch, arrScratchRaw, 1e-8);
|
|
|
|
|
|
// don't waste memory
|
|
|
|
|
|
delete classifier;
|
|
|
delete classifierScratch;
|
|
|
+ delete classifierScratchRaw;
|
|
|
|
|
|
for (std::vector< const NICE::SparseVector *>::iterator exTrainIt = examplesTrain.begin(); exTrainIt != examplesTrain.end(); exTrainIt++)
|
|
|
{
|