Browse Source

towards uint-support, unstable commit!

Alexander Freytag 9 years ago
parent
commit
91d6c7e5b2
6 changed files with 946 additions and 644 deletions
  1. 290 216
      FastMinKernel.cpp
  2. 127 53
      FastMinKernel.h
  3. 112 46
      FeatureMatrixT.h
  4. 338 258
      FeatureMatrixT.tcc
  5. 1 0
      Quantization.cpp
  6. 78 71
      SortedVectorSparse.h

File diff suppressed because it is too large
+ 290 - 216
FastMinKernel.cpp


+ 127 - 53
FastMinKernel.h

@@ -42,46 +42,56 @@ namespace NICE {
 
     protected:
       /** number of examples */
-      int n;
+      uint ui_n;
 
       /** dimension of feature vectors */
-      int d; 
+      uint ui_d; 
 
       /** noise added to the diagonal of the kernel matrix */
-      double noise;
+      double d_noise;
       
       /** sorted matrix of features (sorted along each dimension) */
       NICE::FeatureMatrixT<double> X_sorted;
       
       //! verbose flag for output after calling the restore-function
-      bool verbose;
+      bool b_verbose;
       //! debug flag for output during debugging
-      bool debug;      
+      bool b_debug;      
 
       /** 
       * @brief Set number of examples
       * @author Alexander Freytag
       * @date 07-12-2011 (dd-mm-yyyy)
       */
-      void set_n(const int & _n){n = _n;};
+      void set_n(const uint & _n){this->ui_n = _n;};
       
       /** 
       * @brief Set number of dimensions
       * @author Alexander Freytag
       * @date 07-12-2011 (dd-mm-yyyy)
       */
-      void set_d(const int & _d){d = _d;};     
+      void set_d(const uint & _d){this->ui_d = _d;};     
 
       /** 
       * @brief Prepare the efficient HIK-computations part 1: order the features in each dimension and save the permutation. Pay attention: X is of dim n x d, where as X_sorted is of dimensionality d x n!
       * @author Alexander Freytag
       * @date 07-12-2011 (dd-mm-yyyy)
       */
-      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;
+      void hik_prepare_kernel_multiplications(const std::vector<std::vector<double> > & _X, 
+                                              NICE::FeatureMatrixT<double> & _X_sorted, 
+                                              const uint & _dim = 0
+                                             );
+      
+      void hik_prepare_kernel_multiplications ( const std::vector< const NICE::SparseVector * > & _X, 
+                                                NICE::FeatureMatrixT<double> & _X_sorted, 
+                                                const bool & _dimensionsOverExamples, 
+                                                const uint & _dim = 0
+                                              );
+      
+      void randomPermutation(NICE::Vector & _permutation, 
+                             const std::vector<uint> & _oldIndices, 
+                             const uint & _newSize
+                            ) const;
       
       enum ApproximationScheme{ MEDIAN = 0, EXPECTATION=1};
       ApproximationScheme approxScheme;
@@ -104,7 +114,11 @@ namespace NICE {
       * @author Alexander Freytag
       * @date 06-12-2011 (dd-mm-yyyy)
       */
-      FastMinKernel( const std::vector<std::vector<double> > & X, const double noise , const bool _debug = false, const int & _dim = -1);
+      FastMinKernel( const std::vector<std::vector<double> > & _X, 
+                     const double _noise ,
+                     const bool _debug = false, 
+                     const uint & _dim = 0
+                   );
 
       
       /**
@@ -113,7 +127,12 @@ namespace NICE {
       * @param X vector of sparse vector pointers
       * @param noise GP noise
       */
-      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 std::vector< const NICE::SparseVector * > & X, 
+                     const double _noise, 
+                     const bool _debug = false, 
+                     const bool & dimensionsOverExamples=false, 
+                     const uint & _dim = 0
+                   );
 
 #ifdef NICE_USELIB_MATIO
       /**
@@ -123,7 +142,11 @@ namespace NICE {
       * @param noise additional noise variance of the labels
       * @param examples set of indices to include
       */
-      FastMinKernel ( const sparse_t & X, const double noise, const std::map<int, int> & examples, const bool _debug = false , const int & _dim = -1);
+      FastMinKernel ( const sparse_t & _X, 
+                      const double _noise, 
+                      const std::map<uint, uint> & _examples, 
+                      const bool _debug = false , 
+                      const uint & _dim = 0);
 #endif
 
       /** 
@@ -148,14 +171,14 @@ namespace NICE {
       * @author Alexander Freytag
       * @date 07-12-2011 (dd-mm-yyyy)
       */
-      int get_n() const;
+      uint get_n() const;
       
       /** 
       * @brief Get number of dimensions
       * @author Alexander Freytag
       * @date 07-12-2011 (dd-mm-yyyy)
       */
-      int get_d() const;
+      uint get_d() const;
 
       /** 
       * @brief Computes the ratio of sparsity across the matrix
@@ -183,22 +206,33 @@ namespace NICE {
       *
       * @param pf the parameterized function (optional), if not given, nothing will be done
       */         
-      void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *pf = NULL );
+      void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *_pf = NULL );
           
       /** 
       * @brief  Prepare the efficient HIK-computations part 2: calculate the partial sum for each dimension. Explicitely exploiting sparsity!!! Pay attention: X_sorted is of dimensionality d x n!
       * @author Alexander Freytag
       * @date 17-01-2012 (dd-mm-yyyy)
       */
-      void hik_prepare_alpha_multiplications(const NICE::Vector & alpha, NICE::VVector & A, NICE::VVector & B) const;
+      void hik_prepare_alpha_multiplications(const NICE::Vector & _alpha, 
+                                             NICE::VVector & _A, 
+                                             NICE::VVector & _B
+                                            ) const;
             
       /**
       * @brief Computing K*alpha with the minimum kernel trick, explicitely exploiting sparsity!!!
       * @author Alexander Freytag
       * @date 17-01-2012 (dd-mm-yyyy)
       */
-      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_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;
 
       /**
       * @brief Computing k_{*}*alpha using the minimum kernel trick and exploiting sparsity of the feature vector given
@@ -211,7 +245,12 @@ namespace NICE {
       * @param beta result of the scalar product
       * @param pf optional feature transformation
       */
-      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::SparseVector & _xstar, 
+                          double & _beta, 
+                          const ParameterizedFunction *_pf = NULL 
+                         ) const;
       
       /**
       * @brief Computing k_{*}*alpha using the minimum kernel trick and exploiting sparsity of the feature vector given
@@ -225,7 +264,12 @@ namespace NICE {
       * @param beta result of the scalar product
       * @param pf optional feature transformation
       */
-      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(const NICE::VVector & _A, 
+                          const NICE::VVector & _B, 
+                          const NICE::Vector & _xstar, 
+                          double & _beta, 
+                          const ParameterizedFunction *_pf = NULL 
+                         ) const;      
       
       /**
       * @brief compute beta = k_*^T * alpha by using a large lookup table created by hik_prepare_alpha_multiplications_fast
@@ -238,7 +282,11 @@ namespace NICE {
       * @param xstar feature vector (indirect k_*)
       * @param beta result of the calculation
       */
-      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::Vector & _xstar, 
+                               double & _beta
+                              ) const;
       /**
       * @brief compute beta = k_*^T * alpha by using a large lookup table created by hik_prepare_alpha_multiplications_fast
       * NOTE: Whenever possible, you should use sparse features to obtain significantly smaller computation times!
@@ -250,7 +298,11 @@ namespace NICE {
       * @param beta result of the calculation
       */      
 
-      void hik_kernel_sum_fast(const double *Tlookup, const Quantization & q, const NICE::SparseVector & xstar, double & beta) const;
+      void hik_kernel_sum_fast(const double *_Tlookup, 
+                               const Quantization & _q, 
+                               const NICE::SparseVector & _xstar, 
+                               double & _beta
+                              ) const;
 
       /**
       * @brief compute lookup table for HIK calculation using quantized signals and prepare for K*alpha or k_*^T * alpha computations
@@ -264,7 +316,11 @@ namespace NICE {
       * @return C standard vector representing a q.size()*n double matrix and the lookup table T. Elements can be accessed with
       * T[dim*q.size() + j], where j is a bin entry corresponding to quantization q.
       */
-      double *hik_prepare_alpha_multiplications_fast(const NICE::VVector & A, const NICE::VVector & B, const Quantization & q, const ParameterizedFunction *pf = NULL ) const;
+      double *hik_prepare_alpha_multiplications_fast(const NICE::VVector & _A, 
+                                                     const NICE::VVector & _B, 
+                                                     const Quantization & _q, 
+                                                     const ParameterizedFunction *_pf = NULL 
+                                                    ) const;
       
       /**
       * @brief compute lookup table for HIK calculation using quantized signals and prepare for K*alpha or k_*^T * alpha computations
@@ -277,7 +333,10 @@ namespace NICE {
       * @return C standard vector representing a q.size()*n double matrix and the lookup table T. Elements can be accessed with
       * T[dim*q.size() + j], where j is a bin entry corresponding to quantization q.
       */
-      double* hikPrepareLookupTable(const NICE::Vector & alpha, const Quantization & q, const ParameterizedFunction *pf = NULL) const;
+      double* hikPrepareLookupTable(const NICE::Vector & _alpha, 
+                                    const Quantization & _q, 
+                                    const ParameterizedFunction *_pf = NULL
+                                   ) const;
 
       /**
       * @brief update the lookup table for HIK calculation using quantized signals and prepare for K*alpha or k_*^T * alpha computations
@@ -290,7 +349,13 @@ namespace NICE {
       * @param q Quantization
       * @param pf ParameterizedFunction to change the original feature values
       */
-      void hikUpdateLookupTable(double * T, const double & alphaNew, const double & alphaOld, const int & idx, const Quantization & q, const ParameterizedFunction *pf ) const;
+      void hikUpdateLookupTable(double * _T, 
+                                const double & _alphaNew, 
+                                const double & _alphaOld, 
+                                const int & _idx, 
+                                const Quantization & _q, 
+                                const ParameterizedFunction *pf 
+                               ) const;
 
       /**
       * @brief return a reference to the sorted feature matrix
@@ -315,14 +380,23 @@ namespace NICE {
        * @return C standard vector representing a q.size()*n double matrix and the lookup table T. Elements can be accessed with
        * T[dim*q.size() + j], where j is a bin entry corresponding to quantization q.
        **/
-      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;
+      double *solveLin(const NICE::Vector & _y, 
+                       NICE::Vector & _alpha, 
+                       const Quantization & _q, 
+                       const ParameterizedFunction *_pf = NULL, 
+                       const bool & _useRandomSubsets = true, 
+                       uint _maxIterations = 10000, 
+                       const uint & _sizeOfRandomSubset = 0, 
+                       double _minDelta = 1e-7, 
+                       bool _timeAnalysis = false
+                      ) const;
 
 
       //! set the noise parameter
-      void setNoise ( double noise ) { this->noise = noise; }
+      void setNoise ( double _noise ) { this->d_noise = _noise; }
 
       //! get the current noise parameter
-      double getNoise (void) const { return noise; }
+      double getNoise (void) const { return this->d_noise; }
       
       double getFrobNormApprox();
       
@@ -332,7 +406,7 @@ namespace NICE {
       * @author Alexander Freytag
       * @date 10-04-2012 (dd-mm-yyyy)
       */
-      void hikPrepareKVNApproximation(NICE::VVector & A) const;
+      void hikPrepareKVNApproximation(NICE::VVector & _A) const;
       
       /** 
       * @brief  Compute lookup table for HIK calculation of |k_*|^2 assuming quantized test samples. You have to run hikPrepareSquaredKernelVector before
@@ -346,7 +420,7 @@ namespace NICE {
       * @return C standard vector representing a q.size()*d double matrix and the lookup table T. Elements can be accessed with
       * T[dim*q.size() + j], where j is a bin entry corresponding to quantization q.
       */
-      double * hikPrepareKVNApproximationFast(NICE::VVector & A, const Quantization & q, const ParameterizedFunction *pf = NULL ) const;
+      double * hikPrepareKVNApproximationFast(NICE::VVector & _A, const Quantization & _q, const ParameterizedFunction *_pf = NULL ) const;
       
       /**
       * @brief Compute lookup table for HIK calculation of |k_*|^2 assuming quantized test samples ( equals hikPrepareSquaredKernelVector + hikPrepareSquaredKernelVectorFast, but is faster). Approximation does not considere mixed terms between dimensions.
@@ -359,7 +433,7 @@ namespace NICE {
       * @return C standard vector representing a q.size()*d double matrix and the lookup table T. Elements can be accessed with
       * T[dim*q.size() + j], where j is a bin entry corresponding to quantization q.
       */
-      double* hikPrepareLookupTableForKVNApproximation(const Quantization & q, const ParameterizedFunction *pf = NULL) const;
+      double* hikPrepareLookupTableForKVNApproximation(const Quantization & _q, const ParameterizedFunction *_pf = NULL) const;
       
     //////////////////////////////////////////
     // variance computation: sparse inputs
@@ -375,7 +449,7 @@ namespace NICE {
       * @param norm result of the squared norm approximation
       * @param pf optional feature transformation
       */
-      void hikComputeKVNApproximation(const NICE::VVector & A, const NICE::SparseVector & xstar, double & norm, const ParameterizedFunction *pf = NULL ) ;
+      void hikComputeKVNApproximation(const NICE::VVector & _A, const NICE::SparseVector & _xstar, double & _norm, const ParameterizedFunction *_pf = NULL ) ;
       
       /**
       * @brief Approximate norm = |k_*|^2 using a large lookup table created by hikPrepareSquaredKernelVector and hikPrepareSquaredKernelVectorFast or directly using hikPrepareLookupTableForSquaredKernelVector. Approximation does not considere mixed terms between dimensions.
@@ -387,7 +461,7 @@ namespace NICE {
       * @param xstar feature vector (indirect k_*)
       * @param norm result of the calculation
       */
-      void hikComputeKVNApproximationFast(const double *Tlookup, const Quantization & q, const NICE::SparseVector & xstar, double & norm ) const;
+      void hikComputeKVNApproximationFast(const double *_Tlookup, const Quantization & _q, const NICE::SparseVector & _xstar, double & _norm ) const;
 
       /**
       * @brief Compute the kernel vector k_* between training examples and test example. Runtime. O(n \times D). Exploiting sparsity
@@ -397,7 +471,7 @@ namespace NICE {
       * @param xstar feature vector
       * @param kstar kernel vector
       */      
-      void hikComputeKernelVector( const NICE::SparseVector & xstar, NICE::Vector & kstar) const;
+      void hikComputeKernelVector( const NICE::SparseVector & _xstar, NICE::Vector & _kstar) const;
       
     //////////////////////////////////////////
     // variance computation: non-sparse inputs
@@ -413,7 +487,7 @@ namespace NICE {
       * @param norm result of the squared norm approximation
       * @param pf optional feature transformation
       */
-      void hikComputeKVNApproximation(const NICE::VVector & A, const NICE::Vector & xstar, double & norm, const ParameterizedFunction *pf = NULL ) ;
+      void hikComputeKVNApproximation(const NICE::VVector & _A, const NICE::Vector & _xstar, double & _norm, const ParameterizedFunction *_pf = NULL ) ;
       
       /**
       * @brief Approximate norm = |k_*|^2 using a large lookup table created by hikPrepareSquaredKernelVector and hikPrepareSquaredKernelVectorFast or directly using hikPrepareLookupTableForSquaredKernelVector. Approximation does not considere mixed terms between dimensions.
@@ -425,7 +499,7 @@ namespace NICE {
       * @param xstar feature vector (indirect k_*)
       * @param norm result of the calculation
       */
-      void hikComputeKVNApproximationFast(const double *Tlookup, const Quantization & q, const NICE::Vector & xstar, double & norm ) const;      
+      void hikComputeKVNApproximationFast(const double *_Tlookup, const Quantization & _q, const NICE::Vector & _xstar, double & _norm ) const;      
       
       /**
       * @brief Compute the kernel vector k_* between training examples and test example. Runtime. O(n \times D). Does not exploit sparsity - deprecated!
@@ -435,26 +509,26 @@ namespace NICE {
       * @param xstar feature vector
       * @param kstar kernel vector
       */      
-      void hikComputeKernelVector( const NICE::Vector & xstar, NICE::Vector & kstar) const;      
+      void hikComputeKernelVector( const NICE::Vector & _xstar, NICE::Vector & _kstar) const;      
       
       /** Persistent interface */
-      virtual void restore ( std::istream & is, int format = 0 );
-      virtual void store ( std::ostream & os, int format = 0 ) const; 
+      virtual void restore ( std::istream & _is, int _format = 0 );
+      virtual void store ( std::ostream & _os, int _format = 0 ) const; 
       virtual void clear ();
       
     ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
     // interface specific methods for incremental extensions
     ///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
       
-    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
-				    );  
+    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
+                                    );  
     
 
       /**
@@ -464,7 +538,7 @@ namespace NICE {
       *
       * @param example new feature vector
       */       
-      void addExample(const NICE::SparseVector * example, const NICE::ParameterizedFunction *pf = NULL);
+      void addExample(const NICE::SparseVector * _example, const NICE::ParameterizedFunction *_pf = NULL);
       
       /**
       * @brief Add multiple new example to the feature-storage. You have to update the corresponding variables explicitely after that.
@@ -473,7 +547,7 @@ namespace NICE {
       *
       * @param newExamples new feature vectors
       */       
-      void addMultipleExamples(const std::vector<const NICE::SparseVector * > & newExamples, const NICE::ParameterizedFunction *pf = NULL);        
+      void addMultipleExamples(const std::vector<const NICE::SparseVector * > & _newExamples, const NICE::ParameterizedFunction *_pf = NULL);        
       
       
      

+ 112 - 46
FeatureMatrixT.h

@@ -42,14 +42,14 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
 {
 
   protected:
-    int n;
-    int d;
+    uint ui_n;
+    uint ui_d;
     std::vector<NICE::SortedVectorSparse<T> > features;
     
     //! verbose flag for output after calling the restore-function
-    bool verbose;
+    bool b_verbose;
     //! debug flag for output during debugging
-    bool debug;
+    bool b_debug;
 
 
   public:
@@ -85,7 +85,9 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy) 
     */
-    FeatureMatrixT(const std::vector<std::vector<T> > & _features, const int & _dim = -1);
+    FeatureMatrixT(const std::vector<std::vector<T> > & _features, 
+                   const uint & _dim = 0
+                  );
     
 #ifdef NICE_USELIB_MATIO
     /** 
@@ -93,11 +95,16 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @author Alexander Freytag
     * @date 10-01-2012 (dd-mm-yyyy)
     */
-    FeatureMatrixT(const sparse_t & _features, const int & _dim = -1);//, const int & nrFeatures);
+    FeatureMatrixT(const sparse_t & _features, 
+                   const uint & _dim = 0
+                  );//, const int & nrFeatures);
 #endif
 
     /** just another constructor for sparse features */
-    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & X, const bool dimensionsOverExamples = false, const int & _dim = -1);
+    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & _X, 
+                   const bool _dimensionsOverExamples = false, 
+                   const uint & _dim = 0
+                  );
     
 #ifdef NICE_USELIB_MATIO
     /**
@@ -107,7 +114,9 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @param _features sparse data matrix (sett MatFileIO)
     * @param examples set of example indices
     */
-    FeatureMatrixT(const sparse_t & _features, const std::map<int, int> & examples , const int & _dim = -1);
+    FeatureMatrixT(const sparse_t & _features, 
+                   const std::map<int, int> & _examples , 
+                   const uint & _dim = 0);
 #endif
 
     /** 
@@ -126,20 +135,20 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-      int get_n() const;
+      uint get_n() const;
     /** 
     * @brief Get number of dimensions
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-      int get_d() const;
+      uint get_d() const;
       
     /** 
     * @brief Sets the given dimension and re-sizes internal data structure. WARNING: this will completely remove your current data!
     * @author Alexander Freytag
     * @date 06-12-2011 (dd-mm-yyyy)
     */
-      void set_d(const int & _d);
+      void set_d(const uint & _d);
       
     /** set verbose flag used for restore-functionality*/
     void setVerbose( const bool & _verbose);
@@ -158,7 +167,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @param F data to compare with
     * @return true if \c F and \c this are equal
     */
-    inline bool operator==(const FeatureMatrixT<T> & F) const;
+    inline bool operator==(const FeatureMatrixT<T> & _F) const;
     
     /**
     * @brief Compare \c F with \c this.
@@ -168,7 +177,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @param F data to compare with
     * @return true if \c F and \c this are not equal
     */
-    inline bool operator!= (const FeatureMatrixT<T> & F) const;
+    inline bool operator!= (const FeatureMatrixT<T> & _F) const;
 
     /**
     * @brief Copy data from \c F to \c this.
@@ -177,83 +186,113 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @param v New data
     * @return \c *this
     */
-    inline FeatureMatrixT<T>& operator=(const FeatureMatrixT<T> & F);
+    inline FeatureMatrixT<T>& operator=(const FeatureMatrixT<T> & _F);
       
     /** 
     * @brief Matrix-like operator for element access, performs validity check
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-    inline T operator()(const int row, const int col) const;
+    inline T operator()(const int _row, 
+                        const int _col
+                       ) const;
     
     /** 
     * @brief Element access without validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    inline T getUnsafe(const int row, const int col) const;
+    inline T getUnsafe(const int _row,
+                       const int _col
+                      ) const;
 
     /** 
     * @brief Element access of original values without validity check
     * @author Erik Rodner
     */
-    inline T getOriginal(const int row, const int col) const;
+    inline T getOriginal(const int _row,
+                         const int _col
+                        ) const;
 
     /** 
     * @brief Sets a specified element to the given value, performs validity check
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-    inline void set (const int row, const int col, const T & newElement, bool setTransformedValue = false);
+    inline void set (const int _row, 
+                     const int _col, 
+                     const T & _newElement, 
+                     bool _setTransformedValue = false
+                    );
     
     /** 
     * @brief Sets a specified element to the given value, without validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    inline void setUnsafe (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
+                          );
     
     /** 
     * @brief Access to all element entries of a specified dimension, including validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void getDimension(const int & dim, NICE::SortedVectorSparse<T> & dimension) const;
+    void getDimension(const uint & _dim, 
+                      NICE::SortedVectorSparse<T> & _dimension
+                     ) const;
     
     /** 
     * @brief Access to all element entries of a specified dimension, without validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void getDimensionUnsafe(const int & dim, NICE::SortedVectorSparse<T> & dimension) const;
+    void getDimensionUnsafe(const uint & _dim, 
+                            NICE::SortedVectorSparse<T> & _dimension
+                           ) const;
     
     /** 
     * @brief Finds the first element in a given dimension, which equals elem (orig feature value, not the transformed one)
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void findFirstInDimension(const int & dim, const T & elem, int & position) const;
+    void findFirstInDimension(const uint & _dim, 
+                              const T & _elem, 
+                              int & _position
+                             ) const;
     
     /** 
     * @brief Finds the last element in a given dimension, which equals elem (orig feature value, not the transformed one)
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)1
     */
-    void findLastInDimension(const int & dim, const T & elem, int & position) const;
+    void findLastInDimension(const uint & _dim, 
+                             const T & _elem, 
+                             int & _position
+                            ) const;
     
     /** 
     * @brief Finds the first element in a given dimension, which is larger as elem (orig feature value, not the transformed one)
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void findFirstLargerInDimension(const int & dim, const T & elem, int & position) const;
+    void findFirstLargerInDimension(const uint & _dim, 
+                                    const T & elem, 
+                                    int & position
+                                   ) const;
     
     /** 
     * @brief Finds the last element in a given dimension, which is smaller as elem (orig feature value, not the transformed one)
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void findLastSmallerInDimension(const int & dim, const T & elem, int & position) const;
+    void findLastSmallerInDimension(const uint & _dim, 
+                                    const T & _elem, 
+                                    int & _position
+                                   ) const;
     
     //------------------------------------------------------
     // high level methods
@@ -266,7 +305,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     *
     * @param pf the parameterized function (optional), if not given, nothing will be done
     */    
-    void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *pf = NULL );
+    void applyFunctionToFeatureMatrix ( const NICE::ParameterizedFunction *_pf = NULL );
     
     /** 
     * @brief Computes the ratio of sparsity across the matrix
@@ -280,13 +319,17 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-    void add_feature(const std::vector<T> & feature, const NICE::ParameterizedFunction *pf = NULL);
+    void add_feature(const std::vector<T> & _feature, 
+                     const NICE::ParameterizedFunction *_pf = NULL
+                    );
     /** 
     * @brief add a new feature and insert its elements in the already ordered structure, will be casted to type T
     * @author Alexander Freytag
     * @date 25-04-2012 (dd-mm-yyyy)
     */    
-    void add_feature(const NICE::SparseVector & feature, const NICE::ParameterizedFunction *pf = NULL);
+    void add_feature(const NICE::SparseVector & _feature, 
+                     const NICE::ParameterizedFunction *_pf = NULL
+                    );
 
     /** 
     * @brief add several new features and insert their elements in the already ordered structure
@@ -300,53 +343,76 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-    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 set_features(const std::vector<std::vector<T> > & _features, 
+                      std::vector<std::vector<int> > & _permutations, 
+                      const uint & _dim = 0
+                     );
+    void set_features(const std::vector<std::vector<T> > & _features, 
+                      std::vector<std::map<int,int> > & _permutations, 
+                      const uint & _dim = 0
+                     );
+    void set_features(const std::vector<std::vector<T> > & _features, 
+                      const uint & _dim = 0
+                     );
+    void set_features(const std::vector< const NICE::SparseVector * > & _features, 
+                      const bool _dimensionsOverExamples = false, 
+                      const uint & _dim = 0
+                     );
     
     /**
     * @brief get a permutation vector for each dimension
     *
     * @param resulting permutation matrix
     */
-    void getPermutations( std::vector<std::vector<int> > & permutations) const;
-    void getPermutations( std::vector<std::map<int,int> > & permutations) const;
+    void getPermutations( std::vector<std::vector<int> > & _permutations) const;
+    void getPermutations( std::vector<std::map<int,int> > & _permutations) const;
       
     /** 
     * @brief Prints the whole Matrix (outer loop over dimension, inner loop over features)
     * @author Alexander Freytag
     * @date 07-12-2011 (dd-mm-yyyy)
     */
-    void print(std::ostream & os) const;
+    void print(std::ostream & _os) const;
     
     /** 
     * @brief Computes the whole non-sparse matrix. WARNING: this may result in a really memory-consuming data-structure!
     * @author Alexander Freytag
     * @date 12-01-2012 (dd-mm-yyyy)
     */
-    void computeNonSparseMatrix(NICE::MatrixT<T> & matrix, bool transpose = false) const;
+    void computeNonSparseMatrix(NICE::MatrixT<T> & _matrix, 
+                                bool _transpose = false
+                               ) const;
     
     /** 
     * @brief Computes the whole non-sparse matrix. WARNING: this may result in a really memory-consuming data-structure!
     * @author Alexander Freytag
     * @date 12-01-2012 (dd-mm-yyyy)
     */
-    void computeNonSparseMatrix(std::vector<std::vector<T> > & matrix, bool transpose = false) const;
+    void computeNonSparseMatrix(std::vector<std::vector<T> > & _matrix, 
+                                bool _transpose = false
+                               ) const;
     
     /** 
     * @brief Swaps to specified elements, performing a validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void swap(const int & row1, const int & col1, const int & row2, const int & col2);
+    void swap(const int & _row1, 
+              const int & _col1,
+              const int & _row2, 
+              const int & _col2
+             );
     
     /** 
     * @brief Swaps to specified elements, without performing a validity check
     * @author Alexander Freytag
     * @date 08-12-2011 (dd-mm-yyyy)
     */
-    void swapUnsafe(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
+                   );
 
     /**
     * @brief direct access to elements
@@ -355,7 +421,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     *
     * @return sorted feature values
     */
-    const SortedVectorSparse<T> & getFeatureValues ( int dim ) const { return features[dim]; };
+    const SortedVectorSparse<T> & getFeatureValues ( uint _dim ) const { return this->features[_dim]; };
  
     /**
     * @brief direct read/write access to elements
@@ -364,7 +430,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     *
     * @return sorted feature values
     */
-    SortedVectorSparse<T> & getFeatureValues ( int dim ) { return features[dim]; };
+    SortedVectorSparse<T> & getFeatureValues ( uint _dim ) { return this->features[_dim]; };
    
     
     /**
@@ -372,7 +438,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     *
     * @param diagonalElements resulting vector
     */
-    void hikDiagonalElements( Vector & diagonalElements ) const;
+    void hikDiagonalElements( Vector & _diagonalElements ) const;
 
     /**
     * @brief Compute the trace of the HIK kernel matrix induced by the features
@@ -386,18 +452,18 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
     *
     * @return number of nonzero elements on the specified dimension
     */ 
-    int getNumberOfNonZeroElementsPerDimension(const int & dim) const;
+    int getNumberOfNonZeroElementsPerDimension(const uint & _dim) const;
    
     /**
     * @brief Return the number of zero elements in a specified dimension, that are currently stored in the feature matrix
     *
     * @return number of nonzero elements on the specified dimension
     */ 
-    int getNumberOfZeroElementsPerDimension(const int & dim) const;
+    int getNumberOfZeroElementsPerDimension(const uint & _dim) const;
     
     /** Persistent interface */
-    virtual void restore ( std::istream & is, int format = 0 );
-    virtual void store ( std::ostream & os, int format = 0 ) const;
+    virtual void restore ( std::istream & _is, int _format = 0 );
+    virtual void store ( std::ostream & _os, int _format = 0 ) const;
     virtual void clear ( );
 
 };

File diff suppressed because it is too large
+ 338 - 258
FeatureMatrixT.tcc


+ 1 - 0
Quantization.cpp

@@ -32,6 +32,7 @@ uint Quantization::size() const
   
 double Quantization::getPrototype (uint bin) const
 {
+//   std::cerr << bin / (double)(numBins-1) << std::endl;
   return bin / (double)(numBins-1);
 }
   

+ 78 - 71
SortedVectorSparse.h

@@ -35,17 +35,17 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
 
   public:
     //! original index, transformed feature value
-    typedef typename std::pair< int, T > dataelement;
+    typedef typename std::pair< uint, T > dataelement;
     typedef typename std::multimap< T, dataelement >::iterator elementpointer;
     typedef typename std::multimap< T, dataelement >::const_iterator const_elementpointer;
     typedef typename std::multimap< T, dataelement >::const_reverse_iterator const_reverse_elementpointer;
 
   protected:
     T tolerance;
-    int n;
+    uint ui_n;
     
-    //! verbose flag for output after calling the restore-function
-    bool verbose;
+    //! b_verbose flag for output after calling the restore-function
+    bool b_verbose;
 
     //! mapping of the original feature value to the index and the transformed feature value
     std::multimap< T, dataelement > nzData;
@@ -60,9 +60,9 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @date 10-01-2012 (dd-mm-yyyy)
     */
     SortedVectorSparse() {
-      n = 0;
-      tolerance = ( T ) 10e-10;
-      verbose = false;
+      this->ui_n = 0;
+      this->tolerance = ( T ) 10e-10;
+      this->b_verbose = false;
     }
 
     /**
@@ -70,20 +70,20 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @author Alexander Freytag
     * @date 10-01-2012 (dd-mm-yyyy)
     */
-    SortedVectorSparse ( const SortedVectorSparse<T> &v ) : nzData ( v.nzData )
+    SortedVectorSparse ( const SortedVectorSparse<T> &_v ) : nzData ( _v.nzData )
     {
-      this->tolerance = v.getTolerance();
-      this->n = v.getN();
-      this->nonzero_indices = v.nonzero_indices;
-      this->verbose = v.getVerbose();      
+      this->tolerance = _v.getTolerance();
+      this->ui_n = _v.getN();
+      this->nonzero_indices = _v.nonzero_indices;
+      this->b_verbose = _v.getVerbose();      
     }
 
-    SortedVectorSparse ( const std::vector<T> &v, const T & _tolerance )
+    SortedVectorSparse ( const std::vector<T> &_v, const T & _tolerance )
     {
-      tolerance = _tolerance;
-      n = 0;
-      insert ( v );
-      verbose = false;
+      this->tolerance = _tolerance;
+      this->ui_n = 0;
+      this->insert ( _v );
+      this->b_verbose = false;
     }
 
     /**
@@ -94,10 +94,10 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     ~SortedVectorSparse() {}
 
     T getTolerance() const {
-      return tolerance;
+      return this->tolerance;
     };
-    int getN() const {
-      return n;
+    uint getN() const {
+      return this->ui_n;
     };
     void setTolerance ( const T & _tolerance ) {
       if ( _tolerance < 0 )
@@ -107,15 +107,15 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     };
 
 
-    void setN ( const int & _n ) {
-      n = _n;
+    void setN ( const uint & _n ) {
+      this->ui_n = _n;
     };
-    int getZeros() const {
+    uint getZeros() const {
       //std::cerr << "n in getZeros: " << n << std::endl;
-      return n - nzData.size();
+      return this->ui_n - this->nzData.size();
     };
-    int getNonZeros() const {
-      return nzData.size();
+    uint getNonZeros() const {
+      return this->nzData.size();
     };
 
     /**
@@ -124,20 +124,22 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @param newElement element which will be added
     * @param featureNumber the index of the new element (optional)
     */
-    void insert ( const T & newElement, const int & featureNumber = -1 )
+    void insert ( const T & _newElement, 
+                  const uint & _featureNumber = 0
+                )
     {
-      int newIndex ( featureNumber);
-      if ( featureNumber < 0)
-        newIndex = n;      
+      int newIndex ( _featureNumber);
+      if ( _featureNumber < 0)
+        newIndex = this->ui_n;      
       
-      if ( !checkSparsity ( newElement ) )
+      if ( !checkSparsity ( _newElement ) )
       {
         // element is not sparse
-        std::pair<T, dataelement > p ( newElement, dataelement ( newIndex, newElement ) );
-        elementpointer it = nzData.insert ( p );
-        nonzero_indices.insert ( std::pair<int, elementpointer> ( newIndex, it ) );
+        std::pair<T, dataelement > p ( _newElement, dataelement ( newIndex, _newElement ) );
+        elementpointer it = this->nzData.insert ( p );
+        this->nonzero_indices.insert ( std::pair<int, elementpointer> ( newIndex, it ) );
       }
-      n++;
+      this->ui_n++;
     }
   
     /**
@@ -147,21 +149,24 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @param newElementTransformed transformed feature value
     * @param featureNumber the index of the new element (optional)
     */
-    void insert ( const T & newElement, const T & newElementTransformed, const int & featureNumber = -1 )
+    void insert ( const T & _newElement, 
+                  const T & _newElementTransformed, 
+                  const uint & _featureNumber = 0 
+                )
     {
-      int newIndex ( featureNumber);
-      if ( featureNumber < 0)
-        newIndex = n;
+      int newIndex ( _featureNumber);
+      if ( _featureNumber < 0)
+        newIndex = this->ui_n;
       
-      if ( !checkSparsity ( newElement ) )
+      if ( !checkSparsity ( _newElement ) )
       {
         // element is not sparse
         
-        std::pair<T, dataelement > p ( newElement, dataelement ( newIndex, newElementTransformed ) );
-        elementpointer it = nzData.insert ( p );
-        nonzero_indices.insert ( std::pair<int, elementpointer> ( newIndex, it ) );
+        std::pair<T, dataelement > p ( _newElement, dataelement ( newIndex,_newElementTransformed ) );
+        elementpointer it = this->nzData.insert ( p );
+        this->nonzero_indices.insert ( std::pair<int, elementpointer> ( newIndex, it ) );
       }
-      n++;
+      this->ui_n++;
     }
 
     /**
@@ -169,21 +174,21 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @param v new element which will be added
     */
-    void insert ( const std::vector<T> &v )
+    void insert ( const std::vector<T> &_v )
     {
-      for ( uint i = 0; i < v.size(); i++ )
-        insert ( v[i] );
+      for ( uint i = 0; i < _v.size(); i++ )
+        this->insert ( _v[i] );
     }
     /**
     * @brief add a vector of new elements to the vector. It doesn't make much sense to have such a function, but who knows...
     *
     * @param v Vector of new Elements
     */
-    void insert ( const NICE::SparseVector* v )
+    void insert ( const NICE::SparseVector* _v )
     {
-      for (NICE::SparseVector::const_iterator vIt = v->begin(); vIt != v->end(); vIt++)
+      for (NICE::SparseVector::const_iterator vIt = _v->begin(); vIt != _v->end(); vIt++)
       {
-        insert((T)vIt->second);
+        this->insert((T)vIt->second);
       }
     }
     
@@ -194,10 +199,10 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @return value of the element (not the original value)
     */
-    T accessNonZero ( int a ) const
+    T accessNonZero ( uint _a ) const
     {
-      const_elementpointer it = nzData.begin();
-      advance ( it, a );
+      const_elementpointer it = this->nzData.begin();
+      advance ( it, _a );
       dataelement de = it->second;
 
       return de.second;
@@ -210,10 +215,10 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @return value of the element
     */
-    inline T access ( int a ) const
+    inline T access ( int _a ) const
     {
-      typename std::map<int, elementpointer>::const_iterator i = nonzero_indices.find ( a );
-      if ( i != nonzero_indices.end() ) {
+      typename std::map<uint, elementpointer>::const_iterator i = this->nonzero_indices.find ( _a );
+      if ( i != this->nonzero_indices.end() ) {
         // accessing a nonzero element
         const elementpointer & it = i->second;
         const dataelement & de = it->second;
@@ -233,10 +238,10 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @return value of the element
     */
-    inline T accessOriginal ( int a ) const
+    inline T accessOriginal ( uint _a ) const
     {
-      typename std::map<int, elementpointer>::const_iterator i = nonzero_indices.find ( a );
-      if ( i != nonzero_indices.end() ) {
+      typename std::map<uint, elementpointer>::const_iterator i = this->nonzero_indices.find ( _a );
+      if ( i != this->nonzero_indices.end() ) {
         // accessing a nonzero element
         elementpointer it = i->second;
         return it->first;
@@ -248,17 +253,17 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
 
     std::multimap< T, dataelement > & nonzeroElements()
     {
-      return nzData;
+      return this->nzData;
     }
 
     const std::multimap< T, dataelement > & nonzeroElements() const
     {
-      return nzData;
+      return this->nzData;
     }
 
-    const std::map< int, elementpointer> & nonzeroIndices() const
+    const std::map< uint, elementpointer> & nonzeroIndices() const
     {
-      return nonzero_indices;
+      return this->nonzero_indices;
     }
 
     /**
@@ -268,11 +273,11 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @return
     */
-    bool checkSparsity ( T element )
+    bool checkSparsity ( T _element )
     {
-      if ( element > tolerance )
+      if ( _element > this->tolerance )
         return false;
-      if ( element < -tolerance )
+      if ( _element < -this->tolerance )
         return false;
 
       return true;
@@ -287,9 +292,11 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @param a proper index
     * @param newElement element value
     */
-    void set ( int a, T newElement, bool setTransformedValue = false )
+    void set ( uint _a, 
+               T _newElement, 
+               bool _setTransformedValue = false )
     {
-      if ( a >= n || a < 0 )
+      if ( _a >= this->ui_n || a < 0 )
         fthrow ( Exception, "SortedVectorSparse::set(): out of bounds" );
 
       typename std::map<int, elementpointer>::iterator i = nonzero_indices.find ( a );
@@ -583,9 +590,9 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
       }
     }
     
-    /** set verbose flag used for restore-functionality*/
-    void setVerbose( const bool & _verbose) { verbose = _verbose;};
-    bool getVerbose( ) const { return verbose;};
+    /** set b_verbose flag used for restore-functionality*/
+    void setVerbose( const bool & _b_verbose) { b_verbose = _b_verbose;};
+    bool getVerbose( ) const { return b_verbose;};
     
     
     /** Persistent interface */

Some files were not shown because too many files changed in this diff