|
@@ -1,9 +1,8 @@
|
|
|
/**
|
|
|
* @file FMKGPHyperparameterOptimization.h
|
|
|
* @brief Heart of the framework to set up everything, perform optimization, classification, and variance prediction (Interface)
|
|
|
-* @author Erik Rodner, Alexander Freytag
|
|
|
-* @date 01/02/2012
|
|
|
-
|
|
|
+* @author Alexander Freytag, Erik Rodner
|
|
|
+* @date 01-02-2012 (dd-mm-yyyy)
|
|
|
*/
|
|
|
#ifndef _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
|
|
|
#define _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
|
|
@@ -39,122 +38,203 @@ namespace NICE {
|
|
|
/**
|
|
|
* @class FMKGPHyperparameterOptimization
|
|
|
* @brief Heart of the framework to set up everything, perform optimization, classification, and variance prediction
|
|
|
- * @author Erik Rodner, Alexander Freytag
|
|
|
+ * @author Alexander Freytag, Erik Rodner
|
|
|
*/
|
|
|
|
|
|
class FMKGPHyperparameterOptimization : public NICE::Persistent, public NICE::OnlineLearnable
|
|
|
{
|
|
|
protected:
|
|
|
- enum {
|
|
|
- OPT_GREEDY = 0,
|
|
|
- OPT_DOWNHILLSIMPLEX,
|
|
|
- OPT_NONE,
|
|
|
- OPT_NUMBEROFMETHODS
|
|
|
- };
|
|
|
-
|
|
|
- /** optimization method used */
|
|
|
- int optimizationMethod;
|
|
|
-
|
|
|
- /** the parameterized function we use within the minimum kernel */
|
|
|
- ParameterizedFunction *pf;
|
|
|
-
|
|
|
- /** method computing eigenvalues */
|
|
|
- EigValues *eig;
|
|
|
-
|
|
|
- /** method for solving linear equation systems */
|
|
|
- IterativeLinearSolver *linsolver;
|
|
|
-
|
|
|
- /** object which stores our sorted data and provides fast hik functions */
|
|
|
- FastMinKernel *fmk;
|
|
|
-
|
|
|
- /** object which stores our quantization object */
|
|
|
- Quantization *q;
|
|
|
-
|
|
|
+
|
|
|
+ /////////////////////////
|
|
|
+ /////////////////////////
|
|
|
+ // PROTECTED VARIABLES //
|
|
|
+ /////////////////////////
|
|
|
+ /////////////////////////
|
|
|
+
|
|
|
+ ///////////////////////////////////
|
|
|
+ // output/debug related settings //
|
|
|
+ ///////////////////////////////////
|
|
|
+
|
|
|
/** verbose flag */
|
|
|
bool verbose;
|
|
|
/** verbose flag for time measurement outputs */
|
|
|
bool verboseTime;
|
|
|
/** debug flag for several outputs useful for debugging*/
|
|
|
bool debug;
|
|
|
+
|
|
|
+ //////////////////////////////////////
|
|
|
+ // classification related variables //
|
|
|
+ //////////////////////////////////////
|
|
|
+
|
|
|
+ /** object storing sorted data and providing fast hik methods */
|
|
|
+ NICE::FastMinKernel *fmk;
|
|
|
+
|
|
|
+ /** object performing feature quantization */
|
|
|
+ NICE::Quantization *q;
|
|
|
+
|
|
|
+ /** the parameterized function we use within the minimum kernel */
|
|
|
+ NICE::ParameterizedFunction *pf;
|
|
|
|
|
|
- /** optimization parameters */
|
|
|
+ /** method for solving linear equation systems - needed to compute K^-1 \times y */
|
|
|
+ IterativeLinearSolver *linsolver;
|
|
|
+
|
|
|
+ /** Max. number of iterations the iterative linear solver is allowed to run */
|
|
|
+ int ils_max_iterations;
|
|
|
+
|
|
|
+ /** Simple type definition for precomputation matrices used for fast classification */
|
|
|
+ typedef VVector PrecomputedType;
|
|
|
+
|
|
|
+ /** precomputed arrays A (1 per class) needed for classification without quantization */
|
|
|
+ std::map< int, PrecomputedType > precomputedA;
|
|
|
+ /** precomputed arrays B (1 per class) needed for classification without quantization */
|
|
|
+ std::map< int, PrecomputedType > precomputedB;
|
|
|
+
|
|
|
+ /** precomputed LUTs (1 per class) needed for classification with quantization */
|
|
|
+ std::map< int, double * > precomputedT;
|
|
|
+
|
|
|
+ //! storing the labels is needed for Incremental Learning (re-optimization)
|
|
|
+ NICE::Vector labels;
|
|
|
+
|
|
|
+ //! store the class number of the positive class (i.e., larger class no), only used in binary settings
|
|
|
+ int binaryLabelPositive;
|
|
|
+ //! store the class number of the negative class (i.e., smaller class no), only used in binary settings
|
|
|
+ int binaryLabelNegative;
|
|
|
+
|
|
|
+ //! contains all class numbers of the currently known classes
|
|
|
+ std::set<int> knownClasses;
|
|
|
+
|
|
|
+ //! container for multiple kernel matrices (e.g., a data-containing kernel matrix (GMHIKernel) and a noise matrix (IKMNoise) )
|
|
|
+ NICE::IKMLinearCombination * ikmsum;
|
|
|
+
|
|
|
+
|
|
|
+ /////////////////////////////////////
|
|
|
+ // optimization related parameters //
|
|
|
+ /////////////////////////////////////
|
|
|
+
|
|
|
+ enum {
|
|
|
+ OPT_GREEDY = 0,
|
|
|
+ OPT_DOWNHILLSIMPLEX,
|
|
|
+ OPT_NONE
|
|
|
+ };
|
|
|
+
|
|
|
+ /** specify the optimization method used (see corresponding enum) */
|
|
|
+ int optimizationMethod;
|
|
|
+
|
|
|
+ //! whether or not to optimize noise with the GP likelihood
|
|
|
+ bool optimizeNoise;
|
|
|
+
|
|
|
+ /** upper bound for hyper parameters to optimize */
|
|
|
double parameterUpperBound;
|
|
|
+
|
|
|
+ /** lower bound for hyper parameters to optimize */
|
|
|
double parameterLowerBound;
|
|
|
+
|
|
|
+ // specific to greedy optimization
|
|
|
+ /** step size used in grid based greedy optimization technique */
|
|
|
double parameterStepSize;
|
|
|
- int ils_max_iterations;
|
|
|
-
|
|
|
+
|
|
|
+ // specific to downhill simplex optimization
|
|
|
+ /** Max. number of iterations the downhill simplex optimizer is allowed to run */
|
|
|
int downhillSimplexMaxIterations;
|
|
|
+
|
|
|
+ /** Max. time the downhill simplex optimizer is allowed to run */
|
|
|
double downhillSimplexTimeLimit;
|
|
|
+
|
|
|
+ /** Max. number of iterations the iterative linear solver is allowed to run */
|
|
|
double downhillSimplexParamTol;
|
|
|
+
|
|
|
+
|
|
|
+ // likelihood computation related variables
|
|
|
|
|
|
- /** whether to compute the likelihood with the usual method */
|
|
|
+ /** whether to compute the exact likelihood by computing the exact kernel matrix (not recommended - only for debugging/comparison purpose) */
|
|
|
bool verifyApproximation;
|
|
|
+
|
|
|
+ /** method computing eigenvalues and eigenvectors*/
|
|
|
+ NICE::EigValues *eig;
|
|
|
|
|
|
- /** number of Eigenvalues to consider in the approximation of |K|_F */
|
|
|
+ /** number of Eigenvalues to consider in the approximation of |K|_F used for approximating the likelihood */
|
|
|
int nrOfEigenvaluesToConsider;
|
|
|
|
|
|
- /** number of Eigenvalues to consider in the fine approximation of the predictive variance */
|
|
|
- int nrOfEigenvaluesToConsiderForVarApprox;
|
|
|
-
|
|
|
- typedef VVector PrecomputedType;
|
|
|
-
|
|
|
- /** precomputed arrays and lookup tables */
|
|
|
- std::map< int, PrecomputedType > precomputedA;
|
|
|
- std::map< int, PrecomputedType > precomputedB;
|
|
|
- std::map< int, double * > precomputedT;
|
|
|
-
|
|
|
- PrecomputedType precomputedAForVarEst;
|
|
|
- double * precomputedTForVarEst;
|
|
|
-
|
|
|
- //! optimize noise with the GP likelihood
|
|
|
- bool optimizeNoise;
|
|
|
-
|
|
|
//! k largest eigenvalues of the kernel matrix (k == nrOfEigenvaluesToConsider)
|
|
|
NICE::Vector eigenMax;
|
|
|
|
|
|
//! eigenvectors corresponding to k largest eigenvalues (k == nrOfEigenvaluesToConsider) -- format: nxk
|
|
|
NICE::Matrix eigenMaxVectors;
|
|
|
|
|
|
- //! needed for optimization and variance approximation
|
|
|
- IKMLinearCombination * ikmsum;
|
|
|
+
|
|
|
+ ////////////////////////////////////////////
|
|
|
+ // variance computation related variables //
|
|
|
+ ////////////////////////////////////////////
|
|
|
|
|
|
- //! storing the labels is needed for Incremental Learning (re-optimization)
|
|
|
- NICE::Vector labels;
|
|
|
+ /** number of Eigenvalues to consider in the fine approximation of the predictive variance (fine approximation only) */
|
|
|
+ int nrOfEigenvaluesToConsiderForVarApprox;
|
|
|
+
|
|
|
+ /** precomputed array needed for rough variance approximation without quantization */
|
|
|
+ PrecomputedType precomputedAForVarEst;
|
|
|
+
|
|
|
+ /** precomputed LUT needed for rough variance approximation with quantization */
|
|
|
+ double * precomputedTForVarEst;
|
|
|
|
|
|
+ /////////////////////////////////////////////////////
|
|
|
+ // online / incremental learning related variables //
|
|
|
+ /////////////////////////////////////////////////////
|
|
|
|
|
|
- //! calculate binary label vectors using a multi-class label vector
|
|
|
+ /** whether or not to use previous alpha solutions as initialization after adding new examples*/
|
|
|
+ bool b_usePreviousAlphas;
|
|
|
+
|
|
|
+ //! store alpha vectors for good initializations in the IL setting, if activated
|
|
|
+ std::map<int, NICE::Vector> previousAlphas;
|
|
|
+
|
|
|
+
|
|
|
+ /////////////////////////
|
|
|
+ /////////////////////////
|
|
|
+ // PROTECTED METHODS //
|
|
|
+ /////////////////////////
|
|
|
+ /////////////////////////
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief calculate binary label vectors using a multi-class label vector
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
int prepareBinaryLabels ( std::map<int, NICE::Vector> & binaryLabels, const NICE::Vector & y , std::set<int> & myClasses);
|
|
|
|
|
|
- //! prepare the GPLike object for given binary labels and already given ikmsum-object
|
|
|
+ /**
|
|
|
+ * @brief prepare the GPLike object for given binary labels and already given ikmsum-object
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
inline void setupGPLikelihoodApprox( GPLikelihoodApprox * & gplike, const std::map<int, NICE::Vector> & binaryLabels, uint & parameterVectorSize);
|
|
|
|
|
|
- //! update eigenvectors and eigenvalues for given ikmsum-objects and a method to compute eigenvalues
|
|
|
+ /**
|
|
|
+ * @brief update eigenvectors and eigenvalues for given ikmsum-objects and a method to compute eigenvalues
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
inline void updateEigenDecomposition( const int & i_noEigenValues );
|
|
|
|
|
|
- //! core of the optimize-functions
|
|
|
+ /**
|
|
|
+ * @brief core of the optimize-functions
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
inline void performOptimization( GPLikelihoodApprox & gplike, const uint & parameterVectorSize);
|
|
|
|
|
|
- //! apply the optimized transformation values to the underlying features
|
|
|
+ /**
|
|
|
+ * @brief apply the optimized transformation values to the underlying features
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
inline void transformFeaturesWithOptimalParameters(const GPLikelihoodApprox & gplike, const uint & parameterVectorSize);
|
|
|
|
|
|
- //! build the resulting matrices A and B as well as lookup tables T for fast evaluations using the optimized parameter settings
|
|
|
+ /**
|
|
|
+ * @brief build the resulting matrices A and B as well as lookup tables T for fast evaluations using the optimized parameter settings
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
inline void computeMatricesAndLUTs( const GPLikelihoodApprox & gplike);
|
|
|
|
|
|
|
|
|
- //! store the class number of the positive class (i.e., larger class no), only used in binary settings
|
|
|
- int binaryLabelPositive;
|
|
|
- //! store the class number of the negative class (i.e., smaller class no), only used in binary settings
|
|
|
- int binaryLabelNegative;
|
|
|
-
|
|
|
- //! contains all class numbers of the currently known classes
|
|
|
- std::set<int> knownClasses;
|
|
|
-
|
|
|
- bool b_usePreviousAlphas;
|
|
|
-
|
|
|
- //! we store the alpha vectors for good initializations in the IL setting
|
|
|
- std::map<int, NICE::Vector> previousAlphas;
|
|
|
|
|
|
- //! Update matrices (A, B, LUTs) and optionally find optimal parameters after adding (a) new example(s).
|
|
|
+ /**
|
|
|
+ * @brief Update matrices (A, B, LUTs) and optionally find optimal parameters after adding (a) new example(s).
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void updateAfterIncrement (
|
|
|
const std::set<int> newClasses,
|
|
|
const bool & performOptimizationAfterIncrement = false
|
|
@@ -164,7 +244,10 @@ class FMKGPHyperparameterOptimization : public NICE::Persistent, public NICE::On
|
|
|
|
|
|
public:
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @brief simple constructor
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
FMKGPHyperparameterOptimization();
|
|
|
|
|
|
/**
|
|
@@ -176,21 +259,41 @@ class FMKGPHyperparameterOptimization : public NICE::Persistent, public NICE::On
|
|
|
*/
|
|
|
FMKGPHyperparameterOptimization( const Config *conf, ParameterizedFunction *pf, FastMinKernel *fmk = NULL, const std::string & confSection = "GPHIKClassifier" );
|
|
|
|
|
|
- /** simple destructor */
|
|
|
+ /**
|
|
|
+ * @brief standard destructor
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
virtual ~FMKGPHyperparameterOptimization();
|
|
|
|
|
|
///////////////////// ///////////////////// /////////////////////
|
|
|
// GET / SET
|
|
|
- ///////////////////// ///////////////////// /////////////////////
|
|
|
+ ///////////////////// ///////////////////// /////////////////////
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Set lower bound for hyper parameters to optimize
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void setParameterUpperBound(const double & _parameterUpperBound);
|
|
|
+ /**
|
|
|
+ * @brief Set upper bound for hyper parameters to optimize
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void setParameterLowerBound(const double & _parameterLowerBound);
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Get the currently known class numbers
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
std::set<int> getKnownClassNumbers ( ) const;
|
|
|
|
|
|
///////////////////// ///////////////////// /////////////////////
|
|
|
// CLASSIFIER STUFF
|
|
|
///////////////////// ///////////////////// /////////////////////
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Set variables and parameters to default or config-specified values
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void initialize( const Config *conf, ParameterizedFunction *pf, FastMinKernel *fmk = NULL, const std::string & confSection = "GPHIKClassifier" );
|
|
|
|
|
|
#ifdef NICE_USELIB_MATIO
|
|
@@ -347,19 +450,41 @@ class FMKGPHyperparameterOptimization : public NICE::Persistent, public NICE::On
|
|
|
// interface specific methods for store and restore
|
|
|
///////////////////// INTERFACE PERSISTENT /////////////////////
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief Load current object from external file (stream)
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void restore ( std::istream & is, int format = 0 );
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Save current object to external file (stream)
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void store ( std::ostream & os, int format = 0 ) const;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Clear current object
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
void clear ( ) ;
|
|
|
|
|
|
///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
|
|
|
// interface specific methods for incremental extensions
|
|
|
///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
|
|
|
|
|
|
+ /**
|
|
|
+ * @brief add a new example
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
virtual void addExample( const NICE::SparseVector * example,
|
|
|
const double & label,
|
|
|
const bool & performOptimizationAfterIncrement = true
|
|
|
);
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief add several new examples
|
|
|
+ * @author Alexander Freytag
|
|
|
+ */
|
|
|
virtual void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
|
|
|
const NICE::Vector & newLabels,
|
|
|
const bool & performOptimizationAfterIncrement = true
|