123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419 |
- #ifndef FEATUREMATRIXINCLUDE
- #define FEATUREMATRIXINCLUDE
- #include <vector>
- #include <set>
- #include <map>
- #include <iostream>
- #include <limits>
- #include <core/basics/Exception.h>
- #include <core/basics/Persistent.h>
- #include <core/vector/MatrixT.h>
- #include <core/vector/SparseVectorT.h>
- #ifdef NICE_USELIB_MATIO
- #include <core/matlabAccess/MatFileIO.h>
- #endif
-
- #include "SortedVectorSparse.h"
- #include "gp-hik-core/parameterizedFunctions/ParameterizedFunction.h"
- namespace NICE {
-
-
-
- template<class T> class FeatureMatrixT : NICE::Persistent
- {
- protected:
- int n;
- int d;
- std::vector<NICE::SortedVectorSparse<T> > features;
-
-
- bool verbose;
-
- bool debug;
- public:
-
-
- typedef T value_type;
-
- typedef const T& const_reference;
-
- typedef T* iterator;
-
- typedef const T* const_iterator;
-
- typedef T& reference;
-
-
-
-
-
-
- FeatureMatrixT();
-
-
- FeatureMatrixT(const std::vector<std::vector<T> > & _features, const int & _dim = -1);
-
- #ifdef NICE_USELIB_MATIO
-
- FeatureMatrixT(const sparse_t & _features, const int & _dim = -1);
- #endif
-
- FeatureMatrixT(const std::vector< const NICE::SparseVector * > & X, const bool dimensionsOverExamples = false, const int & _dim = -1);
-
- #ifdef NICE_USELIB_MATIO
-
- FeatureMatrixT(const sparse_t & _features, const std::map<int, int> & examples , const int & _dim = -1);
- #endif
-
- ~FeatureMatrixT();
-
-
-
-
-
-
- int get_n() const;
-
- int get_d() const;
-
-
- void set_d(const int & _d);
-
-
- void setVerbose( const bool & _verbose);
- bool getVerbose( ) const;
-
-
- void setDebug( const bool & _debug);
- bool getDebug( ) const;
-
-
-
- inline bool operator==(const FeatureMatrixT<T> & F) const;
-
-
- inline bool operator!= (const FeatureMatrixT<T> & F) const;
-
- inline FeatureMatrixT<T>& operator=(const FeatureMatrixT<T> & F);
-
-
- inline T operator()(const int row, const int col) const;
-
-
- inline T getUnsafe(const int row, const int col) const;
-
- inline T getOriginal(const int row, const int col) const;
-
- inline void set (const int row, const int col, const T & newElement, bool setTransformedValue = false);
-
-
- inline void setUnsafe (const int row, const int col, const T & newElement, bool setTransformedValue = false);
-
-
- void getDimension(const int & dim, NICE::SortedVectorSparse<T> & dimension) const;
-
-
- void getDimensionUnsafe(const int & dim, NICE::SortedVectorSparse<T> & dimension) const;
-
-
- void findFirstInDimension(const int & dim, const T & elem, int & position) const;
-
-
- void findLastInDimension(const int & dim, const T & elem, int & position) const;
-
-
- void findFirstLargerInDimension(const int & dim, const T & elem, int & position) const;
-
-
- void findLastSmallerInDimension(const int & dim, const T & elem, int & position) const;
-
-
-
-
-
-
-
- void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *pf = NULL );
-
-
- double computeSparsityRatio();
-
- void add_feature(const std::vector<T> & feature, const NICE::ParameterizedFunction *pf = NULL);
-
-
- void add_feature(const NICE::SparseVector & feature, const NICE::ParameterizedFunction *pf = NULL);
-
- void add_features(const std::vector<std::vector<T> > & _features );
-
-
- void set_features(const std::vector<std::vector<T> > & _features, std::vector<std::vector<int> > & permutations, const int & _dim = -1);
- void set_features(const std::vector<std::vector<T> > & _features, std::vector<std::map<int,int> > & permutations, const int & _dim = -1);
- void set_features(const std::vector<std::vector<T> > & _features, const int & _dim = -1);
- void set_features(const std::vector< const NICE::SparseVector * > & _features, const bool dimensionsOverExamples = false, const int & _dim = -1);
-
-
- void getPermutations( std::vector<std::vector<int> > & permutations) const;
- void getPermutations( std::vector<std::map<int,int> > & permutations) const;
-
-
- void print(std::ostream & os) const;
-
-
- void computeNonSparseMatrix(NICE::MatrixT<T> & matrix, bool transpose = false) const;
-
-
- void computeNonSparseMatrix(std::vector<std::vector<T> > & matrix, bool transpose = false) const;
-
-
- void swap(const int & row1, const int & col1, const int & row2, const int & col2);
-
-
- void swapUnsafe(const int & row1, const int & col1, const int & row2, const int & col2);
-
- const SortedVectorSparse<T> & getFeatureValues ( int dim ) const { return features[dim]; };
-
-
- SortedVectorSparse<T> & getFeatureValues ( int dim ) { return features[dim]; };
-
-
-
- void hikDiagonalElements( Vector & diagonalElements ) const;
-
- double hikTrace() const;
-
-
-
- int getNumberOfNonZeroElementsPerDimension(const int & dim) const;
-
-
-
- int getNumberOfZeroElementsPerDimension(const int & dim) const;
-
-
- virtual void restore ( std::istream & is, int format = 0 );
- virtual void store ( std::ostream & os, int format = 0 ) const;
- virtual void clear ( );
- };
-
- typedef FeatureMatrixT<double> FeatureMatrix;
- typedef FeatureMatrixT<bool> BoolFeatureMatrix;
- typedef FeatureMatrixT<char> CharFeatureMatrix;
- typedef FeatureMatrixT<int> IntFeatureMatrix;
- typedef FeatureMatrixT<float> FloatFeatureMatrix;
- }
- #ifdef __GNUC__
- #include "gp-hik-core/FeatureMatrixT.tcc"
- #endif
- #endif
|