Эх сурвалжийг харах

adapted GPHIKClassifier into FP-framework and corrected dependencies

Alexander Freytag 12 жил өмнө
parent
commit
5a03386475

+ 25 - 25
classifier/fpclassifier/GPHIKClassifierNICE.cpp → classifier/fpclassifier/FPCGPHIK.cpp

@@ -1,5 +1,5 @@
 /** 
-* @file GPHIKClassifierNICE.cpp
+* @file FPCGPHIK.cpp
 * @brief feature pool interface for our GP HIK classifier
 * @author Alexander Freytag
 * @date 02/01/2012
@@ -10,14 +10,14 @@
 #include "core/basics/numerictools.h"
 #include <core/basics/Timer.h>
 
-#include "GPHIKClassifierNICE.h"
+#include "FPCGPHIK.h"
 
 using namespace std;
 using namespace NICE;
 using namespace OBJREC;
 
 
-GPHIKClassifierNICE::GPHIKClassifierNICE( const Config *conf, const string & confSection ) 
+FPCGPHIK::FPCGPHIK( const Config *conf, const string & confSection ) 
 {
   this->verbose = conf->gB(confSection, "verbose", false);
   this->useSimpleBalancing = conf->gB(confSection, "use_simple_balancing", false);
@@ -27,22 +27,22 @@ GPHIKClassifierNICE::GPHIKClassifierNICE( const Config *conf, const string & con
   classifier = new GPHIKClassifier(conf, confSection);
 }
 
-GPHIKClassifierNICE::~GPHIKClassifierNICE()
+FPCGPHIK::~FPCGPHIK()
 {
   if ( classifier != NULL )
     delete classifier;
 }
 
-ClassificationResult GPHIKClassifierNICE::classify ( Example & pe )
+ClassificationResult FPCGPHIK::classify ( Example & pe )
 {
   const SparseVector *svec = pe.svec;
 
   if ( svec == NULL )
-    fthrow(Exception, "GPHIKClassifierNICE requires example.svec (SparseVector stored in an Example struct)");
+    fthrow(Exception, "FPCGPHIK requires example.svec (SparseVector stored in an Example struct)");
  return this->classify( svec ); 
 }
 
-ClassificationResult GPHIKClassifierNICE::classify ( const NICE::SparseVector * example )
+ClassificationResult FPCGPHIK::classify ( const NICE::SparseVector * example )
 {
   NICE::SparseVector scores;
   int result;
@@ -72,9 +72,9 @@ ClassificationResult GPHIKClassifierNICE::classify ( const NICE::SparseVector *
   
   if (verbose)
   {
-    std::cerr << " GPHIKClassifierNICE::classify scores" << std::endl;
+    std::cerr << " FPCGPHIK::classify scores" << std::endl;
     scores.store(std::cerr);
-    std::cerr << " GPHIKClassifierNICE::classify fvscores" << std::endl;
+    std::cerr << " FPCGPHIK::classify fvscores" << std::endl;
     fvscores.store(std::cerr);
   }
 
@@ -82,7 +82,7 @@ ClassificationResult GPHIKClassifierNICE::classify ( const NICE::SparseVector *
 }
 
 /** training process */
-void GPHIKClassifierNICE::train ( FeaturePool & fp, Examples & examples )
+void FPCGPHIK::train ( FeaturePool & fp, Examples & examples )
 {
   // we completely ignore the feature pool :)
   //
@@ -91,7 +91,7 @@ void GPHIKClassifierNICE::train ( FeaturePool & fp, Examples & examples )
   int minClass = -1;
   
   if (verbose) 
-    std::cerr << "GPHIKClassifierNICE::train" << std::endl;
+    std::cerr << "FPCGPHIK::train" << std::endl;
 
   if ( useSimpleBalancing)
   {
@@ -136,7 +136,7 @@ void GPHIKClassifierNICE::train ( FeaturePool & fp, Examples & examples )
 
     y[ sparseExamples.size() ] = classno;
     if ( example.svec == NULL )
-      fthrow(Exception, "GPHIKClassifierNICE requires example.svec (SparseVector stored in an Example struct)");
+      fthrow(Exception, "FPCGPHIK requires example.svec (SparseVector stored in an Example struct)");
     sparseExamples.push_back( example.svec );    
   }
 
@@ -147,34 +147,34 @@ void GPHIKClassifierNICE::train ( FeaturePool & fp, Examples & examples )
 }
 
 /** training process */
-void GPHIKClassifierNICE::train ( const std::vector< SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels )
+void FPCGPHIK::train ( const std::vector< SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels )
 {
   classifier->train(examples, binLabels);
 }
 
-void GPHIKClassifierNICE::clear ()
+void FPCGPHIK::clear ()
 {
   if ( classifier != NULL )
     delete classifier;
   classifier = NULL;
 }
 
-FeaturePoolClassifier *GPHIKClassifierNICE::clone () const
+FeaturePoolClassifier *FPCGPHIK::clone () const
 {
-  fthrow(Exception, "GPHIKClassifierNICE: clone() not yet implemented" );
+  fthrow(Exception, "FPCGPHIK: clone() not yet implemented" );
 
   return NULL;
 }
 
-void GPHIKClassifierNICE::predictUncertainty( Example & pe, NICE::Vector & uncertainties )
+void FPCGPHIK::predictUncertainty( Example & pe, NICE::Vector & uncertainties )
 {
   const SparseVector *svec = pe.svec;  
   if ( svec == NULL )
-    fthrow(Exception, "GPHIKClassifierNICE requires example.svec (SparseVector stored in an Example struct)");
+    fthrow(Exception, "FPCGPHIK requires example.svec (SparseVector stored in an Example struct)");
   classifier->predictUncertainty(svec, uncertainties);
 }
    
-void GPHIKClassifierNICE::predictUncertainty( const NICE::SparseVector * example, NICE::Vector & uncertainties )
+void FPCGPHIK::predictUncertainty( const NICE::SparseVector * example, NICE::Vector & uncertainties )
 {  
   classifier->predictUncertainty(example, uncertainties);
 }
@@ -182,7 +182,7 @@ void GPHIKClassifierNICE::predictUncertainty( const NICE::SparseVector * example
 //---------------------------------------------------------------------
 //                           protected methods
 //---------------------------------------------------------------------
-void GPHIKClassifierNICE::restore ( std::istream & is, int format )
+void FPCGPHIK::restore ( std::istream & is, int format )
 {
   if (is.good())
   {
@@ -194,11 +194,11 @@ void GPHIKClassifierNICE::restore ( std::istream & is, int format )
   }
   else
   {
-    std::cerr << "GPHIKClassifierNICE::restore -- InStream not initialized - restoring not possible!" << std::endl;
+    std::cerr << "FPCGPHIK::restore -- InStream not initialized - restoring not possible!" << std::endl;
   }
 }
 
-void GPHIKClassifierNICE::store ( std::ostream & os, int format ) const
+void FPCGPHIK::store ( std::ostream & os, int format ) const
 {
   if (os.good())
   {
@@ -214,13 +214,13 @@ void GPHIKClassifierNICE::store ( std::ostream & os, int format ) const
   }
 }
 
-void GPHIKClassifierNICE::addExample( const Example & pe, const double & label)
+void FPCGPHIK::addExample( const Example & pe, const double & label)
 {
   const SparseVector *svec = pe.svec;
   classifier->addExample(svec, label, this->performOptimizationAfterIncrement);
 }
 
-void GPHIKClassifierNICE::addMultipleExamples( Examples & newExamples)
+void FPCGPHIK::addMultipleExamples( Examples & newExamples)
 {
   //are new examples available? If not, nothing has to be done
   if ( newExamples.size() < 1)
@@ -241,7 +241,7 @@ void GPHIKClassifierNICE::addMultipleExamples( Examples & newExamples)
 
     y[ i ] = classno;
     if ( example.svec == NULL )
-      fthrow(Exception, "GPHIKClassifierNICE requires example.svec (SparseVector stored in an Example struct)");
+      fthrow(Exception, "FPCGPHIK requires example.svec (SparseVector stored in an Example struct)");
     sparseExamples.push_back( example.svec );    
   }  
   

+ 5 - 5
classifier/fpclassifier/GPHIKClassifierNICE.h → classifier/fpclassifier/FPCGPHIK.h

@@ -1,5 +1,5 @@
 /** 
-* @file GPHIKClassifierNICE.h
+* @file FPCGPHIK.h
 * @author Alexander Freytag, Erik Rodner
 * @date 02/01/2012
 
@@ -17,12 +17,12 @@
 
 namespace OBJREC {
   
-/** @class GPHIKClassifierNICE
+/** @class FPCGPHIK
  * Wrapper class (feature pool interface) for our GP HIK classifier 
  *
  * @author Alexander Freytag, Erik Rodner
  */
-class GPHIKClassifierNICE : public FeaturePoolClassifier
+class FPCGPHIK : public FeaturePoolClassifier
 {
 
   protected:
@@ -42,10 +42,10 @@ class GPHIKClassifierNICE : public FeaturePoolClassifier
   public:
 
     /** simple constructor */
-    GPHIKClassifierNICE( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
+    FPCGPHIK( const NICE::Config *conf, const std::string & confSection = "GPHIKClassifier" );
       
     /** simple destructor */
-    virtual ~GPHIKClassifierNICE();
+    virtual ~FPCGPHIK();
    
     /** 
     * @brief classify a given example with the previously learnt model

+ 40 - 40
classifier/fpclassifier/tests/TestGPHIKClassifier.cpp → classifier/fpclassifier/tests/TestFPCGPHIK.cpp

@@ -16,11 +16,11 @@
 
 //----------
 
-#include "gp-hik-exp/GPHIKClassifierNICE.h"
+#include "vislearning/classifier/fpclassifier/FPCGPHIK.h"
 
 //----------
 
-#include "TestGPHIKClassifier.h"
+#include "TestFPCGPHIK.h"
 
 
 const bool verbose = false;
@@ -30,19 +30,19 @@ using namespace OBJREC;
 using namespace NICE;
 using namespace std;
 
-CPPUNIT_TEST_SUITE_REGISTRATION( TestGPHIKClassifier );
+CPPUNIT_TEST_SUITE_REGISTRATION( TestFPCGPHIK );
 
-void TestGPHIKClassifier::setUp() {
+void TestFPCGPHIK::setUp() {
 }
 
-void TestGPHIKClassifier::tearDown() {
+void TestFPCGPHIK::tearDown() {
 }
 
-void myClassifierTest( GPHIKClassifierNICE & classifier, const Matrix & mX, const Vector & vY )
+void myClassifierTest( FPCGPHIK & classifier, const Matrix & mX, const Vector & vY )
 {
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierTest ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierTest ===================== " << std::endl;
   
   Examples examples;
 
@@ -89,15 +89,15 @@ void myClassifierTest( GPHIKClassifierNICE & classifier, const Matrix & mX, cons
   examples.clean();
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierTest done ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierTest done ===================== " << std::endl;
 
 }
 
-void myClassifierStoreRestoreTest( GPHIKClassifierNICE & classifier, const Matrix & mX, const Vector & vY )
+void myClassifierStoreRestoreTest( FPCGPHIK & classifier, const Matrix & mX, const Vector & vY )
 {
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierStoreRestoreTest ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierStoreRestoreTest ===================== " << std::endl;
   
   Examples examples;
 
@@ -139,7 +139,7 @@ void myClassifierStoreRestoreTest( GPHIKClassifierNICE & classifier, const Matri
     std::cerr << "loading ..." << std::endl;  
   
   Config confTmp;
-  GPHIKClassifierNICE classifierRestored(&confTmp);
+  FPCGPHIK classifierRestored(&confTmp);
   
   std::filebuf fbIn;
   fbIn.open (destination.c_str(),ios::in);
@@ -181,15 +181,15 @@ void myClassifierStoreRestoreTest( GPHIKClassifierNICE & classifier, const Matri
   examples.clean();
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierStoreRestoreTest done ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierStoreRestoreTest done ===================== " << std::endl;
 
 }
 
-void myClassifierILTest( GPHIKClassifierNICE & classifierRetrain, GPHIKClassifierNICE & classifierIL, const Matrix & mX, const Vector & vY )
+void myClassifierILTest( FPCGPHIK & classifierRetrain, FPCGPHIK & classifierIL, const Matrix & mX, const Vector & vY )
 {
  
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierILTest ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierILTest ===================== " << std::endl;
   
   Examples examples;
   
@@ -312,24 +312,24 @@ void myClassifierILTest( GPHIKClassifierNICE & classifierRetrain, GPHIKClassifie
   examples.clean();
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::myClassifierILTest done ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::myClassifierILTest done ===================== " << std::endl;
 }
 
-void TestGPHIKClassifier::testGPHIKClassifier() 
+void TestFPCGPHIK::testFPCGPHIK() 
 {
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::testGPHIKClassifier ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::testFPCGPHIK ===================== " << std::endl;
 
   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.sS( "GPHIKClassifier", "optimization_method", "downhillsimplex");
-  conf.sB( "GPHIKClassifier", "uncertaintyPredictionForClassification", true);
+  conf.sD( "FPCGPHIK", "noise", 0.01 );
+  conf.sD( "FPCGPHIK", "parameter_lower_bound", 0.5 );
+  conf.sD( "FPCGPHIK", "parameter_upper_bound", 3.5 );
+  conf.sI( "FPCGPHIK", "uncertaintyPrediction", 1);
+//   conf.sS( "FPCGPHIK", "optimization_method", "none");
+  conf.sS( "FPCGPHIK", "optimization_method", "downhillsimplex");
+  conf.sB( "FPCGPHIK", "uncertaintyPredictionForClassification", true);
 
-  GPHIKClassifierNICE * classifier  = new GPHIKClassifierNICE ( &conf );
+  FPCGPHIK * classifier  = new FPCGPHIK ( &conf );
   
   Matrix mX;
   Vector vY;
@@ -366,8 +366,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
   if (classifier != NULL)
     delete classifier;
   
-  classifier  = new GPHIKClassifierNICE ( &conf );
-    GPHIKClassifierNICE * classifierBatch = new GPHIKClassifierNICE ( &conf ); 
+  classifier  = new FPCGPHIK ( &conf );
+    FPCGPHIK * classifierBatch = new FPCGPHIK ( &conf ); 
   
   myClassifierILTest( *classifierBatch, *classifier, mX, vY );
   
@@ -376,8 +376,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
   if (classifierBatch != NULL)
     delete classifierBatch;
   
-  classifier  = new GPHIKClassifierNICE ( &conf );
-  classifierBatch = new GPHIKClassifierNICE ( &conf );  
+  classifier  = new FPCGPHIK ( &conf );
+  classifierBatch = new FPCGPHIK ( &conf );  
 
   if ( verbose )
     std::cerr << "Multi-class classification test " << std::endl; 
@@ -393,8 +393,8 @@ void TestGPHIKClassifier::testGPHIKClassifier()
   if (classifierBatch != NULL)
     delete classifierBatch;
   
-  classifier  = new GPHIKClassifierNICE ( &conf );
-  classifierBatch = new GPHIKClassifierNICE ( &conf ); 
+  classifier  = new FPCGPHIK ( &conf, "GPHIKClassifier" /* section */);
+  classifierBatch = new FPCGPHIK ( &conf, "GPHIKClassifier" /* section */ ); 
   
   myClassifierILTest( *classifierBatch, *classifier, mX, vY_multi );
   
@@ -404,14 +404,14 @@ void TestGPHIKClassifier::testGPHIKClassifier()
     delete classifierBatch;  
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::testGPHIKClassifier done ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::testFPCGPHIK done ===================== " << std::endl;
  
 }
 
-void TestGPHIKClassifier::testGPHIKVariance()
+void TestFPCGPHIK::testGPHIKVariance()
 {
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::testGPHIKVariance ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::testGPHIKVariance ===================== " << std::endl;
 
   double noise (0.01);
   
@@ -423,28 +423,28 @@ void TestGPHIKClassifier::testGPHIKVariance()
   conf.sB( "GPHIKClassifier", "learn_balanced", true);
   conf.sB( "GPHIKClassifier", "uncertaintyPredictionForClassification", true);
   
-  GPHIKClassifierNICE classifier ( &conf );
+  FPCGPHIK classifier ( &conf );
   
   Config confVarApproxQuant(conf);
   confVarApproxQuant.sB( "GPHIKClassifier", "use_quantization", true );
-  GPHIKClassifierNICE classifierQuant ( &confVarApproxQuant );  
+  FPCGPHIK classifierQuant ( &confVarApproxQuant );  
 
   Config confVarApproxFine1(conf);
   confVarApproxFine1.sS( "GPHIKClassifier", "varianceApproximation", "approximate_fine");  
   confVarApproxFine1.sI( "GPHIKClassifier", "nrOfEigenvaluesToConsiderForVarApprox", 1);
   
-  GPHIKClassifierNICE classifierVarApproxFine1 ( &confVarApproxFine1 );  
+  FPCGPHIK classifierVarApproxFine1 ( &confVarApproxFine1 );  
 
   Config confVarApproxFine2(conf);
   confVarApproxFine2.sS( "GPHIKClassifier", "varianceApproximation", "approximate_fine");    
   confVarApproxFine2.sI( "GPHIKClassifier", "nrOfEigenvaluesToConsiderForVarApprox", 2);
   
-  GPHIKClassifierNICE classifierVarApproxFine2 ( &confVarApproxFine2 );    
+  FPCGPHIK classifierVarApproxFine2 ( &confVarApproxFine2 );    
   
   Config confExact(conf);
   confExact.sS( "GPHIKClassifier", "varianceApproximation", "exact");   
   
-  GPHIKClassifierNICE classifierVarExact ( &confExact );
+  FPCGPHIK classifierVarExact ( &confExact );
   
   NICE::Matrix mX;
   NICE::Vector vY;
@@ -529,7 +529,7 @@ void TestGPHIKClassifier::testGPHIKVariance()
   
   
   if (verboseStartEnd)
-    std::cerr << "================== TestGPHIKClassifier::testGPHIKVariance done ===================== " << std::endl;
+    std::cerr << "================== TestFPCGPHIK::testGPHIKVariance done ===================== " << std::endl;
   
 }
 

+ 7 - 7
classifier/fpclassifier/tests/TestGPHIKClassifier.h → classifier/fpclassifier/tests/TestFPCGPHIK.h

@@ -1,16 +1,16 @@
-#ifndef _TESTGPHIKCLASSIFIER_H
-#define _TESTGPHIKCLASSIFIER_H
+#ifndef _TESTFPCGPHIK_H
+#define _TESTFPCGPHIK_H
 
 #include <cppunit/extensions/HelperMacros.h>
 
 /**
  * CppUnit-Testcase. 
  */
-class TestGPHIKClassifier : public CppUnit::TestFixture {
+class TestFPCGPHIK : public CppUnit::TestFixture {
 
-    CPPUNIT_TEST_SUITE( TestGPHIKClassifier );
+    CPPUNIT_TEST_SUITE( TestFPCGPHIK );
     
-    CPPUNIT_TEST(testGPHIKClassifier);
+    CPPUNIT_TEST(testFPCGPHIK);
     CPPUNIT_TEST(testGPHIKVariance);
 //     CPPUNIT_TEST(testGPHIKIncrementalLearning);
     
@@ -22,10 +22,10 @@ class TestGPHIKClassifier : public CppUnit::TestFixture {
     void setUp();
     void tearDown();
 
-    void testGPHIKClassifier();
+    void testFPCGPHIK();
     void testGPHIKVariance();
 //     void testGPHIKIncrementalLearning();
 
 };
 
-#endif // _TESTFASTHIK_H
+#endif // _TESTFPCGPHIK_H

+ 5 - 4
classifier/genericClassifierSelection.h

@@ -40,6 +40,7 @@
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/classifier/fpclassifier/randomforest/FPCDecisionTree.h"
 #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
+#include "vislearning/classifier/fpclassifier/FPCGPHIK.h"
 
 //vislearning -- classifier combinations
 #include "vislearning/classifier/classifiercombination/VCPreRandomForest.h"
@@ -92,10 +93,10 @@ class GenericClassifierSelection
       //    all Feature Pool Classifiers    //
       //                                    //
       ////////////////////////////////////////
-//       else if ( classifier_type == "GPHIK" ) {
-//         FeaturePoolClassifier *fpc = new GPHIKClassifierNICE ( conf, "GPHIK" );
-//         classifier = new VCFeaturePool ( conf, fpc );
-//       }      
+      else if ( classifier_type == "GPHIK" ) {
+        FeaturePoolClassifier *fpc = new FPCGPHIK ( conf, "GPHIK" );
+        classifier = new VCFeaturePool ( conf, fpc );
+      }      
       else if ( classifier_type == "random_forest" ) {
         FeaturePoolClassifier *fpc = new FPCRandomForests ( conf, "RandomForest" );
         classifier = new VCFeaturePool ( conf, fpc );