|
@@ -185,7 +185,11 @@ void myClassifierStoreRestoreTest( GPHIKClassifierNICE & classifier, const Matri
|
|
|
|
|
|
}
|
|
|
|
|
|
-void myClassifierILTest( GPHIKClassifierNICE & classifierRetrain, GPHIKClassifierNICE & classifierIL, const Matrix & mX, const Vector & vY )
|
|
|
+void myClassifierILTest( OBJREC::GPHIKClassifierNICE & classifierRetrain,
|
|
|
+ OBJREC::GPHIKClassifierNICE & classifierIL,
|
|
|
+ const Matrix & mX,
|
|
|
+ const Vector & vY
|
|
|
+ )
|
|
|
{
|
|
|
|
|
|
if (verboseStartEnd)
|
|
@@ -220,58 +224,72 @@ void myClassifierILTest( GPHIKClassifierNICE & classifierRetrain, GPHIKClassifie
|
|
|
|
|
|
if ( verbose )
|
|
|
std::cerr << "learning ..." << std::endl;
|
|
|
+ Timer t;
|
|
|
+ t.start();
|
|
|
classifierIL.train ( fp, examples );
|
|
|
+ t.stop();
|
|
|
+ std::cerr << "Time used for initial training: " << t.getLast() << std::endl;
|
|
|
|
|
|
//choose next example(s)
|
|
|
|
|
|
+ int i_numExamplesToAdd ( 2 );
|
|
|
+
|
|
|
Examples newExamples;
|
|
|
for ( uint i = 0 ; i < vY.size() ; i++ )
|
|
|
{
|
|
|
if ( i % 4 == 3 )
|
|
|
{
|
|
|
Example example;
|
|
|
- example.svec = new SparseVector;
|
|
|
+ example.svec = new SparseVector();
|
|
|
example.svec->setDim(3);
|
|
|
example.svec->set ( 0, mX(i,0) );
|
|
|
example.svec->set ( 1, mX(i,1) );
|
|
|
example.svec->set ( 2, 1.0-mX(i,0)-mX(i,1) );
|
|
|
- newExamples.push_back ( pair<int, Example> ( vY[i], example ) );
|
|
|
- }
|
|
|
+ newExamples.push_back ( std::pair<int, Example> ( vY[i], example ) );
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( newExamples.size() == i_numExamplesToAdd )
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
-// if ( verbose )
|
|
|
- std::cerr << std::endl << " =============== " << std::endl << "incremental learning ..." << std::endl;
|
|
|
-
|
|
|
- // add them to classifierIL
|
|
|
-// std::cerr << "We add several new examples" << std::endl;
|
|
|
- Timer t;
|
|
|
- t.start();
|
|
|
-// for (uint i = 0; i < newExamples.size(); i++)
|
|
|
- for (uint i = 0; i < 1; i++)
|
|
|
- {
|
|
|
- classifierIL.addExample( newExamples[i].second, newExamples[i].first);
|
|
|
- }
|
|
|
|
|
|
- t.stop();
|
|
|
- std::cerr << "Time used for incremental training: " << t.getLast() << std::endl;
|
|
|
-
|
|
|
+ i_numExamplesToAdd = std::min ( i_numExamplesToAdd, (int) newExamples.size() );
|
|
|
//add the new features to feature pool needed for batch training
|
|
|
-// for (uint i = 0; i < newExamples.size(); i++)
|
|
|
- for (uint i = 0; i < 2; i++)
|
|
|
+ for (uint i = 0; i < i_numExamplesToAdd; i++)
|
|
|
{
|
|
|
examples.push_back( newExamples[i] );
|
|
|
}
|
|
|
|
|
|
- std::cerr << std::endl << " =============== " << std::endl << "We train the second classifier from the scratch with the additional new example" << std::endl;
|
|
|
+ std::cerr << std::endl << " =============== " << std::endl << "We train the second classifier from scratch with the additional new example" << std::endl;
|
|
|
t.start();
|
|
|
|
|
|
classifierRetrain.train ( fp, examples );
|
|
|
|
|
|
t.stop();
|
|
|
- std::cerr << "Time used for batch training: " << t.getLast() << std::endl;
|
|
|
+ std::cerr << "Time used for batch training: " << t.getLast() << std::endl;
|
|
|
+
|
|
|
+ if ( verbose )
|
|
|
+ std::cerr << std::endl << " =============== " << std::endl << "incremental learning ..." << std::endl;
|
|
|
+
|
|
|
+ // add them to classifierIL
|
|
|
+ t.start();
|
|
|
+ if ( verbose )
|
|
|
+ std::cerr << "We add " << i_numExamplesToAdd << " new examples" << std::endl;
|
|
|
+ if ( i_numExamplesToAdd > 1 )
|
|
|
+ classifierIL.addMultipleExamples( newExamples );
|
|
|
+ else if ( i_numExamplesToAdd == 1 )
|
|
|
+ classifierIL.addExample( newExamples[0].second, newExamples[0].first);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //nothing to do
|
|
|
+ }
|
|
|
+
|
|
|
+ t.stop();
|
|
|
+ std::cerr << "Time used for incremental training: " << t.getLast() << std::endl;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
//evaluate both and compare the resulting scores
|
|
|
-// if ( verbose )
|
|
|
+ if ( verbose )
|
|
|
std::cerr << "testing ..." << std::endl;
|
|
|
for ( uint i = 0 ; i < vY.size() ; i++ )
|
|
|
if ( i % 2 == 0 )
|
|
@@ -301,6 +319,7 @@ void myClassifierILTest( GPHIKClassifierNICE & classifierRetrain, GPHIKClassifie
|
|
|
{
|
|
|
if ( fabs(resultIL.scores[i] - resultBatch.scores[i]) > 10e-3)
|
|
|
{
|
|
|
+ std::cerr << " resultIL.scores[i]: " << resultIL.scores[i] << " resultBatch.scores[i]: " << resultBatch.scores[i] << std::endl;
|
|
|
equal = false;
|
|
|
break;
|
|
|
}
|
|
@@ -320,20 +339,21 @@ void TestGPHIKClassifier::testGPHIKClassifier()
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestGPHIKClassifier::testGPHIKClassifier ===================== " << std::endl;
|
|
|
|
|
|
- Config conf;
|
|
|
+ NICE::Config conf;
|
|
|
conf.sD( "GPHIKClassifier", "noise", 0.01 );
|
|
|
conf.sD( "GPHIKClassifier", "parameter_lower_bound", 0.5 );
|
|
|
conf.sD( "GPHIKClassifier", "parameter_upper_bound", 3.5 );
|
|
|
- conf.sI( "GPHIKClassifier", "uncertaintyPrediction", 1);
|
|
|
// conf.sS( "GPHIKClassifier", "optimization_method", "none");
|
|
|
+// conf.sD( "GPHIKClassifier", "performOptimizationAfterIncrement", false );
|
|
|
conf.sS( "GPHIKClassifier", "optimization_method", "downhillsimplex");
|
|
|
- conf.sB( "GPHIKClassifier", "uncertaintyPredictionForClassification", true);
|
|
|
+ conf.sD( "GPHIKClassifier", "performOptimizationAfterIncrement", true );
|
|
|
+ conf.sB( "GPHIKClassifier", "uncertaintyPredictionForClassification", false);
|
|
|
|
|
|
- GPHIKClassifierNICE * classifier = new GPHIKClassifierNICE ( &conf );
|
|
|
+ OBJREC::GPHIKClassifierNICE * classifier = new OBJREC::GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
|
|
|
- Matrix mX;
|
|
|
- Vector vY;
|
|
|
- Vector vY_multi;
|
|
|
+ NICE::Matrix mX;
|
|
|
+ NICE::Vector vY;
|
|
|
+ NICE::Vector vY_multi;
|
|
|
|
|
|
// ifstream ifs ("toyExample1.data", ios::in);
|
|
|
// ifstream ifs ("toyExampleLargeScale.data", ios::in);
|
|
@@ -366,8 +386,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
|
|
|
if (classifier != NULL)
|
|
|
delete classifier;
|
|
|
|
|
|
- classifier = new GPHIKClassifierNICE ( &conf );
|
|
|
- GPHIKClassifierNICE * classifierBatch = new GPHIKClassifierNICE ( &conf );
|
|
|
+ classifier = new OBJREC::GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
+ OBJREC::GPHIKClassifierNICE * classifierBatch = new OBJREC::GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
|
|
|
myClassifierILTest( *classifierBatch, *classifier, mX, vY );
|
|
|
|
|
@@ -376,8 +396,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
|
|
|
if (classifierBatch != NULL)
|
|
|
delete classifierBatch;
|
|
|
|
|
|
- classifier = new GPHIKClassifierNICE ( &conf );
|
|
|
- classifierBatch = new GPHIKClassifierNICE ( &conf );
|
|
|
+ classifier = new OBJREC::GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
+ classifierBatch = new OBJREC::GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
|
|
|
if ( verbose )
|
|
|
std::cerr << "Multi-class classification test " << std::endl;
|
|
@@ -393,8 +413,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
|
|
|
if (classifierBatch != NULL)
|
|
|
delete classifierBatch;
|
|
|
|
|
|
- classifier = new GPHIKClassifierNICE ( &conf );
|
|
|
- classifierBatch = new GPHIKClassifierNICE ( &conf );
|
|
|
+ classifier = new GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
+ classifierBatch = new GPHIKClassifierNICE ( &conf, "GPHIKClassifier" );
|
|
|
|
|
|
myClassifierILTest( *classifierBatch, *classifier, mX, vY_multi );
|
|
|
|
|
@@ -512,10 +532,10 @@ void TestGPHIKClassifier::testGPHIKVariance()
|
|
|
ClassificationResult rVarApproxFine2 = classifierVarApproxFine2.classify ( example );
|
|
|
ClassificationResult rExact = classifierVarExact.classify ( example );
|
|
|
|
|
|
- if (verbose)
|
|
|
- {
|
|
|
+// if (verbose)
|
|
|
+// {
|
|
|
std::cerr << "approxUnc: " << r.uncertainty << " approxUncQuant: " << rQuant.uncertainty<< " approxUncFine1: " << rVarApproxFine1.uncertainty << " approxUncFine2: " << rVarApproxFine2.uncertainty << " exactUnc: " << rExact.uncertainty << std::endl;
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
CPPUNIT_ASSERT ( r.uncertainty <= (1.0 + noise) ); //using the "standard" HIK, this is the upper bound
|
|
|
CPPUNIT_ASSERT ( r.uncertainty > rVarApproxFine1.uncertainty);
|