فهرست منبع

clean-up, test-unit adaptation, bug-fixing for stored index

Alexander Freytag 9 سال پیش
والد
کامیت
0a8c064b19

+ 2 - 10
FMKGPHyperparameterOptimization.cpp

@@ -668,7 +668,6 @@ void FMKGPHyperparameterOptimization::updateEigenDecomposition( const int & _noE
 {
   //compute the largest eigenvalue of K + noise   
   
-  std::cerr << "IKM rows: " << ikmsum->rows() << " cols: " << ikmsum->cols() << std::endl;
   try 
   {
     this->eig->getEigenvalues ( *ikmsum,  eigenMax, eigenMaxVectors, _noEigenValues  );
@@ -1023,7 +1022,6 @@ void FMKGPHyperparameterOptimization::optimize ( std::map<int, NICE::Vector> & b
   t1.start();
   // we compute all needed eigenvectors for standard classification and variance prediction at ones.
   // nrOfEigenvaluesToConsiderForVarApprox should NOT be larger than 1 if a method different than approximate_fine is used!
-  std::cerr << "EV for Arnoldi: " << std::max ( this->nrOfEigenvaluesToConsider, this->nrOfEigenvaluesToConsiderForVarApprox) << std::endl;
   
   this->updateEigenDecomposition(  std::max ( this->nrOfEigenvaluesToConsider, this->nrOfEigenvaluesToConsiderForVarApprox) );
     
@@ -1159,9 +1157,8 @@ int FMKGPHyperparameterOptimization::classify ( const NICE::Vector & xstar, NICE
   for ( std::map<int, PrecomputedType>::const_iterator i = this->precomputedA.begin() ; i != this->precomputedA.end(); i++ )
   {
     int classno = i->first;
-    std::cerr << " classno: " << classno  << std::endl;
     maxClassNo = std::max ( maxClassNo, classno );
-    std::cerr << " current max class number: " << maxClassNo << std::endl;
+    
     double beta;
 
     if ( this->q != NULL )
@@ -1183,11 +1180,9 @@ int FMKGPHyperparameterOptimization::classify ( const NICE::Vector & xstar, NICE
       // searching for upper and lower bounds ( findFirst... functions ) require original feature
       // values as inputs. However, for calculation we need the transformed features values.
 
-      std::cerr << " call this->fmk->hik_kernel_sum ( A, B, xstar, beta, pf ); " << std::endl;
       this->fmk->hik_kernel_sum ( A, B, xstar, beta, this->pf );
     }
 
-    std::cerr << "score for " << classno << " : " << beta << std::endl;
     scores[ classno ] = beta;
   }
   scores.setDim ( maxClassNo + 1 );
@@ -1523,9 +1518,7 @@ void FMKGPHyperparameterOptimization::computePredictiveVarianceExact ( const NIC
   // ---------------- compute the second term --------------------
   NICE::Vector kStar;
   this->fmk->hikComputeKernelVector ( _x, kStar );
-
-  std::cerr << " kStar: " << kStar << std::endl;
-  
+ 
   //now run the ILS method
   NICE::Vector diagonalElements;
   this->ikmsum->getDiagonalElements ( diagonalElements );
@@ -1559,7 +1552,6 @@ void FMKGPHyperparameterOptimization::computePredictiveVarianceExact ( const NIC
   
   double currentSecondTerm( beta.Sum() );
   
-  std::cerr << "kSelf: " << kSelf <<  " currentSecondTerm: " << currentSecondTerm << std::endl;
   _predVariance = kSelf - currentSecondTerm;
 }    
 

+ 33 - 49
FastMinKernel.cpp

@@ -45,7 +45,8 @@ FastMinKernel::FastMinKernel( const std::vector<std::vector<double> > & _X,
                             )
 {
   this->setDebug(_debug);
-  this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dim);
+//   this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dim);
+  this->X_sorted.set_features( _X, _dim);
   this->ui_d         = this->X_sorted.get_d();
   this->ui_n         = this->X_sorted.get_n();
   this->d_noise      = _noise;
@@ -77,7 +78,8 @@ FastMinKernel::FastMinKernel ( const std::vector< const NICE::SparseVector * > &
                                const uint & _dim)
 {
   this->setDebug(_debug);
-  this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dimensionsOverExamples, _dim);
+  this->X_sorted.set_features( _X, _dimensionsOverExamples, _dim);
+//   this->hik_prepare_kernel_multiplications ( _X, this->X_sorted, _dimensionsOverExamples, _dim);
   this->ui_d         = this->X_sorted.get_d();
   this->ui_n         = this->X_sorted.get_n();
   this->d_noise      = _noise;
@@ -159,7 +161,6 @@ void FastMinKernel::hik_prepare_kernel_multiplications(const std::vector< const
                                                       )
 {
   //FIXME why do we hand over the feature matrix here?  
-  std::cerr << "FastMinKernel::hik_prepare_kernel_multiplications -- size of _X : " << _X.size() << std::endl;
   _X_sorted.set_features( _X, _dimensionsOverExamples, _dim );
 }
 
@@ -618,12 +619,8 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
   
     uint dim = i->first;
     double fval = i->second;
-    
-    std::cerr << " FastMinKernel::hik_kernel_sum (sparse)-- dim : " << dim << std::endl;    
-    std::cerr << " FastMinKernel::hik_kernel_sum (sparse)-- fval : " << fval << std::endl;    
-    
+        
     uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);    
-    std::cerr << " FastMinKernel::hik_kernel_sum -- nrZeroIndices : " << nrZeroIndices << std::endl;    
     
     if ( nrZeroIndices == this->ui_n ) {
       // all features are zero and let us ignore it completely
@@ -644,10 +641,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
       position--;
     }
     
-    std::cerr << " FastMinKernel::hik_kernel_sum -- position : " << position << std::endl;
     
-    std::cerr << " FastMinKernel::hik_kernel_sum -- this->ui_n : " << this->ui_n << std::endl;    
-  
     //NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
     //sum_{l \in L_k} \alpha_l x^l_k
     double firstPart(0.0);
@@ -655,9 +649,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
     // Invalid read of size 8
     if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n) ) 
     {
-      std::cerr << " attempt to access A in " << position-nrZeroIndices;
       firstPart = (_A[dim][position-nrZeroIndices]);
-      std::cerr << " with : " << firstPart << std::endl;
     }      
     
     // sum_{u \in U_k} alpha_u
@@ -665,25 +657,20 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
     // sum_{u \in U_k} alpha_u
     // => double secondPart( B(dim, n-1) - B(dim, position));
     //TODO in the next line there occurs the following error
-    // Invalid read of size 8      
-    std::cerr << " attempt to access B in " << this->ui_n-1-nrZeroIndices;    
+    // Invalid read of size 8        
     double secondPart( _B[dim][this->ui_n-1-nrZeroIndices]);
-    std::cerr << " with : " << secondPart << std::endl;    
     //TODO in the "overnext" line there occurs the following error
     // Invalid read of size 8    
     if ( !posIsZero && (position >= nrZeroIndices) )
     {
-      std::cerr << " attempt to access B in " << position-nrZeroIndices;
       secondPart-= _B[dim][position-nrZeroIndices];
-      std::cerr << " with : " << _B[dim][position-nrZeroIndices] << std::endl;
     }
     
     if ( _pf != NULL )
     {
       fval = _pf->f ( dim, fval );
     }   
-    
-    std::cerr << " result dim " << dim << " impact " << firstPart + secondPart* fval << " firstPart " << firstPart << " secondPart " << secondPart <<  " fval " << fval << std::endl;    
+      
     // but apply using the transformed one
     _beta += firstPart + secondPart* fval;
   }
@@ -700,13 +687,10 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
   uint dim ( 0 );
   for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
   {
-    std::cerr << " FastMinKernel::hik_kernel_sum -- dim : " << dim << std::endl;
-  
+ 
     double fval = *i;
-    std::cerr << " FastMinKernel::hik_kernel_sum -- fval : " << fval << std::endl;
     
     uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
-    std::cerr << " FastMinKernel::hik_kernel_sum -- nrZeroIndices : " << nrZeroIndices << std::endl;
     
     if ( nrZeroIndices == this->ui_n ) {
       // all features are zero and let us ignore it completely
@@ -725,12 +709,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
     if ( !posIsZero )
     {
       position--;
-    }
-        
-    std::cerr << " FastMinKernel::hik_kernel_sum -- position : " << position << std::endl;
-    
-    std::cerr << " FastMinKernel::hik_kernel_sum -- this->ui_n : " << this->ui_n << std::endl;
-    
+    }    
     
   
     //NOTE again - pay attention! This is only valid if all entries are NOT negative! - if not, ask wether the current feature is greater than zero. If so, subtract the nrZeroIndices, if not do not
@@ -742,9 +721,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
     
     if ( !posIsZero && ((position-nrZeroIndices) < this->ui_n)  ) 
     {
-      std::cerr << " attempt to access A in " << position-nrZeroIndices;
       firstPart = (_A[dim][position-nrZeroIndices]);
-      std::cerr << " with : " << firstPart << std::endl;
     }
     
     // sum_{u \in U_k} alpha_u
@@ -753,17 +730,13 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
     // => double secondPart( B(dim, n-1) - B(dim, position));
     //TODO in the next line there occurs the following error
     // Invalid read of size 8      
-    std::cerr << " attempt to access B in " << this->ui_n-1-nrZeroIndices;
     double secondPart( _B[dim][this->ui_n-1-nrZeroIndices] );
-    std::cerr << " with : " << secondPart << std::endl;
     //TODO in the "overnext" line there occurs the following error
     // Invalid read of size 8    
     
     if ( !posIsZero && (position >= nrZeroIndices) )
     {
-      std::cerr << " attempt to access B in " << position-nrZeroIndices;
       secondPart-= _B[dim][position-nrZeroIndices];
-      std::cerr << " with : " << _B[dim][position-nrZeroIndices] << std::endl;
     }
     
       
@@ -773,7 +746,6 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
       fval = _pf->f ( dim, fval );
     }   
     
-    std::cerr << " result dim " << dim << " impact " << firstPart + secondPart* fval << " firstPart " << firstPart << " secondPart " << secondPart <<  " fval " << fval << std::endl;
     // but apply using the transformed one
     _beta += firstPart + secondPart* fval;
   }
@@ -881,7 +853,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
     for ( iter = 1; iter <= _maxIterations; iter++ ) 
     {
       NICE::Vector perm;
-      randomPermutation( perm, indices, _sizeOfRandomSubset );
+      this->randomPermutation( perm, indices, _sizeOfRandomSubset );
  
       if ( _timeAnalysis )
       {
@@ -893,7 +865,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
         double res = r.normL2();
         double resMax = r.normInf();
 
-        cerr << "SimpleGradientDescent: TIME " << t.getSum() << " " << res << " " << resMax << endl;
+        std::cerr << "SimpleGradientDescent: TIME " << t.getSum() << " " << res << " " << resMax << std::endl;
 
         t.start();
       }
@@ -978,15 +950,15 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
       
       double delta = delta_alpha.normL2();
       if ( this->b_verbose ) {
-        cerr << "FastMinKernel::solveLin: iteration " << iter << " / " << _maxIterations << endl;     
-        cerr << "FastMinKernel::solveLin: delta = " << delta << endl;
-        cerr << "FastMinKernel::solveLin: pseudo residual = " << pseudoResidual.scalarProduct(pseudoResidual) << endl;
+        std::cerr << "FastMinKernel::solveLin: iteration " << iter << " / " << _maxIterations << std::endl;     
+        std::cerr << "FastMinKernel::solveLin: delta = " << delta << std::endl;
+        std::cerr << "FastMinKernel::solveLin: pseudo residual = " << pseudoResidual.scalarProduct(pseudoResidual) << std::endl;
       }
       
       if ( delta < _minDelta ) 
       {
         if ( this->b_verbose )
-          cerr << "FastMinKernel::solveLin: small delta" << endl;
+          std::cerr << "FastMinKernel::solveLin: small delta" << std::endl;
         break;
       }    
     }
@@ -1429,6 +1401,12 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
   _kstar.resize( this->ui_n );
   _kstar.set(0.0);
   
+  if ( this->b_debug )
+  {
+    std::cerr << " FastMinKernel::hikComputeKernelVector -- input: " << std::endl;
+    _xstar.store( std::cerr);
+  }
+  
   //let's start :)
   for (SparseVector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++)
   {
@@ -1436,6 +1414,9 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
     uint dim = i->first;
     double fval = i->second;
     
+    if ( this->b_debug )
+      std::cerr << "dim: " << dim  << " fval: " << fval << std::endl;
+    
     uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
     if ( nrZeroIndices == this->ui_n ) {
       // all features are zero so let us ignore them completely
@@ -1451,6 +1432,9 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
     this->X_sorted.findFirstLargerInDimension(dim, fval, position);
     //position--;
     
+    if ( this->b_debug )
+      std::cerr << " position: " << position << std::endl;
+    
     //get the non-zero elements for this dimension  
     const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
     
@@ -1460,11 +1444,15 @@ void FastMinKernel::hikComputeKernelVector ( const NICE::SparseVector& _xstar,
     for ( SortedVectorSparse<double>::const_elementpointer i = nonzeroElements.begin(); i != nonzeroElements.end(); i++, count++ )
     {
       uint origIndex(i->second.first); //orig index (i->second.second would be the transformed feature value)
+      
+      if ( this->b_debug )
+        std::cerr << "i->1.2: " << i->second.first <<  " origIndex: " << origIndex << " count: " << count << " position: " << position << std::endl;
       if (count < position)
         _kstar[origIndex] += i->first; //orig feature value
       else
         _kstar[origIndex] += fval;
     }
+    
   }  
 }
 
@@ -1556,16 +1544,13 @@ void FastMinKernel::hikComputeKernelVector( const NICE::Vector & _xstar,
   _kstar.resize(this->ui_n);
   _kstar.set(0.0);
 
-    std::cerr << "test example: " << _xstar << std::endl;
-    std::cerr << " init _kstar: " << _kstar << std::endl;  
-  
+ 
   //let's start :)
   uint dim ( 0 );
   for (NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++)
   {
   
     double fval = *i;
-    std::cerr << "   dim: " << dim << " fval: " << fval << std::endl;
     
     uint nrZeroIndices = this->X_sorted.getNumberOfZeroElementsPerDimension(dim);
     if ( nrZeroIndices == this->ui_n ) {
@@ -1582,7 +1567,6 @@ void FastMinKernel::hikComputeKernelVector( const NICE::Vector & _xstar,
     this->X_sorted.findFirstLargerInDimension(dim, fval, position);
     //position--;    
     
-    std::cerr << "   dim: " << dim << " fval: " << fval << std::endl;
     
     //get the non-zero elements for this dimension  
     const multimap< double, SortedVectorSparse<double>::dataelement> & nonzeroElements = this->X_sorted.getFeatureValues(dim).nonzeroElements();
@@ -1620,7 +1604,7 @@ void FastMinKernel::restore ( std::istream & _is,
     if ( ! this->isStartTag( tmp, "FastMinKernel" ) )
     {
         std::cerr << " WARNING - attempt to restore FastMinKernel, but start flag " << tmp << " does not match! Aborting... " << std::endl;
-	throw;
+        throw;
     }   
         
     _is.precision (numeric_limits<double>::digits10 + 1);

+ 11 - 14
FeatureMatrixT.tcc

@@ -455,7 +455,6 @@ namespace NICE {
       
       if (this->features[_dim].getNonZeros() == 1)
       {
-        std::cerr << " FeatureMatrixT<T>::findFirstLargerInDimension  -- only one non-zero element: " << this->features[_dim].getNonZeros() << " with value : " << this->features[_dim].nonzeroElements().begin()->first << std::endl;
         // if element is greater than the only nonzero element, then it is larger than everything else
         if (this->features[_dim].nonzeroElements().begin()->first <= _elem)
           _position = this->ui_n;
@@ -464,7 +463,6 @@ namespace NICE {
         else if (_elem > this->features[_dim].getTolerance() )
           _position = this->ui_n -1;
         
-        std::cerr << " -> decided position: " << _position << std::endl;
         return;
       }
       
@@ -480,9 +478,6 @@ namespace NICE {
       _position = distance( this->features[_dim].nonzeroElements().begin(), it );
       
       
-      T valtmp ( it->second.second );
-      std::cerr << " FeatureMatrixT<T>::findFirstLargerInDimension  --distance is : " << _position << " with value: " << (double) valtmp << std::endl;
-
       if ( _elem > this->features[_dim].getTolerance() )
       {
         //position += features[dim].getZeros();
@@ -605,9 +600,9 @@ namespace NICE {
       for (NICE::SparseVector::const_iterator it = _feature.begin(); it != _feature.end(); it++)
       {
         if (_pf != NULL)
-          this->features[it->first].insert( (T) it->second, _pf->f( it->first, (T) it->second), this->ui_n );
+          this->features[it->first].insert( (T) it->second, _pf->f( it->first, (T) it->second), true /* _specifyFeatureNumber */, this->ui_n );
         else  
-          this->features[it->first].insert( (T) it->second, this->ui_n );
+          this->features[it->first].insert( (T) it->second, true /* _specifyFeatureNumber */, this->ui_n );
       }
       this->ui_n++;
     }    
@@ -642,7 +637,7 @@ namespace NICE {
                                         )
     {
       this->features.clear();
-      this->set_d( std::max ( _dim, _features.size() ) );
+      this->set_d( std::max ( _dim, (const uint) _features.size() ) );
       
       if ( this->ui_d > 0 )
         this->ui_n = _features[0].size();
@@ -683,8 +678,7 @@ namespace NICE {
                                         )
     {
       this->features.clear();
-      uint featsize ( _features.size() ); // necessary for some compiler reasons
-      this->set_d( std::max ( _dim, featsize ) );
+      this->set_d( std::max ( _dim, (const uint) _features.size() ) );
       
       if ( this->ui_d > 0 )
         this->ui_n = _features[0].size();
@@ -692,6 +686,11 @@ namespace NICE {
       //pay attention: we assume now, that we have a vector (over dimensions) containing vectors over features (examples per dimension) - to be more efficient
       for (uint dim = 0; dim < this->ui_d; dim++)
       {
+        if ( this->b_debug ) 
+        {
+          std::cerr << " dim: " << dim << " add " << _features[dim].size() << " examples " << std::endl;
+        }
+        
         this->features[dim].insert( _features[dim] );
       }
     }
@@ -737,9 +736,7 @@ namespace NICE {
         }        
       }
       this->set_d( dimTmp ); 
-      
-      std::cerr << "FeatureMatrixT<T>::set_features -- dimension: " << this->get_d() << std::endl;
-            
+                  
       // set number of examples n
       if ( this->ui_d > 0 )
       {
@@ -772,7 +769,7 @@ namespace NICE {
             if ( this->b_debug )
               std::cerr << elemIt->first << "-" << elemIt->second << " ";
             //elemIt->first: dim, elemIt->second: value
-            this->features[elemIt->first].insert( (T) elemIt->second, nr);
+            this->features[elemIt->first].insert( (T) elemIt->second, true /* _specifyFeatureNumber */, nr);
           }//for non-zero-values of the feature
           if ( this->b_debug )
             std::cerr << std::endl;

+ 4 - 16
GPHIKClassifier.cpp

@@ -163,12 +163,9 @@ void GPHIKClassifier::classify ( const NICE::Vector * example,  int & result, Sp
 
 void GPHIKClassifier::classify ( const SparseVector * example,  int & result, SparseVector & scores, double & uncertainty ) const
 {
-  std::cerr << " classify sparse vectors " << std::endl;
   if ( ! this->b_isTrained )
      fthrow(Exception, "Classifier not trained yet -- aborting!" );
-  
-  example->store ( std::cerr );
-  
+    
   scores.clear(); 
  
   result = gphyper->classify ( *example, scores );
@@ -202,7 +199,6 @@ void GPHIKClassifier::classify ( const NICE::Vector * _example,
                                  double & _uncertainty 
                                ) const
 {
-  std::cerr << " classify non-sparse vectors " << std::endl;
   
   if ( ! this->b_isTrained )
      fthrow(Exception, "Classifier not trained yet -- aborting!" );  
@@ -210,8 +206,7 @@ void GPHIKClassifier::classify ( const NICE::Vector * _example,
   _scores.clear();
   
   _result = gphyper->classify ( *_example, _scores );
-  //_scores.clear(); //debugging
-  
+ 
 
   if ( _scores.size() == 0 ) {
     fthrow(Exception, "Zero scores, something is likely to be wrong here: svec.size() = " << _example->size() );
@@ -241,9 +236,7 @@ void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & e
 {
   
   //FIXME add check whether the classifier has been trained already. if so, discard all previous results.
-  
-    std::cerr << "1. train method" << std::endl;  
-  
+    
   // security-check: examples and labels have to be of same size
   if ( examples.size() != labels.size() ) 
   {
@@ -259,11 +252,7 @@ void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & e
   t.start();
   
   FastMinKernel *fmk = new FastMinKernel ( examples, noise, this->debug );
-  //foo bar check that all examples are correct
-  if (verbose)
-  {
-    fmk->store ( std::cerr ); // does not work correctly...
-  }
+
   gphyper->setFastMinKernel ( fmk ); 
   
   t.stop();
@@ -316,7 +305,6 @@ void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & e
 /** training process */
 void GPHIKClassifier::train ( const std::vector< const NICE::SparseVector *> & examples, std::map<int, NICE::Vector> & binLabels )
 { 
-    std::cerr << "2. train method" << std::endl;
   // security-check: examples and labels have to be of same size
   for ( std::map< int, NICE::Vector >::const_iterator binLabIt = binLabels.begin();
         binLabIt != binLabels.end();

+ 18 - 13
SortedVectorSparse.h

@@ -121,23 +121,26 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     /**
     * @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 featureNumber the index of the new element (optional)
+    * @param _newElement element which will be added
+    * @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 bool _specifyFeatureNumber = false,
                   const uint & _featureNumber = 0
                 )
     {
-      int newIndex ( _featureNumber);
-      if ( _featureNumber < 0)
-        newIndex = this->ui_n;      
+      
+      uint newIndex ( this->ui_n );
+      if ( _specifyFeatureNumber )
+        newIndex = _featureNumber;
       
       if ( !checkSparsity ( _newElement ) )
       {
         // element is not sparse
         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 ) );
+        this->nonzero_indices.insert ( std::pair<uint, elementpointer> ( newIndex, it ) );
       }
       this->ui_n++;
     }
@@ -147,16 +150,18 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     *
     * @param newElement element which will be added
     * @param newElementTransformed transformed feature value
+    * @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 
                 )
     {
-      int newIndex ( _featureNumber);
-      if ( _featureNumber < 0)
-        newIndex = this->ui_n;
+      uint newIndex ( this->ui_n );
+      if ( _specifyFeatureNumber )
+        newIndex = _featureNumber;
       
       if ( !checkSparsity ( _newElement ) )
       {
@@ -164,7 +169,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         
         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 ) );
+        this->nonzero_indices.insert ( std::pair<uint, elementpointer> ( newIndex, it ) );
       }
       this->ui_n++;
     }
@@ -299,7 +304,7 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
       if ( _a >= this->ui_n || _a < 0 )
         fthrow ( Exception, "SortedVectorSparse::set(): out of bounds" );
 
-      typename std::map<int, elementpointer>::iterator i = this->nonzero_indices.find ( _a );
+      typename std::map<uint, elementpointer>::iterator i = this->nonzero_indices.find ( _a );
 
       // check whether the element was previously non-sparse
       if ( i != this->nonzero_indices.end() ) {
@@ -426,14 +431,14 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
     {
       std::vector<uint> rv ( this->ui_n );
 
-      uint idx = std::max( this->ui_n - 1, 0 );
+      uint idx = std::max( this->ui_n - 1, (uint) 0 );
       typename std::multimap<T, dataelement>::const_reverse_iterator it ;
       for ( it = this->nzData.rbegin(); it != this->nzData.rend() && ( it->first > tolerance ); it++, idx-- )
       {
         rv[ idx ] = it->second.first;
       }
 
-      uint i = std::max( this->ui_n - 1, 0 );
+      uint i = std::max( this->ui_n - 1, (uint) 0 );
       for ( int iCnt = this->ui_n - 1 ; iCnt >= 0 ; i--, iCnt-- )
         if ( nonzero_indices.find ( i ) == nonzero_indices.end() )
         {

+ 0 - 4
matlab/GPHIKClassifierMex.cpp

@@ -252,7 +252,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     // create object
     if ( !strcmp("new", cmd.c_str() ) )
     {
-      std::cerr << "create gphik mex object" << std::endl;
         // check output variable
         if (nlhs != 1)
             mexErrMsgTxt("New: One output expected.");
@@ -329,7 +328,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         yMultiTrain = MatlabConversion::convertDoubleVectorToNice(prhs[3]);
 
         //----------------- train our classifier -------------
-        std::cerr << "call train from GPHIKClassifierMex" << std::endl;
         classifier->train ( examplesTrain , yMultiTrain );
 
         //----------------- clean up -------------
@@ -359,9 +357,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         {
             NICE::SparseVector * example;
             example = new NICE::SparseVector ( MatlabConversion::convertSparseVectorToNice( prhs[2] ) );
-            std::cerr << "do classification" << std::endl;
             classifier->classify ( example,  result, scores, uncertainty );
-            std::cerr << "classification done" << std::endl;
             
             //----------------- clean up -------------
             delete example;

+ 44 - 20
tests/TestFastHIK.cpp

@@ -15,6 +15,17 @@
 
 #include "TestFastHIK.h"
 
+const bool b_debug = false;
+const bool verbose = false;
+const bool verboseStartEnd = true;
+const bool solveLinWithoutRand = false;
+const uint n = 30;//1500;//1500;//10;
+const uint d = 5;//200;//2;
+const uint numBins = 11;//1001;//1001;
+const uint solveLinMaxIterations = 1000;
+const double sparse_prob = 0.6;
+const bool smallTest = false;
+
 bool compareVVector(const NICE::VVector & A, const NICE::VVector & B, const double & tolerance = 10e-8)
 {
   bool result(true);
@@ -67,15 +78,7 @@ bool compareLUTs(const double* LUT1, const double* LUT2, const int & size, const
   return result;
 }
 
-const bool verbose = false;
-const bool verboseStartEnd = true;
-const bool solveLinWithoutRand = false;
-const uint n = 30;//1500;//1500;//10;
-const uint d = 5;//200;//2;
-const uint numBins = 11;//1001;//1001;
-const uint solveLinMaxIterations = 1000;
-const double sparse_prob = 0.6;
-const bool smallTest = false;
+
 
 using namespace NICE;
 using namespace std;
@@ -146,7 +149,8 @@ void TestFastHIK::testKernelMultiplication()
   NICE::Matrix K (hikSlow.computeKernelMatrix(dataMatrix_transposed, noise));
   //toc
   float time_slowComputation = (float) (clock() - slow_start);
-  std::cerr << "Time for computing the kernel matrix without using sparsity: " << time_slowComputation/CLOCKS_PER_SEC << " s" << std::endl;  
+  if (verbose)
+    std::cerr << "Time for computing the kernel matrix without using sparsity: " << time_slowComputation/CLOCKS_PER_SEC << " s" << std::endl;  
 
   // tic
   time_t  slow_sparse_start = clock();
@@ -154,7 +158,8 @@ void TestFastHIK::testKernelMultiplication()
   NICE::Matrix KSparseCalculated (hikSlow.computeKernelMatrix(fmk.featureMatrix(), noise));
   //toc
   float time_slowComputation_usingSparsity = (float) (clock() - slow_sparse_start);
-  std::cerr << "Time for computing the kernel matrix using sparsity: " << time_slowComputation_usingSparsity/CLOCKS_PER_SEC << " s" << std::endl;    
+  if (verbose)
+    std::cerr << "Time for computing the kernel matrix using sparsity: " << time_slowComputation_usingSparsity/CLOCKS_PER_SEC << " s" << std::endl;    
 
   if ( verbose ) 
     cerr << "K = " << K << endl;
@@ -674,7 +679,8 @@ void TestFastHIK::testLinSolve()
   NICE::Vector alpha;
   NICE::Vector alphaRandomized;
 
-  std::cerr << "solveLin with randomization" << std::endl;
+  if ( verbose )
+    std::cerr << "solveLin with randomization" << std::endl;
   // tic
   NICE::Timer t;
   t.start();
@@ -682,8 +688,9 @@ void TestFastHIK::testLinSolve()
   fmk.solveLin(y,alphaRandomized,q,pf,true,solveLinMaxIterations,30);
   //toc
   t.stop();
-  float time_randomizedSolving = t.getLast();
-  std::cerr << "Time for solving with random subsets: " << time_randomizedSolving << " s" << std::endl;  
+  float time_randomizedSolving = t.getLast();  
+  if ( verbose )
+    std::cerr << "Time for solving with random subsets: " << time_randomizedSolving << " s" << std::endl;  
   
   // test the case, where we first transform and then use the multiply stuff
   std::vector<std::vector<double> > dataMatrix_transposed (dataMatrix);
@@ -697,12 +704,17 @@ void TestFastHIK::testLinSolve()
   
   if (solveLinWithoutRand)
   {
-    std::cerr << "solveLin without randomization" << std::endl;
+    if ( verbose )
+      std::cerr << "solveLin without randomization" << std::endl;
     fmk.solveLin(y,alpha,q,pf,false,1000);
     Vector K_alpha;
     K_alpha.multiply(gK, alpha);
-    std::cerr << "now assert that K_alpha == y" << std::endl;
-    std::cerr << "(K_alpha-y).normL1(): " << (K_alpha-y).normL1() << std::endl;
+    
+    if ( verbose )
+    {
+      std::cerr << "now assert that K_alpha == y" << std::endl;
+      std::cerr << "(K_alpha-y).normL1(): " << (K_alpha-y).normL1() << std::endl;
+    }
   }
    
 //   std::cerr << "alpha: " << alpha << std::endl;
@@ -718,8 +730,11 @@ void TestFastHIK::testLinSolve()
 //   std::cerr << "test_alpha (CGM): " << test_alpha << std::endl;
 //   std::cerr << "K_times_alpha (CGM): " << K_alpha << std::endl;
   
-  std::cerr << "now assert that K_alphaRandomized == y" << std::endl;
-  std::cerr << "(K_alphaRandomized-y).normL1(): " << (K_alphaRandomized-y).normL1() << std::endl;
+  if ( verbose )
+  {
+    std::cerr << "now assert that K_alphaRandomized == y" << std::endl;
+    std::cerr << "(K_alphaRandomized-y).normL1(): " << (K_alphaRandomized-y).normL1() << std::endl; 
+  }
   
 
 //   CPPUNIT_ASSERT_DOUBLES_EQUAL((K_alphaRandomized-y).normL1(), 0.0, 1e-6);
@@ -746,7 +761,8 @@ void TestFastHIK::testKernelVector()
   }
 
   double noise = 1.0;
-  FastMinKernel fmk ( dataMatrix, noise );
+  FastMinKernel fmk ( dataMatrix, noise, b_debug );
+  
 
   std::vector<double> xStar; xStar.push_back(0.2);xStar.push_back(0.7);xStar.push_back(0.1);
   NICE::Vector xStarVec (xStar);
@@ -755,9 +771,17 @@ void TestFastHIK::testKernelVector()
   
   NICE::SparseVector xStarsparse( xStarVec );
   NICE::SparseVector x2sparse( x2Vec );
+
+
+  if ( b_debug )
+  {
+    fmk.store ( std::cerr );
+    xStarsparse.store ( std::cerr );
+  }
   
   NICE::Vector k1;
   fmk.hikComputeKernelVector( xStarsparse, k1 );
+
   
   NICE::Vector k2;
   fmk.hikComputeKernelVector( x2sparse, k2 );

+ 2 - 2
tests/TestFeatureMatrixT.cpp

@@ -36,7 +36,7 @@ void TestFeatureMatrixT::testSetup()
 
   generateRandomFeatures ( d, n, dataMatrix );
 
-  int nrZeros(0);
+  uint nrZeros(0);
   for ( uint i = 0 ; i < d; i++ )
   {
     for ( uint k = 0; k < n; k++ )
@@ -64,7 +64,7 @@ void TestFeatureMatrixT::testSetup()
   }
   
   transposeVectorOfVectors(dataMatrix);
-  std::vector<std::vector<int> > permutations;
+  std::vector<std::vector<uint> > permutations;
   if (verbose)
     std::cerr << "now try to set_features" << std::endl;
   fm.set_features(dataMatrix, permutations);

+ 5 - 2
tests/TestGPHIKRegression.cpp

@@ -117,8 +117,11 @@ void TestGPHIKRegression::testRegressionHoldInData()
   NICE::GPHIKRegression * regressionMethod;
   regressionMethod = new NICE::GPHIKRegression ( &conf );
   regressionMethod->train ( examplesTrain , yValues );
-  std::cerr << " yValues used for training regression object" << std::endl;
-  std::cerr << yValues << std::endl;
+  if (verbose)
+  {
+    std::cerr << " yValues used for training regression object" << std::endl;
+    std::cerr << yValues << std::endl;
+  }
   
   double holdInLoss ( 0.0 );
   

+ 26 - 26
tests/TestVectorSorter.cpp

@@ -27,16 +27,16 @@ void TestVectorSorter::checkData ( const vector<double> & all_elements, const NI
   if (verboseStartEnd)
     std::cerr << "================== TestVectorSorter::checkData ===================== " << std::endl;
   
-  vector< pair<double, int> > all_elements_sorted;
+  std::vector< pair<double, uint> > all_elements_sorted;
 
-  vector< pair<double, int> > nonzero_elements;
+  std::vector< pair<double, uint> > nonzero_elements;
   for (uint i = 0 ; i < all_elements.size(); i++ )
   {
     if ( fabs(all_elements[i]) > sparse_tolerance ) {
-      nonzero_elements.push_back( pair<double, int> ( all_elements[i], i ) );
-      all_elements_sorted.push_back( pair<double, int> ( all_elements[i], i ) );
+      nonzero_elements.push_back( pair<double, uint> ( all_elements[i], i ) );
+      all_elements_sorted.push_back( pair<double, uint> ( all_elements[i], i ) );
     } else {
-      all_elements_sorted.push_back( pair<double, int> ( 0.0, i ) );
+      all_elements_sorted.push_back( pair<double, uint> ( 0.0, i ) );
     }
   }
 
@@ -46,34 +46,32 @@ void TestVectorSorter::checkData ( const vector<double> & all_elements, const NI
   // looping through all non-zero values
   uint k = 0;
   for (NICE::SortedVectorSparse<double>::const_elementpointer it = vSS.nonzeroElements().begin(); it != vSS.nonzeroElements().end(); it++,k++)
-	{
+  {
     CPPUNIT_ASSERT_DOUBLES_EQUAL( nonzero_elements[k].first, it->first, 0.0 );
     CPPUNIT_ASSERT_EQUAL( nonzero_elements[k].second, it->second.first );
-	}
+  }
 
   // 2 3 0 1 5 4
-	std::vector<int> vSSPerm(vSS.getPermutation());
-	for (int k = 0;k < vSSPerm.size(); k++)
+	std::vector<uint> vSSPerm(vSS.getPermutation());
+	for ( uint k = 0;k < vSSPerm.size(); k++ )
 	{
     CPPUNIT_ASSERT_EQUAL( all_elements_sorted[k].second, vSSPerm[k] );
 	}
 	
-	std::vector<int> vSSPermNNZ (vSS.getPermutationNonZero());
-  vector<pair<int,double> > sv ( vSS.getOrderInSeparateVector() );
-	for (int k = 0;k < vSSPermNNZ.size(); k++)
-	{
+  std::vector<uint> vSSPermNNZ (vSS.getPermutationNonZero());
+  vector<pair<uint,double> > sv ( vSS.getOrderInSeparateVector() );
+  for ( int k = 0;k < vSSPermNNZ.size(); k++ )
+  {
     CPPUNIT_ASSERT_EQUAL( nonzero_elements[k].second, vSSPermNNZ[k] );
     CPPUNIT_ASSERT_EQUAL( sv[k].first, vSSPermNNZ[k] );
     CPPUNIT_ASSERT_EQUAL( sv[k].second, vSS.access( sv[k].first ) );
-	}
+  }
 
-//   cerr << endl;
-  for (int k = 0;k < vSS.getN();k++)
+
+  for ( uint k = 0;k < vSS.getN();k++ )
   {
     CPPUNIT_ASSERT_DOUBLES_EQUAL( all_elements[k], vSS.access(k), sparse_tolerance ); 
-//     cerr << "Element " << k << " = " << vSS.access(k) << endl;
   }
-//     vSS.print();
 
   if (verboseStartEnd)
     std::cerr << "================== TestVectorSorter::checkData done ===================== " << std::endl;  
@@ -86,7 +84,7 @@ void TestVectorSorter::testVectorSorter()
   if (verboseStartEnd)
     std::cerr << "================== TestVectorSorter::testVectorSorter ===================== " << std::endl;
   
-  vector<double> all_elements;
+  std::vector<double> all_elements;
   all_elements.push_back(2);
   all_elements.push_back(4);
   all_elements.push_back(0);
@@ -98,28 +96,30 @@ void TestVectorSorter::testVectorSorter()
 
   // Now we put everything in a vectorsortersparse object
   NICE::SortedVectorSparse<double> vSS;
-	vSS.setTolerance(sparse_tolerance);
+  vSS.setTolerance(sparse_tolerance);
   for (uint i = 0 ; i < all_elements.size(); i++ )
+  {
     vSS.insert( all_elements[i] );
+  }
 
   checkData( all_elements, vSS );
   
 
 //   cerr << endl;
 //   cerr << "v[1] = 3.0 ";
-  vSS.set(1, 3.0);
+  vSS.set( 1, 3.0);
   all_elements[1] = 3.0;
   checkData( all_elements, vSS );
   
 //   cerr << endl;
 //   cerr << "v[1] = 0.0 ";
-  vSS.set(1, 0.0);
+  vSS.set( 1, 0.0);
   all_elements[1] = 0.0;
   checkData( all_elements, vSS );
 
 //   cerr << endl;
 //   cerr << "v[5] = -3.0 ";
-  vSS.set(5, -3.0);
+  vSS.set( 5, -3.0);
   all_elements[5] = -3.0;
   checkData( all_elements, vSS );
 
@@ -137,19 +137,19 @@ void TestVectorSorter::testVectorSorter()
 
 //   cerr << endl;
 //   cerr << "v[0] = -10.0 ";
-  vSS.set(0, -10.0);
+  vSS.set( 0, -10.0);
   all_elements[0] = -10.0;
   checkData( all_elements, vSS );
 
 //   cerr << endl;
 //   cerr << "v[5] = 2.0 ";
-  vSS.set(5, 2.0);
+  vSS.set( 5, 2.0);
   all_elements[5] = 2.0;
   checkData( all_elements, vSS );
 
 //   cerr << endl;
 //   cerr << "v[5] = 0.0 ";
-  vSS.set(5, 0.0);
+  vSS.set( 5, 0.0);
   all_elements[5] = 0.0;
   checkData( all_elements, vSS );