Bläddra i källkod

MATIO bugfixes

Erik Rodner 9 år sedan
förälder
incheckning
6e514f8b0d
3 ändrade filer med 187 tillägg och 187 borttagningar
  1. 68 68
      FastMinKernel.cpp
  2. 15 15
      FeatureMatrixT.tcc
  3. 104 104
      SortedVectorSparse.h

+ 68 - 68
FastMinKernel.cpp

@@ -59,7 +59,7 @@ FastMinKernel::FastMinKernel ( const sparse_t & _X,
                                const std::map<uint, uint> & _examples,
                                const bool _debug,
                                const uint & _dim
-                             ) : this->X_sorted( _X, _examples, _dim )
+                             ) : X_sorted( _X, _examples, _dim )
 {
   this->ui_d         = this->X_sorted.get_d();
   this->ui_n         = this->X_sorted.get_n();
@@ -230,7 +230,7 @@ void FastMinKernel::hik_prepare_alpha_multiplications(const NICE::Vector & _alph
 double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVector & _A,
                                                               const NICE::VVector & _B,
                                                               const Quantization * _q,
-                                                              const ParameterizedFunction *_pf 
+                                                              const ParameterizedFunction *_pf
                                                              ) const
 {
   //NOTE keep in mind: for doing this, we already have precomputed A and B using hik_prepare_alpha_multiplications!
@@ -242,7 +242,7 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
   double * prototypes   = new double [ hmax * this->ui_d ];
   double * p_prototypes = prototypes;
 
-  for (uint dim = 0; dim < this->ui_d; dim++)  
+  for (uint dim = 0; dim < this->ui_d; dim++)
   {
     for ( uint i = 0 ; i < hmax ; i++ )
     {
@@ -253,11 +253,11 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
       {
         *p_prototypes = _q->getPrototype( i, dim );
       }
-      
+
       p_prototypes++;
     }
-  } 
-  
+  }
+
   // creating the lookup table as pure C, which might be beneficial
   // for fast evaluation
   double *Tlookup = new double [ hmax * this->ui_d ];
@@ -281,7 +281,7 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
     uint index = 0;
     // we use the quantization of the original features! the transformed feature were
     // already used to calculate A and B, this of course assumes monotonic functions!!!
-    uint qBin = _q->quantize ( i->first, dim ); 
+    uint qBin = _q->quantize ( i->first, dim );
 
     // the next loop is linear in max(hmax, n)
     // REMARK: this could be changed to hmax*log(n), when
@@ -331,9 +331,9 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
   return Tlookup;
 }
 
-double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha, 
-                                             const Quantization * _q, 
-                                             const ParameterizedFunction *_pf 
+double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
+                                             const Quantization * _q,
+                                             const ParameterizedFunction *_pf
                                             ) const
 {
   // number of quantization bins
@@ -343,7 +343,7 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
   double * prototypes   = new double [ hmax * this->ui_d ];
   double * p_prototypes = prototypes;
 
-  for (uint dim = 0; dim < this->ui_d; dim++)  
+  for (uint dim = 0; dim < this->ui_d; dim++)
   {
     for ( uint i = 0 ; i < hmax ; i++ )
     {
@@ -354,7 +354,7 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
       {
         *p_prototypes = _q->getPrototype( i, dim );
       }
-      
+
       p_prototypes++;
     }
   }
@@ -388,8 +388,8 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
     uint index = 0;
 
     // we use the quantization of the original features! Nevetheless, the resulting lookupTable is computed using the transformed ones
-    uint qBin = _q->quantize ( i->first, dim ); 
-    
+    uint qBin = _q->quantize ( i->first, dim );
+
     double alpha_sum(0.0);
     double alpha_times_x_sum(0.0);
     double alpha_sum_prev(0.0);
@@ -447,12 +447,12 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
 }
 
 
-void FastMinKernel::hikUpdateLookupTable(double * _T, 
-                                         const double & _alphaNew, 
-                                         const double & _alphaOld, 
-                                         const uint & _idx, 
-                                         const Quantization * _q, 
-                                         const ParameterizedFunction *_pf 
+void FastMinKernel::hikUpdateLookupTable(double * _T,
+                                         const double & _alphaNew,
+                                         const double & _alphaOld,
+                                         const uint & _idx,
+                                         const Quantization * _q,
+                                         const ParameterizedFunction *_pf
                                         ) const
 {
 
@@ -469,7 +469,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
   double * prototypes   = new double [ hmax * this->ui_d ];
   double * p_prototypes = prototypes;
 
-  for (uint dim = 0; dim < this->ui_d; dim++)  
+  for (uint dim = 0; dim < this->ui_d; dim++)
   {
     for ( uint i = 0 ; i < hmax ; i++ )
     {
@@ -480,11 +480,11 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
       {
         *p_prototypes = _q->getPrototype( i, dim );
       }
-      
+
       p_prototypes++;
     }
   }
-  
+
   double diffOfAlpha(_alphaNew - _alphaOld);
 
   // loop through all dimensions
@@ -501,7 +501,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
     {
         double fval;
         uint q_bin = _q->quantize( x_i, dim );
-        
+
         if ( q_bin > j )
           fval = prototypes[ dim*hmax + j ];
         else
@@ -583,9 +583,9 @@ void FastMinKernel::hik_kernel_multiply(const NICE::VVector & _A,
   }
 }
 
-void FastMinKernel::hik_kernel_multiply_fast(const double *_Tlookup, 
-                                             const Quantization * _q, 
-                                             const NICE::Vector & _alpha, 
+void FastMinKernel::hik_kernel_multiply_fast(const double *_Tlookup,
+                                             const Quantization * _q,
+                                             const NICE::Vector & _alpha,
                                              NICE::Vector & _beta) const
 {
   _beta.resize( this->ui_n );
@@ -760,9 +760,9 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
   }
 }
 
-void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup, 
-                                        const Quantization * _q, 
-                                        const NICE::Vector & _xstar, 
+void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
+                                        const Quantization * _q,
+                                        const NICE::Vector & _xstar,
                                         double & _beta
                                        ) const
 {
@@ -778,14 +778,14 @@ void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
   {
     double v = _xstar[dim];
     uint qBin = _q->quantize( v, dim );
-    
+
     _beta += _Tlookup[dim*_q->getNumberOfBins() + qBin];
   }
 }
 
-void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup, 
-                                        const Quantization * _q, 
-                                        const NICE::SparseVector & _xstar, 
+void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
+                                        const Quantization * _q,
+                                        const NICE::SparseVector & _xstar,
                                         double & _beta
                                        ) const
 {
@@ -799,19 +799,19 @@ void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
     uint dim = i->first;
     double v = i->second;
     uint qBin = _q->quantize( v, dim );
-    
+
     _beta += _Tlookup[dim*_q->getNumberOfBins() + qBin];
   }
 }
 
 double *FastMinKernel::solveLin(const NICE::Vector & _y,
                                 NICE::Vector & _alpha,
-                                const Quantization * _q, 
-                                const ParameterizedFunction *_pf, 
-                                const bool & _useRandomSubsets, 
-                                uint _maxIterations, 
-                                const uint & _sizeOfRandomSubset, 
-                                double _minDelta, 
+                                const Quantization * _q,
+                                const ParameterizedFunction *_pf,
+                                const bool & _useRandomSubsets,
+                                uint _maxIterations,
+                                const uint & _sizeOfRandomSubset,
+                                double _minDelta,
                                 bool _timeAnalysis
                                ) const
 {
@@ -826,7 +826,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
 
   // number of quantization bins
   uint hmax = _q->getNumberOfBins();
-  
+
   NICE::Vector diagonalElements(_y.size(),0.0);
   this->X_sorted.hikDiagonalElements(diagonalElements);
   diagonalElements += this->d_noise;
@@ -1151,8 +1151,8 @@ void FastMinKernel::hikPrepareKVNApproximation(NICE::VVector & _A) const
   }
 }
 
-double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A, 
-                                                       const Quantization * _q, 
+double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
+                                                       const Quantization * _q,
                                                        const ParameterizedFunction *_pf ) const
 {
   //NOTE keep in mind: for doing this, we already have precomputed A using hikPrepareSquaredKernelVector!
@@ -1163,8 +1163,8 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
   // store (transformed) prototypes
   double *prototypes = new double [ hmax * this->ui_d ];
   double * p_prototypes = prototypes;
-  
-  for (uint dim = 0; dim < this->ui_d; dim++)  
+
+  for (uint dim = 0; dim < this->ui_d; dim++)
   {
     for ( uint i = 0 ; i < hmax ; i++ )
     {
@@ -1175,7 +1175,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
       {
         *p_prototypes = _q->getPrototype( i, dim );
       }
-      
+
       p_prototypes++;
     }
   }
@@ -1201,7 +1201,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
     uint index = 0;
     // we use the quantization of the original features! the transformed feature were
     // already used to calculate A and B, this of course assumes monotonic functions!!!
-    uint qBin = _q->quantize ( i->first, dim ); 
+    uint qBin = _q->quantize ( i->first, dim );
 
     // the next loop is linear in max(hmax, n)
     // REMARK: this could be changed to hmax*log(n), when
@@ -1238,7 +1238,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
           t = _A[dim][index];
         } else {
           // standard case
-          t =  _A[dim][index-1] + pow( fval, 2 ) * (this->ui_n-nrZeroIndices-(index) );          
+          t =  _A[dim][index-1] + pow( fval, 2 ) * (this->ui_n-nrZeroIndices-(index) );
         }
       }
 
@@ -1252,7 +1252,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
 }
 
 double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantization * _q,
-                                                                const ParameterizedFunction *_pf 
+                                                                const ParameterizedFunction *_pf
                                                                ) const
 {
   // number of quantization bins
@@ -1262,7 +1262,7 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
   double *prototypes = new double [ hmax * this->ui_d ];
   double * p_prototypes = prototypes;
 
-  for (uint dim = 0; dim < this->ui_d; dim++)  
+  for (uint dim = 0; dim < this->ui_d; dim++)
   {
     for ( uint i = 0 ; i < hmax ; i++ )
     {
@@ -1273,10 +1273,10 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
       {
         *p_prototypes = _q->getPrototype( i, dim );
       }
-      
+
       p_prototypes++;
     }
-  }    
+  }
 
   // creating the lookup table as pure C, which might be beneficial
   // for fast evaluation
@@ -1298,7 +1298,7 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
     uint index = 0;
 
     // we use the quantization of the original features! Nevetheless, the resulting lookupTable is computed using the transformed ones
-    uint qBin = _q->quantize ( i->first, dim ); 
+    uint qBin = _q->quantize ( i->first, dim );
 
     double sum(0.0);
 
@@ -1409,9 +1409,9 @@ void FastMinKernel::hikComputeKVNApproximation(const NICE::VVector & _A,
   }
 }
 
-void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup, 
-                                                   const Quantization * _q, 
-                                                   const NICE::SparseVector & _xstar, 
+void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
+                                                   const Quantization * _q,
+                                                   const NICE::SparseVector & _xstar,
                                                    double & _norm
                                                   ) const
 {
@@ -1421,12 +1421,12 @@ void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
   {
     uint dim = i->first;
     double v = i->second;
-    // we do not need a parameterized function here, since the quantizer works on the original feature values. 
-    // nonetheless, the lookup table was created using the parameterized function    
+    // we do not need a parameterized function here, since the quantizer works on the original feature values.
+    // nonetheless, the lookup table was created using the parameterized function
     uint qBin = _q->quantize( v, dim );
-    
+
     _norm += _Tlookup[dim*_q->getNumberOfBins() + qBin];
-  }  
+  }
 }
 
 void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
@@ -1552,9 +1552,9 @@ void FastMinKernel::hikComputeKVNApproximation(const NICE::VVector & _A,
   }
 }
 
-void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup, 
-                                                   const Quantization * _q, 
-                                                   const NICE::Vector & _xstar, 
+void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
+                                                   const Quantization * _q,
+                                                   const NICE::Vector & _xstar,
                                                    double & _norm
                                                   ) const
 {
@@ -1564,12 +1564,12 @@ void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
   for ( NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++ )
   {
     double v = *i;
-    // we do not need a parameterized function here, since the quantizer works on the original feature values. 
-    // nonetheless, the lookup table was created using the parameterized function    
+    // we do not need a parameterized function here, since the quantizer works on the original feature values.
+    // nonetheless, the lookup table was created using the parameterized function
     uint qBin = _q->quantize( v, dim );
-    
+
     _norm += _Tlookup[dim*_q->getNumberOfBins() + qBin];
-  }  
+  }
 }
 
 

+ 15 - 15
FeatureMatrixT.tcc

@@ -124,7 +124,7 @@ namespace NICE {
       {
         for ( uint j = _features.jc[i]; j < _features.jc[i+1] && j < _features.ndata; j++ ) //walk over single features, which are sparsely represented
         {
-          this->features[i].insert(((T*)_features.data)[j], _features.ir[ j]);
+          this->features[i].insert(((T*)_features.data)[j], true /* specify feature number */, _features.ir[ j]);
           if ((_features.ir[ j])>nMax)
             nMax = _features.ir[ j];
         }
@@ -156,9 +156,9 @@ namespace NICE {
         for ( uint j = _features.jc[i]; j < _features.jc[i+1] && j < _features.ndata; j++ ) //walk over single features, which are sparsely represented
         {
           uint example_index = _features.ir[ j];
-          std::map<uint, uint>::const_iterator it = examples.find(example_index);
-          if ( it != examples.end() ) {
-            this->features[i].insert(((T*)_features.data)[j], it->second /* new index */);
+          std::map<uint, uint>::const_iterator it = _examples.find(example_index);
+          if ( it != _examples.end() ) {
+            this->features[i].insert(((T*)_features.data)[j], true /* specify feature number */, it->second /* new index */);
             if (it->second > nMax)
               nMax = it->second;
           }
@@ -489,13 +489,13 @@ namespace NICE {
       if ( it->first > this->features[_dim].getTolerance() )
         _position += this->features[_dim].getZeros();
     }
-    
+
     template <typename T>
     T FeatureMatrixT<T>::getLargestValue ( const bool & _getTransformedValue ) const
     {
-      T vmax = (T) 0; 
+      T vmax = (T) 0;
       T vtmp = (T) 0;
-      
+
       uint tmp ( 0 );
       for ( typename std::vector<NICE::SortedVectorSparse<T> >::const_iterator it = this->features.begin();
             it != this->features.end();
@@ -510,26 +510,26 @@ namespace NICE {
       }
       return vmax;
     }
-    
+
     template <typename T>
-    NICE::VectorT<T> FeatureMatrixT<T>::getLargestValuePerDimension ( const double & _quantile, 
+    NICE::VectorT<T> FeatureMatrixT<T>::getLargestValuePerDimension ( const double & _quantile,
                                                                       const bool & _getTransformedValue
-                                                                    ) const     
+                                                                    ) const
     {
       NICE::VectorT<T> vmax ( this->get_d() );
-      
-      uint tmp ( 0 );      
+
+      uint tmp ( 0 );
       typename NICE::VectorT<T>::iterator vmaxIt = vmax.begin();
       for ( typename std::vector<NICE::SortedVectorSparse<T> >::const_iterator it = this->features.begin();
             it != this->features.end();
             it++, vmaxIt++, tmp++
       )
-      {       
+      {
         *vmaxIt = it->getLargestValueUnsafe( _quantile, _getTransformedValue );
-      }    
+      }
       return vmax;
     }
-    
+
     //------------------------------------------------------
     // high level methods
     //------------------------------------------------------

+ 104 - 104
SortedVectorSparse.h

@@ -18,19 +18,19 @@
 // NICE-core includes
 #include <core/basics/Exception.h>
 #include <core/basics/Persistent.h>
-// 
+//
 #include <core/vector/VectorT.h>
 #include <core/vector/SparseVectorT.h>
 
 
 namespace NICE {
 
- /** 
+ /**
  * @class SortedVectorSparse
  * @brief A sparse vector that is always sorted and keeps index mapping!
  * @author Alexander Freytag
- */  
-  
+ */
+
 template<class T> class SortedVectorSparse : NICE::Persistent{
 
   public:
@@ -43,7 +43,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
   protected:
     T tolerance;
     uint ui_n;
-    
+
     //! b_verbose flag for output after calling the restore-function
     bool b_verbose;
 
@@ -75,7 +75,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
       this->tolerance = _v.getTolerance();
       this->ui_n = _v.getN();
       this->nonzero_indices = _v.nonzero_indices;
-      this->b_verbose = _v.getVerbose();      
+      this->b_verbose = _v.getVerbose();
     }
 
     SortedVectorSparse ( const std::vector<T> &_v, const T & _tolerance )
@@ -125,16 +125,16 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @param _specifyFeatureNumber specify whether to use the optinally given index
     * @param _featureNumber the index of the new element (optional)
     */
-    void insert ( const T & _newElement, 
+    void insert ( const T & _newElement,
                   const bool _specifyFeatureNumber = false,
                   const uint & _featureNumber = 0
                 )
     {
-      
+
       uint newIndex ( this->ui_n );
       if ( _specifyFeatureNumber )
         newIndex = _featureNumber;
-      
+
       if ( !checkSparsity ( _newElement ) )
       {
         // element is not sparse
@@ -144,29 +144,29 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
       }
       this->ui_n++;
     }
-  
+
     /**
     * @brief add an element to the vector. If feature number is set, we do not check, wether this feature was already available or not!
     *
     * @param newElement element which will be added
     * @param newElementTransformed transformed feature value
-    * @param _specifyFeatureNumber specify whether to use the optinally given index* 
+    * @param _specifyFeatureNumber specify whether to use the optinally given index*
     * @param featureNumber the index of the new element (optional)
     */
-    void insert ( const T & _newElement, 
-                  const T & _newElementTransformed, 
-                  const bool _specifyFeatureNumber = false,                  
-                  const uint & _featureNumber = 0 
+    void insert ( const T & _newElement,
+                  const T & _newElementTransformed,
+                  const bool _specifyFeatureNumber = false,
+                  const uint & _featureNumber = 0
                 )
     {
       uint newIndex ( this->ui_n );
       if ( _specifyFeatureNumber )
         newIndex = _featureNumber;
-      
+
       if ( !checkSparsity ( _newElement ) )
       {
         // element is not sparse
-        
+
         std::pair<T, dataelement > p ( _newElement, dataelement ( newIndex,_newElementTransformed ) );
         elementpointer it = this->nzData.insert ( p );
         this->nonzero_indices.insert ( std::pair<uint, elementpointer> ( newIndex, it ) );
@@ -175,7 +175,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     }
 
     /**
-    * @brief add a vector of new elements to the vector 
+    * @brief add a vector of new elements to the vector
     *
     * @param v new element which will be added
     */
@@ -196,7 +196,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         this->insert((T)vIt->second);
       }
     }
-    
+
     /**
     * @brief non-efficient access to a specific non-zero element
     *
@@ -255,8 +255,8 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         return ( T ) 0;
       }
     }
-    
-    inline T getLargestValueUnsafe ( const double & _quantile = 1.0, 
+
+    inline T getLargestValueUnsafe ( const double & _quantile = 1.0,
                                      const bool & _getTransformedValue = false
                                    ) const
     {
@@ -264,19 +264,19 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
       {
         return  0.0;
       }
-      
+
         uint idxDest ( round ( (this->getNonZeros() - 1) * _quantile)  );
-        
+
         if ( _quantile > 0.5 )
         {
           typename std::multimap< T, dataelement >::const_reverse_iterator it = this->nzData.rend();
-          
+
           //
           // take as many backward steps as indicated by _quantile
           for ( uint idx = this->getNonZeros(); idx > idxDest; idx-- )
           {
             it++;
-          }          
+          }
           // alternative usage for random access iterators:
           // it = it + (uint) this->getNonZeros() * ( 1.0 -  _quantile );
 
@@ -288,57 +288,57 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         else
         {
           typename std::multimap< T, dataelement >::const_iterator it = this->nzData.begin();
-          
+
           // take as many steps forward as indicated by _quantile
           for ( uint idx = 0; idx < idxDest; idx++ )
           {
             it++;
           }
           // alternative usage for random access iterators:
-          // it = it + (uint) this->getNonZeros() * _quantile;  
-          
+          // it = it + (uint) this->getNonZeros() * _quantile;
+
           if ( _getTransformedValue )
             return it->second.second;
           else
             return it->first;
         }
-    }    
-    
+    }
+
     inline T getLargestTransformedValueUnsafe ( const double & _quantile = 1.0 ) const
     {
         uint idxDest ( round ( (this->getNonZeros() - 1) * _quantile )  );
-        
+
         if ( _quantile > 0.5 )
         {
           typename std::multimap< T, dataelement >::const_reverse_iterator it = this->nzData.rend();
-          
+
           //
           // take as many backward steps as indicated by _quantile
           for ( uint idx = this->getNonZeros(); idx > idxDest; idx-- )
           {
             it++;
-          }          
+          }
           // alternative usage for random access iterators:
           // it = it + (uint) this->getNonZeros() * ( 1.0 -  _quantile );
-     
+
           return it->second.second;
         }
         else
         {
           typename std::multimap< T, dataelement >::const_iterator it = this->nzData.begin();
-          
+
           // take as many steps forward as indicated by _quantile
           for ( uint idx = 0; idx < idxDest; idx++ )
           {
             it++;
           }
           // alternative usage for random access iterators:
-          // it = it + (uint) this->getNonZeros() * _quantile;  
-          
+          // it = it + (uint) this->getNonZeros() * _quantile;
+
           return it->second.second;
         }
     }
-      
+
     std::multimap< T, dataelement > & nonzeroElements()
     {
       return this->nzData;
@@ -380,8 +380,8 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     * @param a proper index
     * @param newElement element value
     */
-    void set ( uint _a, 
-               T _newElement, 
+    void set ( uint _a,
+               T _newElement,
                bool _setTransformedValue = false )
     {
       if ( _a >= this->ui_n || _a < 0 )
@@ -562,14 +562,14 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     */
     T getMedian() const
     {
-      if ( this->ui_n % 2 == 1 ) 
+      if ( this->ui_n % 2 == 1 )
       {
         // even number of training examples
         uint medianPosition = this->nzData.size() - this->ui_n/2;
         if ( medianPosition < 0 ) //FIXME not possible with uint anymore
           return 0.0;
         else
-          return this->accessNonZero(medianPosition); 
+          return this->accessNonZero(medianPosition);
       } else {
         // odd number of training examples
         uint medianA = this->nzData.size() - this->ui_n/2;
@@ -583,7 +583,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         return (a + b)/2.0;
       }
     }
-    
+
     /**
     * @brief get the maximum of the vector including zero elements
     *
@@ -595,7 +595,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         return this->accessNonZero( this->nzData.size()-1 );
       return (T) 0.0;
     }
-    
+
     /**
     * @brief get the minimum of the vector including zero elements
     *
@@ -607,22 +607,22 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         return (T) 0.0;
       return this->accessNonZero(0);
     }
-    
-    
+
+
 
     /**
     * @brief get median feature values for each class seperately, we do not apply averaging when the number
     * of examples is even
     *
-    * @param classMedians resulting sparse vector, i.e. classMedians[classno] is the median value 
+    * @param classMedians resulting sparse vector, i.e. classMedians[classno] is the median value
     * of every example of class classno
     * @param labels vector of labels with the same size n as the current vector
     * @param elementCounts this vector contains the number of examples for each class, compute this using the labels
     * for efficiency reasons
     */
-    void getClassMedians ( SparseVector & _classMedians, 
-                           const Vector & _labels, 
-                           const Vector & _elementCounts 
+    void getClassMedians ( SparseVector & _classMedians,
+                           const Vector & _labels,
+                           const Vector & _elementCounts
                          ) const
     {
       if ( _labels.size() != this->ui_n )
@@ -669,7 +669,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
             break;
         }
 
-        for ( int i = 0; i < this->getZer_os(); i++ )
+        for ( int i = 0; i < this->getZeros(); i++ )
         {
           _os << ( T ) 0.0 << " " ;
         }
@@ -681,67 +681,67 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         _os << std::endl;
       }
     }
-    
+
     /** set b_verbose flag used for restore-functionality*/
     void setVerbose( const bool & _verbose) { this->b_verbose = _verbose;};
     bool getVerbose( ) const { return this->b_verbose;};
-    
-    
+
+
     /** Persistent interface */
-    virtual void restore ( std::istream & _is, 
-                           int _format = 0 
+    virtual void restore ( std::istream & _is,
+                           int _format = 0
                          )
     {
       bool b_restoreVerbose ( false );
       if ( _is.good() )
       {
-        if ( b_restoreVerbose ) 
+        if ( b_restoreVerbose )
           std::cerr << " restore SortedVectorSparse" << std::endl;
-        
+
         std::string tmp;
-        _is >> tmp; //class name 
-        
+        _is >> tmp; //class name
+
         if ( ! this->isStartTag( tmp, "SortedVectorSparse" ) )
         {
             std::cerr << " WARNING - attempt to restore SortedVectorSparse, but start flag " << tmp << " does not match! Aborting... " << std::endl;
             throw;
-        }   
-            
+        }
+
         _is.precision ( std::numeric_limits<double>::digits10 + 1);
-        
+
         bool b_endOfBlock ( false ) ;
-        
+
         while ( !b_endOfBlock )
         {
-          _is >> tmp; // start of block 
-          
+          _is >> tmp; // start of block
+
           if ( this->isEndTag( tmp, "SortedVectorSparse" ) )
           {
             b_endOfBlock = true;
             continue;
-          }      
-          
+          }
+
           tmp = this->removeStartTag ( tmp );
-          
+
           if ( b_restoreVerbose )
             std::cerr << " currently restore section " << tmp << " in SortedVectorSparse" << std::endl;
-          
+
           if ( tmp.compare("tolerance") == 0 )
           {
-            _is >> this->tolerance;        
-            _is >> tmp; // end of block 
+            _is >> this->tolerance;
+            _is >> tmp; // end of block
             tmp = this->removeEndTag ( tmp );
           }
           else if ( tmp.compare("ui_n") == 0 )
           {
-            _is >> this->ui_n;        
-            _is >> tmp; // end of block 
+            _is >> this->ui_n;
+            _is >> tmp; // end of block
             tmp = this->removeEndTag ( tmp );
           }
           else if ( tmp.compare("underlying_data_(sorted)") == 0 )
           {
-            _is >> tmp; // start of block 
-            
+            _is >> tmp; // start of block
+
             uint nonZeros;
             if ( ! this->isStartTag( tmp, "nonZeros" ) )
             {
@@ -751,12 +751,12 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
             else
             {
               _is >> nonZeros;
-              _is >> tmp; // end of block 
-              tmp = this->removeEndTag ( tmp );     
+              _is >> tmp; // end of block
+              tmp = this->removeEndTag ( tmp );
             }
-            
-            _is >> tmp; // start of block 
-            
+
+            _is >> tmp; // start of block
+
             if ( ! this->isStartTag( tmp, "data" ) )
             {
               std::cerr << "Attempt to restore SortedVectorSparse, but found no data. Aborting..." << std::endl;
@@ -767,25 +767,25 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
               T origValue;
               uint origIndex;
               T transformedValue;
-              
+
               this->nzData.clear();
               for ( uint i = 0; i < nonZeros; i++)
-              {              
+              {
                 _is >> origValue;
                 _is >> origIndex;
                 _is >> transformedValue;
-                    
+
                 std::pair<T, dataelement > p ( origValue, dataelement ( origIndex, transformedValue ) );
                 elementpointer it = this->nzData.insert ( p);
                 this->nonzero_indices.insert ( std::pair<uint, elementpointer> ( origIndex, it ) );
               }
-              
-              _is >> tmp; // end of block 
-              tmp = this->removeEndTag ( tmp );  
+
+              _is >> tmp; // end of block
+              tmp = this->removeEndTag ( tmp );
             }
-            
-            
-            _is >> tmp; // end of block 
+
+
+            _is >> tmp; // end of block
             tmp = this->removeEndTag ( tmp );
           }
           else
@@ -793,31 +793,31 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
             std::cerr << "WARNING -- unexpected SortedVectorSparse object -- " << tmp << " -- for restoration... aborting" << std::endl;
             throw;
           }
-        }        
+        }
 
       }
       else
       {
         std::cerr << "SortedVectorSparse::restore -- InStream not initialized - restoring not possible!" << std::endl;
         throw;
-      }      
+      }
     };
-    
-    virtual void store ( std::ostream & _os, 
-                         int _format = 0 
+
+    virtual void store ( std::ostream & _os,
+                         int _format = 0
                        ) const
     {
       if ( _os.good() )
       {
         // show starting point
         _os << this->createStartTag( "SortedVectorSparse" ) << std::endl;
-        
+
         _os.precision (std::numeric_limits<double>::digits10 + 1);
-        
+
         _os << this->createStartTag( "tolerance" ) << std::endl;
         _os << tolerance << std::endl;
         _os << this->createEndTag( "tolerance" ) << std::endl;
-        
+
         _os << this->createStartTag( "ui_n" ) << std::endl;
         _os << this->ui_n << std::endl;
         _os << this->createEndTag( "ui_n" ) << std::endl;
@@ -827,8 +827,8 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         _os << this->createStartTag( "nonZeros" ) << std::endl;
         _os << this->getNonZeros() << std::endl;
         _os << this->createEndTag( "nonZeros" ) << std::endl;
-        
-        _os << this->createStartTag( "data" ) << std::endl;  
+
+        _os << this->createStartTag( "data" ) << std::endl;
         for (const_elementpointer elP = this->nzData.begin();  elP != this->nzData.end(); elP++)
         {
           _os << elP->first << " " << elP->second.first << " " << elP->second.second << " ";
@@ -836,16 +836,16 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         _os << std::endl;
         _os << this->createEndTag( "data" ) << std::endl;
         _os << this->createEndTag( "underlying_data_(sorted)" ) << std::endl;
-      
+
         // done
         _os << this->createEndTag( "SortedVectorSparse" ) << std::endl;
       }
       else
       {
         std::cerr << "SortedVectorSparse::store -- OutStream not initialized - storing not possible!" << std::endl;
-      }      
-    };    
-    
+      }
+    };
+
     virtual void clear (){};
 };