123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- #ifndef _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
- #define _NICE_FMKGPHYPERPARAMETEROPTIMIZATIONINCLUDE
- #include <vector>
- #include <set>
- #include <map>
- #include <core/algebra/EigValues.h>
- #include <core/algebra/IterativeLinearSolver.h>
- #include <core/basics/Config.h>
- #include <core/basics/Persistent.h>
- #include <core/vector/VectorT.h>
- #ifdef NICE_USELIB_MATIO
- #include <core/matlabAccess/MatFileIO.h>
- #endif
- #include "gp-hik-core/FastMinKernel.h"
- #include "gp-hik-core/GPLikelihoodApprox.h"
- #include "gp-hik-core/IKMLinearCombination.h"
- #include "gp-hik-core/OnlineLearnable.h"
- #include "gp-hik-core/Quantization.h"
- #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
- namespace NICE {
-
-
-
- class FMKGPHyperparameterOptimization : public NICE::Persistent, public NICE::OnlineLearnable
- {
- protected:
-
-
-
-
-
-
-
-
-
-
-
-
- bool verbose;
-
- bool verboseTime;
-
- bool debug;
-
-
-
-
-
-
- bool b_performRegression;
-
-
- NICE::FastMinKernel *fmk;
-
- NICE::Quantization *q;
-
-
-
- double parameterUpperBound;
-
-
- double parameterLowerBound;
-
-
- NICE::ParameterizedFunction *pf;
-
-
-
-
- typedef VVector PrecomputedType;
-
- std::map< int, PrecomputedType > precomputedA;
-
- std::map< int, PrecomputedType > precomputedB;
-
-
- std::map< int, double * > precomputedT;
-
-
- NICE::Vector labels;
-
-
- int binaryLabelPositive;
-
- int binaryLabelNegative;
-
-
- std::set<int> knownClasses;
-
-
- NICE::IKMLinearCombination * ikmsum;
-
-
-
-
-
-
- IterativeLinearSolver *linsolver;
-
-
- int ils_max_iterations;
-
-
-
-
-
- enum OPTIMIZATIONTECHNIQUE{
- OPT_GREEDY = 0,
- OPT_DOWNHILLSIMPLEX,
- OPT_NONE
- };
-
- OPTIMIZATIONTECHNIQUE optimizationMethod;
-
-
- bool optimizeNoise;
-
-
-
- double parameterStepSize;
-
-
-
-
-
- int downhillSimplexMaxIterations;
-
-
- double downhillSimplexTimeLimit;
-
-
- double downhillSimplexParamTol;
-
-
-
-
-
-
- bool verifyApproximation;
-
- NICE::EigValues *eig;
-
-
- int nrOfEigenvaluesToConsider;
-
-
- NICE::Vector eigenMax;
-
- NICE::Matrix eigenMaxVectors;
-
-
-
-
-
-
- int nrOfEigenvaluesToConsiderForVarApprox;
-
-
- PrecomputedType precomputedAForVarEst;
-
-
- double * precomputedTForVarEst;
-
-
-
-
-
- bool b_usePreviousAlphas;
-
-
- std::map<int, NICE::Vector> previousAlphas;
-
-
-
-
-
-
-
-
-
- int prepareBinaryLabels ( std::map<int, NICE::Vector> & binaryLabels, const NICE::Vector & y , std::set<int> & myClasses);
-
-
- inline void setupGPLikelihoodApprox( GPLikelihoodApprox * & gplike, const std::map<int, NICE::Vector> & binaryLabels, uint & parameterVectorSize);
-
-
- inline void updateEigenDecomposition( const int & i_noEigenValues );
-
-
- inline void performOptimization( GPLikelihoodApprox & gplike, const uint & parameterVectorSize);
-
-
-
- inline void transformFeaturesWithOptimalParameters(const GPLikelihoodApprox & gplike, const uint & parameterVectorSize);
-
-
- inline void computeMatricesAndLUTs( const GPLikelihoodApprox & gplike);
-
-
-
-
- void updateAfterIncrement (
- const std::set<int> newClasses,
- const bool & performOptimizationAfterIncrement = false
- );
-
-
- public:
-
- FMKGPHyperparameterOptimization( );
-
-
- FMKGPHyperparameterOptimization( const bool & b_performRegression );
-
- FMKGPHyperparameterOptimization( const Config *conf, const std::string & confSection = "FMKGPHyperparameterOptimization" );
-
-
-
- FMKGPHyperparameterOptimization( const Config *conf, FastMinKernel *_fmk, const std::string & confSection = "FMKGPHyperparameterOptimization" );
-
-
- virtual ~FMKGPHyperparameterOptimization();
-
-
-
- void initFromConfig( const Config *conf, const std::string & confSection = "FMKGPHyperparameterOptimization" );
-
-
-
-
-
-
-
-
- void setParameterUpperBound(const double & _parameterUpperBound);
-
-
- void setParameterLowerBound(const double & _parameterLowerBound);
-
-
-
- std::set<int> getKnownClassNumbers ( ) const;
-
-
- void setPerformRegression ( const bool & b_performRegression );
-
-
-
- void setFastMinKernel ( FastMinKernel *fmk );
-
-
- void setNrOfEigenvaluesToConsiderForVarApprox ( const int & i_nrOfEigenvaluesToConsiderForVarApprox );
-
-
-
-
-
-
- #ifdef NICE_USELIB_MATIO
-
- void optimizeBinary ( const sparse_t & data, const NICE::Vector & y, const std::set<int> & positives, const std::set<int> & negatives, double noise );
-
- void optimize ( const sparse_t & data, const NICE::Vector & y, const std::map<int, int> & examples, double noise );
- #endif
-
- void optimize ( const NICE::Vector & y );
-
-
- void optimize ( std::map<int, NICE::Vector> & binaryLabels );
-
-
-
- void prepareVarianceApproximationRough();
-
-
-
- void prepareVarianceApproximationFine();
-
-
- int classify ( const NICE::SparseVector & x, SparseVector & scores ) const;
-
-
- int classify ( const NICE::Vector & x, SparseVector & scores ) const;
-
-
-
-
-
-
- void computePredictiveVarianceApproximateRough(const NICE::SparseVector & x, double & predVariance ) const;
-
-
-
- void computePredictiveVarianceApproximateFine(const NICE::SparseVector & x, double & predVariance ) const;
-
-
-
- void computePredictiveVarianceExact(const NICE::SparseVector & x, double & predVariance ) const;
-
-
-
-
-
-
-
-
- void computePredictiveVarianceApproximateRough(const NICE::Vector & x, double & predVariance ) const;
-
-
-
-
- void computePredictiveVarianceApproximateFine(const NICE::Vector & x, double & predVariance ) const;
-
-
-
-
- void computePredictiveVarianceExact(const NICE::Vector & x, double & predVariance ) const;
-
-
-
-
-
-
-
-
-
-
-
- void restore ( std::istream & is, int format = 0 );
-
-
-
- void store ( std::ostream & os, int format = 0 ) const;
-
-
-
- void clear ( ) ;
-
-
-
-
-
-
-
- virtual void addExample( const NICE::SparseVector * example,
- const double & label,
- const bool & performOptimizationAfterIncrement = true
- );
-
-
- virtual void addMultipleExamples( const std::vector< const NICE::SparseVector * > & newExamples,
- const NICE::Vector & newLabels,
- const bool & performOptimizationAfterIncrement = true
- );
- };
- }
- #endif
|