|
@@ -27,123 +27,116 @@ using namespace NICE;
|
|
|
|
|
|
|
|
|
|
|
|
-void GPHIKRegression::init(const Config *conf, const string & s_confSection)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+GPHIKRegression::GPHIKRegression( )
|
|
|
{
|
|
|
-
|
|
|
- if ( this->confCopy != conf )
|
|
|
- {
|
|
|
- if ( this->confCopy != NULL )
|
|
|
- delete this->confCopy;
|
|
|
-
|
|
|
- this->confCopy = new Config ( *conf );
|
|
|
-
|
|
|
- this->confCopy->setIoUntilEndOfFile(false);
|
|
|
- }
|
|
|
+ this->b_isTrained = false;
|
|
|
+ this->confSection = "";
|
|
|
|
|
|
-
|
|
|
+ this->gphyper = new NICE::FMKGPHyperparameterOptimization();
|
|
|
|
|
|
- double parameterUpperBound = confCopy->gD(confSection, "parameter_upper_bound", 5.0 );
|
|
|
- double parameterLowerBound = confCopy->gD(confSection, "parameter_lower_bound", 1.0 );
|
|
|
-
|
|
|
- this->noise = confCopy->gD(confSection, "noise", 0.01);
|
|
|
+
|
|
|
+
|
|
|
+ NICE::Config tmpConfEmpty ;
|
|
|
+ this->initFromConfig ( &tmpConfEmpty, this->confSection );
|
|
|
+
|
|
|
+
|
|
|
+ this->gphyper->setPerformRegression ( true );
|
|
|
+}
|
|
|
|
|
|
- string transform = confCopy->gS(confSection, "transform", "absexp" );
|
|
|
+GPHIKRegression::GPHIKRegression( const Config *conf, const string & s_confSection )
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this->b_isTrained = false;
|
|
|
+ this->confSection = "";
|
|
|
+
|
|
|
+ this->gphyper = new NICE::FMKGPHyperparameterOptimization();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- if (pf == NULL)
|
|
|
+ this->confSection = s_confSection;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if ( conf != NULL )
|
|
|
{
|
|
|
- if ( transform == "absexp" )
|
|
|
- {
|
|
|
- this->pf = new PFAbsExp( 1.0, parameterLowerBound, parameterUpperBound );
|
|
|
- } else if ( transform == "exp" ) {
|
|
|
- this->pf = new PFExp( 1.0, parameterLowerBound, parameterUpperBound );
|
|
|
- }else if ( transform == "MKL" ) {
|
|
|
-
|
|
|
- std::set<int> steps; steps.insert(4000); steps.insert(6000);
|
|
|
- this->pf = new PFMKL( steps, parameterLowerBound, parameterUpperBound );
|
|
|
- } else {
|
|
|
- fthrow(Exception, "Transformation type is unknown " << transform);
|
|
|
- }
|
|
|
+ this->initFromConfig( conf, confSection );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
+ NICE::Config tmpConfEmpty ;
|
|
|
+ this->initFromConfig ( &tmpConfEmpty, this->confSection );
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ this->gphyper->setPerformRegression ( true );
|
|
|
+}
|
|
|
+
|
|
|
+GPHIKRegression::~GPHIKRegression()
|
|
|
+{
|
|
|
+ if ( gphyper != NULL )
|
|
|
+ delete gphyper;
|
|
|
+}
|
|
|
+
|
|
|
+void GPHIKRegression::initFromConfig(const Config *conf, const string & s_confSection)
|
|
|
+{
|
|
|
+
|
|
|
+ this->noise = conf->gD(confSection, "noise", 0.01);
|
|
|
+
|
|
|
this->confSection = confSection;
|
|
|
- this->verbose = confCopy->gB(confSection, "verbose", false);
|
|
|
- this->debug = confCopy->gB(confSection, "debug", false);
|
|
|
- this->uncertaintyPredictionForRegression = confCopy->gB( confSection, "uncertaintyPredictionForRegression", false );
|
|
|
+ this->verbose = conf->gB(confSection, "verbose", false);
|
|
|
+ this->debug = conf->gB(confSection, "debug", false);
|
|
|
+ this->uncertaintyPredictionForRegression = conf->gB( confSection, "uncertaintyPredictionForRegression", false );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- string s_varianceApproximation = confCopy->gS(confSection, "varianceApproximation", "approximate_fine");
|
|
|
+ string s_varianceApproximation = conf->gS(confSection, "varianceApproximation", "approximate_fine");
|
|
|
if ( (s_varianceApproximation.compare("approximate_rough") == 0) || ((s_varianceApproximation.compare("1") == 0)) )
|
|
|
{
|
|
|
this->varianceApproximation = APPROXIMATE_ROUGH;
|
|
|
|
|
|
|
|
|
- this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 0 );
|
|
|
+ this->gphyper->setNrOfEigenvaluesToConsiderForVarApprox ( 0 );
|
|
|
}
|
|
|
else if ( (s_varianceApproximation.compare("approximate_fine") == 0) || ((s_varianceApproximation.compare("2") == 0)) )
|
|
|
{
|
|
|
this->varianceApproximation = APPROXIMATE_FINE;
|
|
|
|
|
|
|
|
|
- this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", std::max( confCopy->gI(confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 ), 1) );
|
|
|
+ this->gphyper->setNrOfEigenvaluesToConsiderForVarApprox ( std::max( conf->gI(confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 ), 1) );
|
|
|
}
|
|
|
else if ( (s_varianceApproximation.compare("exact") == 0) || ((s_varianceApproximation.compare("3") == 0)) )
|
|
|
{
|
|
|
this->varianceApproximation = EXACT;
|
|
|
|
|
|
|
|
|
- this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 );
|
|
|
+ this->gphyper->setNrOfEigenvaluesToConsiderForVarApprox ( 0 );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this->varianceApproximation = NONE;
|
|
|
|
|
|
|
|
|
- this->confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 1 );
|
|
|
+ this->gphyper->setNrOfEigenvaluesToConsiderForVarApprox ( 0 );
|
|
|
}
|
|
|
|
|
|
if ( this->verbose )
|
|
|
std::cerr << "varianceApproximationStrategy: " << s_varianceApproximation << std::endl;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-GPHIKRegression::GPHIKRegression( const Config *conf, const string & s_confSection )
|
|
|
-{
|
|
|
-
|
|
|
- gphyper = NULL;
|
|
|
- pf = NULL;
|
|
|
- confCopy = NULL;
|
|
|
-
|
|
|
- uncertaintyPredictionForRegression = false;
|
|
|
-
|
|
|
- this->confSection = s_confSection;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if ( conf != NULL )
|
|
|
- {
|
|
|
- this->init(conf, confSection);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-GPHIKRegression::~GPHIKRegression()
|
|
|
-{
|
|
|
- if ( gphyper != NULL )
|
|
|
- delete gphyper;
|
|
|
|
|
|
- if (pf != NULL)
|
|
|
- delete pf;
|
|
|
-
|
|
|
- if ( confCopy != NULL )
|
|
|
- delete confCopy;
|
|
|
+
|
|
|
+ this->gphyper->initFromConfig ( conf, confSection );
|
|
|
}
|
|
|
|
|
|
|
|
@@ -170,7 +163,7 @@ void GPHIKRegression::estimate ( const NICE::Vector * example, double & result
|
|
|
|
|
|
void GPHIKRegression::estimate ( const SparseVector * example, double & result, double & uncertainty ) const
|
|
|
{
|
|
|
- if (gphyper == NULL)
|
|
|
+ if ( ! this->b_isTrained )
|
|
|
fthrow(Exception, "Regression object not trained yet -- aborting!" );
|
|
|
|
|
|
NICE::SparseVector scores;
|
|
@@ -206,7 +199,7 @@ void GPHIKRegression::estimate ( const SparseVector * example, double & result,
|
|
|
|
|
|
void GPHIKRegression::estimate ( const NICE::Vector * example, double & result, double & uncertainty ) const
|
|
|
{
|
|
|
- if (gphyper == NULL)
|
|
|
+ if ( ! this->b_isTrained )
|
|
|
fthrow(Exception, "Regression object not trained yet -- aborting!" );
|
|
|
|
|
|
NICE::SparseVector scores;
|
|
@@ -253,34 +246,17 @@ void GPHIKRegression::train ( const std::vector< const NICE::SparseVector *> & e
|
|
|
{
|
|
|
std::cerr << "GPHIKRegression::train" << std::endl;
|
|
|
}
|
|
|
-
|
|
|
- if ( this->confCopy == NULL )
|
|
|
- {
|
|
|
- std::cerr << "WARNING -- No config used so far, initialize values with empty config file now..." << std::endl;
|
|
|
- NICE::Config tmpConfEmpty ;
|
|
|
- this->init ( &tmpConfEmpty, this->confSection );
|
|
|
- }
|
|
|
|
|
|
Timer t;
|
|
|
t.start();
|
|
|
+
|
|
|
FastMinKernel *fmk = new FastMinKernel ( examples, noise, this->debug );
|
|
|
+ gphyper->setFastMinKernel ( fmk );
|
|
|
|
|
|
t.stop();
|
|
|
if (verbose)
|
|
|
std::cerr << "Time used for setting up the fmk object: " << t.getLast() << std::endl;
|
|
|
|
|
|
- if (gphyper != NULL)
|
|
|
- delete gphyper;
|
|
|
-
|
|
|
-
|
|
|
- if ( ( varianceApproximation != APPROXIMATE_FINE) )
|
|
|
- confCopy->sI ( confSection, "nrOfEigenvaluesToConsiderForVarApprox", 0);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- confCopy->sB ( confSection, "b_performRegression", true );
|
|
|
- gphyper = new FMKGPHyperparameterOptimization ( confCopy, pf, fmk, confSection );
|
|
|
-
|
|
|
if (verbose)
|
|
|
cerr << "Learning ..." << endl;
|
|
|
|
|
@@ -315,7 +291,9 @@ void GPHIKRegression::train ( const std::vector< const NICE::SparseVector *> & e
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ this->b_isTrained = true;
|
|
|
+
|
|
|
|
|
|
if (verbose)
|
|
|
std::cerr << "Learning finished" << std::endl;
|
|
@@ -331,7 +309,7 @@ GPHIKRegression *GPHIKRegression::clone () const
|
|
|
|
|
|
void GPHIKRegression::predictUncertainty( const NICE::SparseVector * example, double & uncertainty ) const
|
|
|
{
|
|
|
- if (gphyper == NULL)
|
|
|
+ if ( ! this->b_isTrained )
|
|
|
fthrow(Exception, "Regression object not trained yet -- aborting!" );
|
|
|
|
|
|
switch (varianceApproximation)
|
|
@@ -360,7 +338,7 @@ void GPHIKRegression::predictUncertainty( const NICE::SparseVector * example, do
|
|
|
|
|
|
void GPHIKRegression::predictUncertainty( const NICE::Vector * example, double & uncertainty ) const
|
|
|
{
|
|
|
- if (gphyper == NULL)
|
|
|
+ if ( ! this->b_isTrained )
|
|
|
fthrow(Exception, "Regression object not trained yet -- aborting!" );
|
|
|
|
|
|
switch (varianceApproximation)
|
|
@@ -415,16 +393,6 @@ void GPHIKRegression::restore ( std::istream & is, int format )
|
|
|
throw;
|
|
|
}
|
|
|
|
|
|
- if (pf != NULL)
|
|
|
- {
|
|
|
- delete pf;
|
|
|
- pf = NULL;
|
|
|
- }
|
|
|
- if ( confCopy != NULL )
|
|
|
- {
|
|
|
- delete confCopy;
|
|
|
- confCopy = NULL;
|
|
|
- }
|
|
|
if (gphyper != NULL)
|
|
|
{
|
|
|
delete gphyper;
|
|
@@ -456,49 +424,6 @@ void GPHIKRegression::restore ( std::istream & is, int format )
|
|
|
is >> tmp;
|
|
|
tmp = this->removeEndTag ( tmp );
|
|
|
}
|
|
|
- else if ( tmp.compare("pf") == 0 )
|
|
|
- {
|
|
|
-
|
|
|
- is >> tmp;
|
|
|
- if ( this->isEndTag( tmp, "pf" ) )
|
|
|
- {
|
|
|
- std::cerr << " ParameterizedFunction object can not be restored. Aborting..." << std::endl;
|
|
|
- throw;
|
|
|
- }
|
|
|
-
|
|
|
- std::string transform = this->removeStartTag ( tmp );
|
|
|
-
|
|
|
-
|
|
|
- if ( transform == "PFAbsExp" )
|
|
|
- {
|
|
|
- this->pf = new PFAbsExp ();
|
|
|
- } else if ( transform == "PFExp" ) {
|
|
|
- this->pf = new PFExp ();
|
|
|
- } else {
|
|
|
- fthrow(Exception, "Transformation type is unknown " << transform);
|
|
|
- }
|
|
|
-
|
|
|
- pf->restore(is, format);
|
|
|
-
|
|
|
- is >> tmp;
|
|
|
- tmp = this->removeEndTag ( tmp );
|
|
|
- }
|
|
|
- else if ( tmp.compare("ConfigCopy") == 0 )
|
|
|
- {
|
|
|
-
|
|
|
- if ( confCopy == NULL )
|
|
|
- confCopy = new Config;
|
|
|
- confCopy->clear();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- confCopy->setIoUntilEndOfFile( false );
|
|
|
-
|
|
|
- confCopy->restore(is, format);
|
|
|
-
|
|
|
- is >> tmp;
|
|
|
- tmp = this->removeEndTag ( tmp );
|
|
|
- }
|
|
|
else if ( tmp.compare("gphyper") == 0 )
|
|
|
{
|
|
|
if ( gphyper == NULL )
|
|
@@ -510,20 +435,51 @@ void GPHIKRegression::restore ( std::istream & is, int format )
|
|
|
|
|
|
is >> tmp;
|
|
|
tmp = this->removeEndTag ( tmp );
|
|
|
- }
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("b_isTrained") == 0 )
|
|
|
+ {
|
|
|
+ is >> b_isTrained;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("noise") == 0 )
|
|
|
+ {
|
|
|
+ is >> noise;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("verbose") == 0 )
|
|
|
+ {
|
|
|
+ is >> verbose;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("debug") == 0 )
|
|
|
+ {
|
|
|
+ is >> debug;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("uncertaintyPredictionForRegression") == 0 )
|
|
|
+ {
|
|
|
+ is >> uncertaintyPredictionForRegression;
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
+ else if ( tmp.compare("varianceApproximation") == 0 )
|
|
|
+ {
|
|
|
+ unsigned int ui_varianceApproximation;
|
|
|
+ is >> ui_varianceApproximation;
|
|
|
+ varianceApproximation = static_cast<VarianceApproximation> ( ui_varianceApproximation );
|
|
|
+ is >> tmp;
|
|
|
+ tmp = this->removeEndTag ( tmp );
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
std::cerr << "WARNING -- unexpected GPHIKRegression object -- " << tmp << " -- for restoration... aborting" << std::endl;
|
|
|
throw;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- std::cerr << "run this->init" << std::endl;
|
|
|
- this->init(confCopy, confSection);
|
|
|
- std::cerr << "run gphyper->initialize" << std::endl;
|
|
|
-
|
|
|
- gphyper->initFromConfig ( confCopy, confSection );
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -548,16 +504,6 @@ void GPHIKRegression::store ( std::ostream & os, int format ) const
|
|
|
os << confSection << std::endl;
|
|
|
os << this->createEndTag( "confSection" ) << std::endl;
|
|
|
|
|
|
- os << this->createStartTag( "pf" ) << std::endl;
|
|
|
- pf->store(os, format);
|
|
|
- os << this->createEndTag( "pf" ) << std::endl;
|
|
|
-
|
|
|
- os << this->createStartTag( "ConfigCopy" ) << std::endl;
|
|
|
-
|
|
|
- confCopy->setIoUntilEndOfFile(false);
|
|
|
- confCopy->store(os,format);
|
|
|
- os << this->createEndTag( "ConfigCopy" ) << std::endl;
|
|
|
-
|
|
|
os << this->createStartTag( "gphyper" ) << std::endl;
|
|
|
|
|
|
|
|
@@ -565,6 +511,32 @@ void GPHIKRegression::store ( std::ostream & os, int format ) const
|
|
|
gphyper->store(os, format);
|
|
|
os << this->createEndTag( "gphyper" ) << std::endl;
|
|
|
|
|
|
+ os << this->createStartTag( "b_isTrained" ) << std::endl;
|
|
|
+ os << b_isTrained << std::endl;
|
|
|
+ os << this->createEndTag( "b_isTrained" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "noise" ) << std::endl;
|
|
|
+ os << noise << std::endl;
|
|
|
+ os << this->createEndTag( "noise" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ os << this->createStartTag( "verbose" ) << std::endl;
|
|
|
+ os << verbose << std::endl;
|
|
|
+ os << this->createEndTag( "verbose" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "debug" ) << std::endl;
|
|
|
+ os << debug << std::endl;
|
|
|
+ os << this->createEndTag( "debug" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "uncertaintyPredictionForRegression" ) << std::endl;
|
|
|
+ os << uncertaintyPredictionForRegression << std::endl;
|
|
|
+ os << this->createEndTag( "uncertaintyPredictionForRegression" ) << std::endl;
|
|
|
+
|
|
|
+ os << this->createStartTag( "varianceApproximation" ) << std::endl;
|
|
|
+ os << varianceApproximation << std::endl;
|
|
|
+ os << this->createEndTag( "varianceApproximation" ) << std::endl;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
os << this->createEndTag( "GPHIKRegression" ) << std::endl;
|
|
@@ -582,18 +554,6 @@ void GPHIKRegression::clear ()
|
|
|
delete gphyper;
|
|
|
gphyper = NULL;
|
|
|
}
|
|
|
-
|
|
|
- if (pf != NULL)
|
|
|
- {
|
|
|
- delete pf;
|
|
|
- pf = NULL;
|
|
|
- }
|
|
|
-
|
|
|
- if ( confCopy != NULL )
|
|
|
- {
|
|
|
- delete confCopy;
|
|
|
- confCopy = NULL;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -606,7 +566,7 @@ void GPHIKRegression::addExample( const NICE::SparseVector * example,
|
|
|
)
|
|
|
{
|
|
|
|
|
|
- if ( this->gphyper == NULL )
|
|
|
+ if ( ! this->b_isTrained )
|
|
|
{
|
|
|
|
|
|
std::cerr << "Regression object not initially trained yet -- run initial training instead of incremental extension!" << std::endl;
|