瀏覽代碼

iterative solver with options in the raw version

Erik Rodner 9 年之前
父節點
當前提交
cf37cf10ba
共有 3 個文件被更改,包括 15 次插入6 次删除
  1. 10 4
      GPHIKRawClassifier.cpp
  2. 3 0
      GPHIKRawClassifier.h
  3. 2 2
      tests/TestFastHIK.cpp

+ 10 - 4
GPHIKRawClassifier.cpp

@@ -80,6 +80,7 @@ GPHIKRawClassifier::GPHIKRawClassifier( const Config *_conf,
 
 GPHIKRawClassifier::~GPHIKRawClassifier()
 {
+  delete solver;
 }
 
 void GPHIKRawClassifier::initFromConfig(const Config *_conf,
@@ -91,6 +92,13 @@ void GPHIKRawClassifier::initFromConfig(const Config *_conf,
   this->confSection = _confSection;
   this->b_verbose   = _conf->gB( _confSection, "verbose", false);
   this->b_debug     = _conf->gB( _confSection, "debug", false);
+
+  string ilssection = "FMKGPHyperparameterOptimization";
+  uint ils_max_iterations = _conf->gI( ilssection, "ils_max_iterations", 1000 );
+  double ils_min_delta = _conf->gD( ilssection, "ils_min_delta", 1e-7 );
+  double ils_min_residual = _conf->gD( ilssection, "ils_min_residual", 1e-7 );
+  bool ils_verbose = _conf->gB( ilssection, "ils_verbose", false );
+  this->solver = new ILSConjugateGradients( ils_verbose, ils_max_iterations, ils_min_delta, ils_min_residual );
 }
 
 ///////////////////// ///////////////////// /////////////////////
@@ -204,8 +212,7 @@ void GPHIKRawClassifier::train ( const std::vector< const NICE::SparseVector *>
 
   // sort examples in each dimension and "transpose" the feature matrix
   // set up the GenericMatrix interface
-  GMHIKernelRaw gm ( _examples );
-  IterativeLinearSolver *ils = new ILSConjugateGradients();
+  GMHIKernelRaw gm ( _examples, this->d_noise );
 
   // solve linear equations for each class
   for ( map<uint, NICE::Vector>::const_iterator i = _binLabels.begin();
@@ -213,11 +220,10 @@ void GPHIKRawClassifier::train ( const std::vector< const NICE::SparseVector *>
   {
     const Vector & y = i->second;
     Vector alpha;
-    ils->solveLin( gm, y, alpha );
+    solver->solveLin( gm, y, alpha );
     // TODO: get lookup tables, A, B, etc. and store them
   }
 
-  delete ils;
 
   t.stop();
   if ( this->b_verbose )

+ 3 - 0
GPHIKRawClassifier.h

@@ -15,6 +15,7 @@
 #include <core/basics/Config.h>
 #include <core/basics/Persistent.h>
 #include <core/vector/SparseVectorT.h>
+#include <core/algebra/IterativeLinearSolver.h>
 //
 
 namespace NICE {
@@ -62,6 +63,8 @@ class GPHIKRawClassifier //: public NICE::Persistent
     /** Gaussian label noise for model regularization */
     double d_noise;
 
+    IterativeLinearSolver *solver;
+
     /////////////////////////
     /////////////////////////
     //  PROTECTED METHODS  //

+ 2 - 2
tests/TestFastHIK.cpp

@@ -24,8 +24,8 @@ const bool b_debug = true;
 const bool verbose = true;
 const bool verboseStartEnd = true;
 const bool solveLinWithoutRand = false;
-const uint n = 5000;//1500;//1500;//10;
-const uint d = 1000;//200;//2;
+const uint n = 15000;//1500;//1500;//10;
+const uint d = 200;//200;//2;
 const uint numBins = 11;//1001;//1001;
 const uint solveLinMaxIterations = 1000;
 const double sparse_prob = 0.6;