|
@@ -255,8 +255,8 @@ FMKGPHyperparameterOptimization::FMKGPHyperparameterOptimization( )
|
|
this->b_debug = false;
|
|
this->b_debug = false;
|
|
|
|
|
|
//stupid unneeded default values
|
|
//stupid unneeded default values
|
|
- this->i_binaryLabelPositive = -1;
|
|
|
|
- this->i_binaryLabelNegative = -2;
|
|
|
|
|
|
+ this->i_binaryLabelPositive = 0;
|
|
|
|
+ this->i_binaryLabelNegative = 1;
|
|
this->knownClasses.clear();
|
|
this->knownClasses.clear();
|
|
|
|
|
|
this->b_usePreviousAlphas = false;
|
|
this->b_usePreviousAlphas = false;
|
|
@@ -284,8 +284,8 @@ FMKGPHyperparameterOptimization::FMKGPHyperparameterOptimization( const bool & _
|
|
this->b_debug = false;
|
|
this->b_debug = false;
|
|
|
|
|
|
//stupid unneeded default values
|
|
//stupid unneeded default values
|
|
- this->i_binaryLabelPositive = -1;
|
|
|
|
- this->i_binaryLabelNegative = -2;
|
|
|
|
|
|
+ this->i_binaryLabelPositive = 0;
|
|
|
|
+ this->i_binaryLabelNegative = 1;
|
|
this->knownClasses.clear();
|
|
this->knownClasses.clear();
|
|
|
|
|
|
this->b_usePreviousAlphas = false;
|
|
this->b_usePreviousAlphas = false;
|
|
@@ -320,8 +320,8 @@ FMKGPHyperparameterOptimization::FMKGPHyperparameterOptimization ( const Config
|
|
this->b_debug = false;
|
|
this->b_debug = false;
|
|
|
|
|
|
//stupid unneeded default values
|
|
//stupid unneeded default values
|
|
- this->i_binaryLabelPositive = -1;
|
|
|
|
- this->i_binaryLabelNegative = -2;
|
|
|
|
|
|
+ this->i_binaryLabelPositive = 0;
|
|
|
|
+ this->i_binaryLabelNegative = 1;
|
|
this->knownClasses.clear();
|
|
this->knownClasses.clear();
|
|
|
|
|
|
this->b_usePreviousAlphas = false;
|
|
this->b_usePreviousAlphas = false;
|
|
@@ -357,8 +357,8 @@ FMKGPHyperparameterOptimization::FMKGPHyperparameterOptimization ( const Config
|
|
this->b_debug = false;
|
|
this->b_debug = false;
|
|
|
|
|
|
//stupid unneeded default values
|
|
//stupid unneeded default values
|
|
- this->i_binaryLabelPositive = -1;
|
|
|
|
- this->i_binaryLabelNegative = -2;
|
|
|
|
|
|
+ this->i_binaryLabelPositive = 0;
|
|
|
|
+ this->i_binaryLabelNegative = 1;
|
|
this->knownClasses.clear();
|
|
this->knownClasses.clear();
|
|
|
|
|
|
this->b_usePreviousAlphas = false;
|
|
this->b_usePreviousAlphas = false;
|
|
@@ -453,27 +453,22 @@ void FMKGPHyperparameterOptimization::initFromConfig ( const Config *_conf,
|
|
|
|
|
|
|
|
|
|
std::string s_quantType = _conf->gS( _confSection, "s_quantType", "1d-aequi-0-1" );
|
|
std::string s_quantType = _conf->gS( _confSection, "s_quantType", "1d-aequi-0-1" );
|
|
|
|
+
|
|
if ( s_quantType == "1d-aequi-0-1" )
|
|
if ( s_quantType == "1d-aequi-0-1" )
|
|
{
|
|
{
|
|
this->q = new NICE::Quantization1DAequiDist0To1 ( numBins );
|
|
this->q = new NICE::Quantization1DAequiDist0To1 ( numBins );
|
|
}
|
|
}
|
|
else if ( s_quantType == "1d-aequi-0-max" )
|
|
else if ( s_quantType == "1d-aequi-0-max" )
|
|
- {
|
|
|
|
- // FIXME this explicite setting is just one option. alternatively, we could compute the largest value of all training data
|
|
|
|
- double vmax = _conf->gD( _confSection, "vmax-Quantization1DAequiDist0ToMax", 1.0 );
|
|
|
|
- NICE::Vector upperBound ( 1 );
|
|
|
|
- upperBound ( 0 ) = vmax;
|
|
|
|
-
|
|
|
|
- this->q = new NICE::Quantization1DAequiDist0ToMax ( numBins, &upperBound );
|
|
|
|
|
|
+ {
|
|
|
|
+ this->q = new NICE::Quantization1DAequiDist0ToMax ( numBins );
|
|
}
|
|
}
|
|
else if ( s_quantType == "nd-aequi-0-1" )
|
|
else if ( s_quantType == "nd-aequi-0-1" )
|
|
{
|
|
{
|
|
- // FIXME load the upper bounds from a separate file or compute them here...
|
|
|
|
this->q = new NICE::QuantizationNDAequiDist0ToMax ( numBins );
|
|
this->q = new NICE::QuantizationNDAequiDist0ToMax ( numBins );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- fthrow(Exception, "Quantization type is unknown " << transform);
|
|
|
|
|
|
+ fthrow(Exception, "Quantization type is unknown " << s_quantType);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -672,7 +667,10 @@ void FMKGPHyperparameterOptimization::setFastMinKernel ( FastMinKernel * _fmk )
|
|
this->fmk = NULL;
|
|
this->fmk = NULL;
|
|
}
|
|
}
|
|
this->fmk = _fmk;
|
|
this->fmk = _fmk;
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ this->q->computeParametersFromData ( this->fmk->featureMatrix() );
|
|
}
|
|
}
|
|
|
|
|
|
void FMKGPHyperparameterOptimization::setNrOfEigenvaluesToConsiderForVarApprox ( const int & _nrOfEigenvaluesToConsiderForVarApprox )
|
|
void FMKGPHyperparameterOptimization::setNrOfEigenvaluesToConsiderForVarApprox ( const int & _nrOfEigenvaluesToConsiderForVarApprox )
|
|
@@ -833,9 +831,9 @@ void FMKGPHyperparameterOptimization::computeMatricesAndLUTs ( const GPLikelihoo
|
|
this->precomputedA[ i->first ] = A;
|
|
this->precomputedA[ i->first ] = A;
|
|
this->precomputedB[ i->first ] = B;
|
|
this->precomputedB[ i->first ] = B;
|
|
|
|
|
|
- if ( q != NULL )
|
|
|
|
|
|
+ if ( this->q != NULL )
|
|
{
|
|
{
|
|
- double *T = fmk->hik_prepare_alpha_multiplications_fast ( A, B, *q, pf );
|
|
|
|
|
|
+ double *T = fmk->hik_prepare_alpha_multiplications_fast ( A, B, this->q, this->pf );
|
|
//just to be sure that we do not waste space here
|
|
//just to be sure that we do not waste space here
|
|
if ( precomputedT[ i->first ] != NULL )
|
|
if ( precomputedT[ i->first ] != NULL )
|
|
delete precomputedT[ i->first ];
|
|
delete precomputedT[ i->first ];
|
|
@@ -1122,9 +1120,9 @@ void FMKGPHyperparameterOptimization::prepareVarianceApproximationRough()
|
|
this->precomputedAForVarEst = AVar;
|
|
this->precomputedAForVarEst = AVar;
|
|
this->precomputedAForVarEst.setIoUntilEndOfFile ( false );
|
|
this->precomputedAForVarEst.setIoUntilEndOfFile ( false );
|
|
|
|
|
|
- if ( q != NULL )
|
|
|
|
|
|
+ if ( this->q != NULL )
|
|
{
|
|
{
|
|
- double *T = this->fmk->hikPrepareLookupTableForKVNApproximation ( *q, pf );
|
|
|
|
|
|
+ double *T = this->fmk->hikPrepareLookupTableForKVNApproximation ( this->q, this->pf );
|
|
this->precomputedTForVarEst = T;
|
|
this->precomputedTForVarEst = T;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1159,7 +1157,7 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::SparseVector & _xst
|
|
if ( this->q != NULL ) {
|
|
if ( this->q != NULL ) {
|
|
std::map<uint, double *>::const_iterator j = this->precomputedT.find ( classno );
|
|
std::map<uint, double *>::const_iterator j = this->precomputedT.find ( classno );
|
|
double *T = j->second;
|
|
double *T = j->second;
|
|
- this->fmk->hik_kernel_sum_fast ( T, *q, _xstar, beta );
|
|
|
|
|
|
+ this->fmk->hik_kernel_sum_fast ( T, this->q, _xstar, beta );
|
|
} else {
|
|
} else {
|
|
const PrecomputedType & A = i->second;
|
|
const PrecomputedType & A = i->second;
|
|
std::map<uint, PrecomputedType>::const_iterator j = this->precomputedB.find ( classno );
|
|
std::map<uint, PrecomputedType>::const_iterator j = this->precomputedB.find ( classno );
|
|
@@ -1220,7 +1218,7 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::Vector & _xstar,
|
|
{
|
|
{
|
|
std::map<uint, double *>::const_iterator j = this->precomputedT.find ( classno );
|
|
std::map<uint, double *>::const_iterator j = this->precomputedT.find ( classno );
|
|
double *T = j->second;
|
|
double *T = j->second;
|
|
- this->fmk->hik_kernel_sum_fast ( T, *q, _xstar, beta );
|
|
|
|
|
|
+ this->fmk->hik_kernel_sum_fast ( T, this->q, _xstar, beta );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1283,13 +1281,13 @@ void FMKGPHyperparameterOptimization::computePredictiveVarianceApproximateRough
|
|
// ---------------- compute the approximation of the second term --------------------
|
|
// ---------------- compute the approximation of the second term --------------------
|
|
double normKStar;
|
|
double normKStar;
|
|
|
|
|
|
- if ( q != NULL )
|
|
|
|
|
|
+ if ( this->q != NULL )
|
|
{
|
|
{
|
|
if ( precomputedTForVarEst == NULL )
|
|
if ( precomputedTForVarEst == NULL )
|
|
{
|
|
{
|
|
fthrow ( Exception, "The precomputed LUT for uncertainty prediction is NULL...have you prepared the uncertainty prediction? Aborting..." );
|
|
fthrow ( Exception, "The precomputed LUT for uncertainty prediction is NULL...have you prepared the uncertainty prediction? Aborting..." );
|
|
}
|
|
}
|
|
- fmk->hikComputeKVNApproximationFast ( precomputedTForVarEst, *q, _x, normKStar );
|
|
|
|
|
|
+ fmk->hikComputeKVNApproximationFast ( precomputedTForVarEst, this->q, _x, normKStar );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1498,13 +1496,13 @@ void FMKGPHyperparameterOptimization::computePredictiveVarianceApproximateRough
|
|
// ---------------- compute the approximation of the second term --------------------
|
|
// ---------------- compute the approximation of the second term --------------------
|
|
double normKStar;
|
|
double normKStar;
|
|
|
|
|
|
- if ( q != NULL )
|
|
|
|
|
|
+ if ( this->q != NULL )
|
|
{
|
|
{
|
|
if ( precomputedTForVarEst == NULL )
|
|
if ( precomputedTForVarEst == NULL )
|
|
{
|
|
{
|
|
fthrow ( Exception, "The precomputed LUT for uncertainty prediction is NULL...have you prepared the uncertainty prediction? Aborting..." );
|
|
fthrow ( Exception, "The precomputed LUT for uncertainty prediction is NULL...have you prepared the uncertainty prediction? Aborting..." );
|
|
}
|
|
}
|
|
- fmk->hikComputeKVNApproximationFast ( precomputedTForVarEst, *q, x, normKStar );
|
|
|
|
|
|
+ fmk->hikComputeKVNApproximationFast ( precomputedTForVarEst, this->q, x, normKStar );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1512,7 +1510,7 @@ void FMKGPHyperparameterOptimization::computePredictiveVarianceApproximateRough
|
|
{
|
|
{
|
|
fthrow ( Exception, "The precomputedAForVarEst is empty...have you trained this classifer? Aborting..." );
|
|
fthrow ( Exception, "The precomputedAForVarEst is empty...have you trained this classifer? Aborting..." );
|
|
}
|
|
}
|
|
- fmk->hikComputeKVNApproximation ( precomputedAForVarEst, x, normKStar, pf );
|
|
|
|
|
|
+ fmk->hikComputeKVNApproximation ( precomputedAForVarEst, x, normKStar, this->pf );
|
|
}
|
|
}
|
|
|
|
|
|
predVariance = kSelf - ( 1.0 / eigenMax[0] )* normKStar;
|
|
predVariance = kSelf - ( 1.0 / eigenMax[0] )* normKStar;
|
|
@@ -1759,7 +1757,28 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & _is,
|
|
{
|
|
{
|
|
if ( this->q != NULL )
|
|
if ( this->q != NULL )
|
|
delete this->q;
|
|
delete this->q;
|
|
- this->q = new Quantization();
|
|
|
|
|
|
+
|
|
|
|
+ std::string s_quantType;
|
|
|
|
+ _is >> s_quantType;
|
|
|
|
+ s_quantType = this->removeStartTag ( s_quantType );
|
|
|
|
+
|
|
|
|
+ if ( s_quantType == "Quantization1DAequiDist0To1" )
|
|
|
|
+ {
|
|
|
|
+ this->q = new NICE::Quantization1DAequiDist0To1();
|
|
|
|
+ }
|
|
|
|
+ else if ( s_quantType == "Quantization1DAequiDist0ToMax" )
|
|
|
|
+ {
|
|
|
|
+ this->q = new NICE::Quantization1DAequiDist0ToMax ( );
|
|
|
|
+ }
|
|
|
|
+ else if ( s_quantType == "QuantizationNDAequiDist0ToMax" )
|
|
|
|
+ {
|
|
|
|
+ this->q = new NICE::QuantizationNDAequiDist0ToMax ( );
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ fthrow(Exception, "Quantization type is unknown " << s_quantType);
|
|
|
|
+ }
|
|
|
|
+
|
|
this->q->restore ( _is, _format );
|
|
this->q->restore ( _is, _format );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1793,14 +1812,17 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & _is,
|
|
throw;
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
- std::string transform = this->removeStartTag ( tmp );
|
|
|
|
-
|
|
|
|
|
|
+ std::string transform ( this->removeStartTag( tmp ) );
|
|
|
|
|
|
if ( transform == "PFAbsExp" )
|
|
if ( transform == "PFAbsExp" )
|
|
{
|
|
{
|
|
- this->pf = new PFAbsExp ();
|
|
|
|
|
|
+ this->pf = new NICE::PFAbsExp ();
|
|
} else if ( transform == "PFExp" ) {
|
|
} else if ( transform == "PFExp" ) {
|
|
- this->pf = new PFExp ();
|
|
|
|
|
|
+ this->pf = new NICE::PFExp ();
|
|
|
|
+ }
|
|
|
|
+ else if ( transform == "PFIdentity" )
|
|
|
|
+ {
|
|
|
|
+ this->pf = new NICE::PFIdentity( );
|
|
} else {
|
|
} else {
|
|
fthrow(Exception, "Transformation type is unknown " << transform);
|
|
fthrow(Exception, "Transformation type is unknown " << transform);
|
|
}
|
|
}
|
|
@@ -1826,7 +1848,7 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & _is,
|
|
PrecomputedType pct;
|
|
PrecomputedType pct;
|
|
pct.setIoUntilEndOfFile ( false );
|
|
pct.setIoUntilEndOfFile ( false );
|
|
pct.restore ( _is, _format );
|
|
pct.restore ( _is, _format );
|
|
- precomputedA.insert ( std::pair<uint, PrecomputedType> ( nr, pct ) );
|
|
|
|
|
|
+ this->precomputedA.insert ( std::pair<uint, PrecomputedType> ( nr, pct ) );
|
|
}
|
|
}
|
|
|
|
|
|
_is >> tmp; // end of block
|
|
_is >> tmp; // end of block
|
|
@@ -1848,7 +1870,7 @@ void FMKGPHyperparameterOptimization::restore ( std::istream & _is,
|
|
PrecomputedType pct;
|
|
PrecomputedType pct;
|
|
pct.setIoUntilEndOfFile ( false );
|
|
pct.setIoUntilEndOfFile ( false );
|
|
pct.restore ( _is, _format );
|
|
pct.restore ( _is, _format );
|
|
- precomputedB.insert ( std::pair<uint, PrecomputedType> ( nr, pct ) );
|
|
|
|
|
|
+ this->precomputedB.insert ( std::pair<uint, PrecomputedType> ( nr, pct ) );
|
|
}
|
|
}
|
|
|
|
|
|
_is >> tmp; // end of block
|
|
_is >> tmp; // end of block
|
|
@@ -2250,7 +2272,7 @@ void FMKGPHyperparameterOptimization::store ( std::ostream & _os,
|
|
if ( q != NULL )
|
|
if ( q != NULL )
|
|
{
|
|
{
|
|
_os << "NOTNULL" << std::endl;
|
|
_os << "NOTNULL" << std::endl;
|
|
- q->store ( _os, _format );
|
|
|
|
|
|
+ this->q->store ( _os, _format );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|