123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- namespace NICE {
- /**
- * @class FastMinKernel
- * @brief Efficient GPs with HIK for classification by regression
- * @author Alexander Freytag
- */
-
- /** interface to FastMinKernel implementation*/
- class FastMinKernel : public NICE::Persistent, public OnlineLearnable
- {
- protected:
- /** number of examples */
- int n;
-
- int d;
-
- double noise;
-
-
- NICE::FeatureMatrixT<double> X_sorted;
-
-
- bool verbose;
-
- bool debug;
-
- void set_n(const int & _n){n = _n;};
-
-
- void set_d(const int & _d){d = _d;};
-
- void hik_prepare_kernel_multiplications(const std::vector<std::vector<double> > & X, NICE::FeatureMatrixT<double> & X_sorted, const int & _dim = -1);
-
- void hik_prepare_kernel_multiplications ( const std::vector< const NICE::SparseVector * > & X, NICE::FeatureMatrixT<double> & X_sorted, const bool & dimensionsOverExamples, const int & _dim = -1);
-
- void randomPermutation(NICE::Vector & permutation, const std::vector<int> & oldIndices, const int & newSize) const;
-
- enum ApproximationScheme{ MEDIAN = 0, EXPECTATION=1};
- ApproximationScheme approxScheme;
- public:
-
-
-
-
-
- FastMinKernel();
-
-
- FastMinKernel( const std::vector<std::vector<double> > & X, const double noise , const bool _debug = false, const int & _dim = -1);
-
-
- FastMinKernel( const std::vector< const NICE::SparseVector * > & X, const double noise, const bool _debug = false, const bool & dimensionsOverExamples=false, const int & _dim = -1);
-
- FastMinKernel ( const sparse_t & X, const double noise, const std::map<int, int> & examples, const bool _debug = false , const int & _dim = -1);
-
- ~FastMinKernel();
-
-
-
-
-
- void setApproximationScheme(const ApproximationScheme & _approxScheme = MEDIAN) {approxScheme = _approxScheme;};
-
- virtual void setApproximationScheme(const int & _approxScheme = 0);
-
-
- int get_n() const {return n;};
-
-
- int get_d() const {return d;};
-
- double getSparsityRatio(){return X_sorted.computeSparsityRatio();};
-
-
- void setVerbose( const bool & _verbose);
- bool getVerbose( ) const;
-
-
- void setDebug( const bool & _debug);
- bool getDebug( ) const;
-
-
-
-
-
-
-
- void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *pf = NULL );
-
-
- void hik_prepare_alpha_multiplications(const NICE::Vector & alpha, NICE::VVector & A, NICE::VVector & B) const;
-
-
- void hik_kernel_multiply(const NICE::VVector & A, const NICE::VVector & B, const NICE::Vector & alpha, NICE::Vector & beta) const;
- void hik_kernel_multiply_fast(const double *Tlookup, const Quantization & q, const NICE::Vector & alpha, NICE::Vector & beta) const;
-
- void hik_kernel_sum(const NICE::VVector & A, const NICE::VVector & B, const NICE::SparseVector & xstar, double & beta, const ParameterizedFunction *pf = NULL ) const;
-
-
- void hik_kernel_sum(const NICE::VVector & A, const NICE::VVector & B, const NICE::Vector & xstar, double & beta, const ParameterizedFunction *pf = NULL ) const;
-
-
- void hik_kernel_sum_fast(const double* Tlookup, const Quantization & q, const NICE::Vector & xstar, double & beta) const;
-
-
- void hik_kernel_sum_fast(const double *Tlookup, const Quantization & q, const NICE::SparseVector & xstar, double & beta) const;
-
- double *hik_prepare_alpha_multiplications_fast(const NICE::VVector & A, const NICE::VVector & B, const Quantization & q, const ParameterizedFunction *pf = NULL ) const;
-
-
- double* hikPrepareLookupTable(const NICE::Vector & alpha, const Quantization & q, const ParameterizedFunction *pf = NULL) const;
-
- void hikUpdateLookupTable(double * T, const double & alphaNew, const double & alphaOld, const int & idx, const Quantization & q, const ParameterizedFunction *pf ) const;
-
- FeatureMatrix & featureMatrix(void) { return X_sorted; };
- const FeatureMatrix & featureMatrix(void) const { return X_sorted; };
-
-
- double *solveLin(const NICE::Vector & y, NICE::Vector & alpha, const Quantization & q, const ParameterizedFunction *pf = NULL, const bool & useRandomSubsets = true, uint maxIterations = 10000, const int & _sizeOfRandomSubset = (-1), double minDelta = 1e-7, bool timeAnalysis = false) const;
-
- void setNoise ( double noise ) { this->noise = noise; }
-
- double getNoise (void) const { return noise; }
-
- double getFrobNormApprox();
-
-
-
- void hikPrepareKVNApproximation(NICE::VVector & A) const;
-
-
- double * hikPrepareKVNApproximationFast(NICE::VVector & A, const Quantization & q, const ParameterizedFunction *pf = NULL ) const;
-
-
- double* hikPrepareLookupTableForKVNApproximation(const Quantization & q, const ParameterizedFunction *pf = NULL) const;
-
-
-
-
-
-
- void hikComputeKVNApproximation(const NICE::VVector & A, const NICE::SparseVector & xstar, double & norm, const ParameterizedFunction *pf = NULL ) ;
-
-
- void hikComputeKVNApproximationFast(const double *Tlookup, const Quantization & q, const NICE::SparseVector & xstar, double & norm ) const;
-
-
- void hikComputeKernelVector( const NICE::SparseVector & xstar, NICE::Vector & kstar) const;
-
-
-
-
-
-
- void hikComputeKVNApproximation(const NICE::VVector & A, const NICE::Vector & xstar, double & norm, const ParameterizedFunction *pf = NULL ) ;
-
-
- void hikComputeKVNApproximationFast(const double *Tlookup, const Quantization & q, const NICE::Vector & xstar, double & norm ) const;
-
-
-
- void hikComputeKernelVector( const NICE::Vector & xstar, NICE::Vector & kstar) const;
-
-
- virtual void restore ( std::istream & is, int format = 0 );
- virtual void store ( std::ostream & os, int format = 0 ) const;
- virtual 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
- );
-
-
-
- void addExample(const NICE::SparseVector * example, const NICE::ParameterizedFunction *pf = NULL);
-
-
-
- void addMultipleExamples(const std::vector<const NICE::SparseVector * > & newExamples, const NICE::ParameterizedFunction *pf = NULL);
-
-
-
- };
- }
|