Browse Source

fixed minor bug for IL in regression setting

Alexander Freytag 11 years ago
parent
commit
8142c3e762

+ 16 - 11
FMKGPHyperparameterOptimization.cpp

@@ -55,7 +55,15 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
   std::map<int, NICE::Vector> binaryLabels;
   std::set<int> classesToUse;
   //TODO this could be made faster when storing the previous binary label vectors...
-  this->prepareBinaryLabels ( binaryLabels, this->labels , classesToUse );
+  
+  if ( this->b_performRegression )
+  {
+    // for regression, we are not interested in regression scores, rather than in any "label" 
+    int regressionLabel ( 1 );  
+    binaryLabels.insert ( std::pair< int, NICE::Vector> ( regressionLabel, this->labels ) );
+  }
+  else
+    this->prepareBinaryLabels ( binaryLabels, this->labels , classesToUse );
   
   if ( this->verbose )
     std::cerr << "labels.size() after increment: " << this->labels.size() << std::endl;
@@ -71,7 +79,6 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
   if ( this->verboseTime )
     std::cerr << "Time used for setting up the gplike-objects: " << t1.getLast() << std::endl;
 
-
   t1.start();
   if ( this->b_usePreviousAlphas && ( this->previousAlphas.size() > 0) )
   {
@@ -116,7 +123,7 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
     //if we do not use previous alphas, we do not have to set up anything here
     gplike->setInitialAlphaGuess ( NULL );
   }
-  
+    
   t1.stop();
   if ( this->verboseTime )
     std::cerr << "Time used for setting up the alpha-objects: " << t1.getLast() << std::endl;
@@ -136,8 +143,7 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
   //////////////////////  //////////////////////
   //   RE-RUN THE OPTIMIZATION, IF DESIRED    //
   //////////////////////  //////////////////////    
-  
-  
+    
   if ( this->verbose )
     std::cerr << "resulting eigenvalues for first class: " << eigenMax[0] << std::endl;
   
@@ -154,7 +160,7 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
     
   if ( this->verbose )
     std::cerr << "perform optimization after increment " << std::endl;
-  
+   
   int optimizationMethodTmpCopy;
   if ( !performOptimizationAfterIncrement )
   {
@@ -163,7 +169,7 @@ void FMKGPHyperparameterOptimization::updateAfterIncrement (
     optimizationMethodTmpCopy = this->optimizationMethod;
     this->optimizationMethod = OPT_NONE;
   }
-      
+  
   t1.start();
   this->performOptimization ( *gplike, parameterVectorSize);
 
@@ -721,7 +727,8 @@ void FMKGPHyperparameterOptimization::optimize ( const NICE::Vector & y )
   
   if ( this->b_performRegression )
   {
-    int regressionLabel ( 1 );    
+    // for regression, we are not interested in regression scores, rather than in any "label" 
+    int regressionLabel ( 1 );  
     binaryLabels.insert ( std::pair< int, NICE::Vector> ( regressionLabel, y ) );
     this->knownClasses.clear();
     this->knownClasses.insert ( regressionLabel );
@@ -878,7 +885,7 @@ int FMKGPHyperparameterOptimization::classify ( const NICE::SparseVector & xstar
     double beta;
 
     if ( q != NULL ) {
-      map<int, double *>::const_iterator j = precomputedT.find ( classno );
+      std::map<int, double *>::const_iterator j = precomputedT.find ( classno );
       double *T = j->second;
       fmk->hik_kernel_sum_fast ( T, *q, xstar, beta );
     } else {
@@ -1847,12 +1854,10 @@ void FMKGPHyperparameterOptimization::addExample( const NICE::SparseVector * exa
   if ( this->verboseTime)
     std::cerr << "Time used for adding the data to the fmk object: " << tFmk.getLast() << std::endl;
 
-  //TODO check that nothing serious happens here for regression setting!
   
   // add examples to all implicite kernel matrices we currently use
   this->ikmsum->addExample ( example, label, performOptimizationAfterIncrement );
   
-  //TODO check that nothing serious happens here for regression setting!
   
   // update the corresponding matrices A, B and lookup tables T  
   // optional: do the optimization again using the previously known solutions as initialization

+ 3 - 6
GPHIKRegression.cpp

@@ -254,11 +254,6 @@ void GPHIKRegression::train ( const std::vector< const NICE::SparseVector *> & e
     std::cerr << "GPHIKRegression::train" << std::endl;
   }
   
-  //TODO add flag fpr gphyper that only regression is performed, or add a new method for this.
-  // thereby, all the binary-label-stuff should be skipped :)
-  // also think about the internal stuff, like initialization of alpha vectors and stuff like that .... :(
-  // in the worst case, stuff has to be re-written...
-  
   if ( this->confCopy == NULL )
   {
     std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
@@ -280,7 +275,9 @@ void GPHIKRegression::train ( const std::vector< const NICE::SparseVector *> & e
   
   if ( ( varianceApproximation != APPROXIMATE_FINE) )
     confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 0);
-  
+
+  // add flag for gphyper that only regression is performed
+  // thereby, all the binary-label-stuff should be skipped :)  
   confCopy->sB ( confSection, "b_performRegression", true );
   gphyper = new FMKGPHyperparameterOptimization ( confCopy, pf, fmk, confSection ); 
 

+ 2 - 2
matlab/plot1dExampleRegression.m

@@ -1,7 +1,7 @@
-myData = [ 0.2; 0.8];
+myData = [ 0.1; 0.3; 0.8];
 % create l1-normalized 'histograms'
 myData = cat(2,myData , 1-myData)';
-myValues = [1,2];
+myValues = [0.3, 0.0, 1.4];
 
 
 % init new GPHIKRegression object

+ 11 - 13
tests/TestGPHIKRegression.cpp

@@ -24,7 +24,7 @@ using namespace std; //C basics
 using namespace NICE;  // nice-core
 
 const bool verboseStartEnd = true;
-const bool verbose = true;
+const bool verbose = false;
 
 
 CPPUNIT_TEST_SUITE_REGISTRATION( TestGPHIKRegression );
@@ -158,8 +158,8 @@ void TestGPHIKRegression::testRegressionHoldOutData()
   
   conf.sB ( "GPHIKRegression", "eig_verbose", false);
   conf.sS ( "GPHIKRegression", "optimization_method", "downhillsimplex");
-  // set pretty low built-in noise for hold-in regression estimation
-  conf.sD ( "GPHIKRegression", "noise", 1e-6 );
+  // set higher built-in noise for hold-out regression estimation
+  conf.sD ( "GPHIKRegression", "noise", 1e-4 );
   
   std::string s_trainData = conf.gS( "main", "trainData", "toyExampleSmallScaleTrain.data" );
   
@@ -182,7 +182,7 @@ void TestGPHIKRegression::testRegressionHoldOutData()
     
   //create regressionMethod object
   NICE::GPHIKRegression * regressionMethod;
-  regressionMethod = new NICE::GPHIKRegression ( &conf );
+  regressionMethod = new NICE::GPHIKRegression ( &conf, "GPHIKRegression" );
   regressionMethod->train ( examplesTrain , yValues );
   
   //------------- read the test data --------------
@@ -204,7 +204,7 @@ void TestGPHIKRegression::testRegressionHoldOutData()
   evaluateRegressionMethod ( holdOutLoss, regressionMethod, dataTest, yValuesTest ); 
 
   // acceptable difference for every estimated y-value on average
-  double diffOkay ( 0.35 );
+  double diffOkay ( 0.4 );
   
   if ( verbose ) 
   {
@@ -235,6 +235,8 @@ void TestGPHIKRegression::testRegressionOnlineLearning()
   
   conf.sB ( "GPHIKRegressionMethod", "eig_verbose", false);
   conf.sS ( "GPHIKRegressionMethod", "optimization_method", "downhillsimplex");//downhillsimplex greedy
+  // set higher built-in noise for hold-out regression estimation
+  conf.sD ( "GPHIKRegression", "noise", 1e-4 );  
   
   std::string s_trainData = conf.gS( "main", "trainData", "toyExampleSmallScaleTrain.data" );
   
@@ -257,14 +259,13 @@ void TestGPHIKRegression::testRegressionOnlineLearning()
   
   // TRAIN INITIAL CLASSIFIER FROM SCRATCH
   NICE::GPHIKRegression * regressionMethod;
-  regressionMethod = new NICE::GPHIKRegression ( &conf );
+  regressionMethod = new NICE::GPHIKRegression ( &conf, "GPHIKRegression" );
 
   //use all but the first example for training and add the first one lateron
   NICE::Vector yValuesRelevantTrain  ( yValuesTrain.getRangeRef( 0, yValuesTrain.size()-2  ) );
   
   regressionMethod->train ( examplesTrain , yValuesRelevantTrain );
   
-  std::cerr << " initial training done " << std::endl;
   
   // RUN INCREMENTAL LEARNING
   
@@ -272,19 +273,16 @@ void TestGPHIKRegression::testRegressionOnlineLearning()
   
   NICE::SparseVector * exampleToAdd = new NICE::SparseVector ( dataTrain.getRow( (int)dataTrain.rows()-1 ) );
   
-  exampleToAdd->store  ( std::cerr );
-  std::cerr << "corresponding label: " << yValuesTrain[ (int)dataTrain.rows()-2 ] << std::endl;
   
-  // TODO seg fault happens here!
   regressionMethod->addExample ( exampleToAdd, yValuesTrain[ (int)dataTrain.rows()-2 ], performOptimizationAfterIncrement );
   
   if ( verbose )
     std::cerr << "label of example to add: " << yValuesTrain[ (int)dataTrain.rows()-1 ] << std::endl;
   
-  // TRAIN SECOND CLASSIFIER FROM SCRATCH USING THE SAME OVERALL AMOUNT OF EXAMPLES
+  // TRAIN SECOND REGRESSOR FROM SCRATCH USING THE SAME OVERALL AMOUNT OF EXAMPLES
   examplesTrain.push_back(  exampleToAdd );
 
-  NICE::GPHIKRegression * regressionMethodScratch = new NICE::GPHIKRegression ( &conf );
+  NICE::GPHIKRegression * regressionMethodScratch = new NICE::GPHIKRegression ( &conf, "GPHIKRegression" );
   regressionMethodScratch->train ( examplesTrain, yValuesTrain );
   
   if ( verbose )
@@ -347,7 +345,7 @@ void TestGPHIKRegression::testRegressionOnlineLearning()
   }
   
   
-  CPPUNIT_ASSERT_DOUBLES_EQUAL( holdOutLossIL, holdOutLossScratch, 1e-8);
+  CPPUNIT_ASSERT_DOUBLES_EQUAL( holdOutLossIL, holdOutLossScratch, 1e-4);
   
   // don't waste memory