Explorar o código

Merge branch 'master' of dbv.inf-cv.uni-jena.de:nice/nice-gp-hik-core into raw_version

Erik Rodner %!s(int64=9) %!d(string=hai) anos
pai
achega
93eab3099a

+ 3 - 6
FMKGPHyperparameterOptimization.cpp

@@ -1150,11 +1150,9 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::SparseVector & _xst
     fthrow ( Exception, "The precomputation vector is zero...have you trained this classifier?" );
   }
 
-  uint maxClassNo = 0;
   for ( std::map<uint, PrecomputedType>::const_iterator i = this->precomputedA.begin() ; i != this->precomputedA.end(); i++ )
   {
     uint classno = i->first;
-    maxClassNo = std::max ( maxClassNo, classno );
     double beta;
 
     if ( this->q != NULL ) {
@@ -1178,7 +1176,7 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::SparseVector & _xst
 
     _scores[ classno ] = beta;
   }
-  _scores.setDim ( maxClassNo + 1 );
+  _scores.setDim ( *(this->knownClasses.rbegin() ) + 1 );
   
   if ( this->precomputedA.size() > 1 )
   { // multi-class classification
@@ -1206,11 +1204,9 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::Vector & _xstar,
     fthrow ( Exception, "The precomputation vector is zero...have you trained this classifier?" );
   }
 
-  uint maxClassNo = 0;
   for ( std::map<uint, PrecomputedType>::const_iterator i = this->precomputedA.begin() ; i != this->precomputedA.end(); i++ )
   {
     uint classno = i->first;
-    maxClassNo = std::max ( maxClassNo, classno );
     
     double beta;
 
@@ -1238,7 +1234,8 @@ uint FMKGPHyperparameterOptimization::classify ( const NICE::Vector & _xstar,
 
     _scores[ classno ] = beta;
   }
-  _scores.setDim ( maxClassNo + 1 );
+
+  _scores.setDim ( *(this->knownClasses.rbegin() ) + 1 );
   
   
   if ( this->precomputedA.size() > 1 )

+ 1 - 1
FeatureMatrixT.h

@@ -101,7 +101,7 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
 #endif
 
     /** just another constructor for sparse features */
-    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & _X, 
+    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & _features,
                    const bool _dimensionsOverExamples = false, 
                    const uint & _dim = 0
                   );

+ 17 - 12
FeatureMatrixT.tcc

@@ -36,11 +36,12 @@ namespace NICE {
                                       const uint & _dim
                                      )
     {
-      this->ui_n = 0;
-      if (_dim < 0)
-        this->ui_d = (*_features.begin()).size();
-      else
-        this->ui_d = _dim;
+        // resize our data structure
+        if (_dim == 0)
+            this->set_d( (*_features.begin()).size() );
+        else
+            this->set_d( _dim );
+
 
       for (typename std::vector<std::vector<T> >::const_iterator it = _features.begin(); it != _features.end(); it++)
       {
@@ -53,23 +54,27 @@ namespace NICE {
     //Constructor reading data from a vector of sparse vector pointers
     template <typename T>
     FeatureMatrixT<T>::
-    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & _X,
+    FeatureMatrixT(const std::vector< const NICE::SparseVector * > & _features,
                    const bool _dimensionsOverExamples,
                    const uint & _dim
                   )
     {
       this->features.clear();
 
-      // resize our data structure
-      set_d( _dim );
+        // resize our data structure
+        if (_dim == 0)
+            this->set_d( (*_features.begin())->getDim() );
+        else
+            this->set_d( _dim );
+
 
       // set number of examples n
       if ( this->ui_d > 0 )
       {
         if (_dimensionsOverExamples) //do we have dim x examples ?
-          this->ui_n = _X[0]->getDim(); //NOTE Pay attention: we assume, that this number is set!
+          this->ui_n = _features[0]->getDim(); //NOTE Pay attention: we assume, that this number is set!
         else //we have examples x dimes (as usually done)
-          this->ui_n = _X.size();
+          this->ui_n = _features.size();
       }
 
 
@@ -78,7 +83,7 @@ namespace NICE {
       {
         for (uint dim = 0; dim < this->ui_d; dim++)
         {
-          this->features[dim].insert( _X[dim] );
+          this->features[dim].insert( _features[dim] );
         }
       }
       else //we have examples x dimes (as usually done)
@@ -87,7 +92,7 @@ namespace NICE {
         for (uint nr = 0; nr < this->ui_n; nr++)
         {
           //loop over every dimension to add the specific value to the corresponding SortedVectorSparse
-          for (NICE::SparseVector::const_iterator elemIt = _X[nr]->begin(); elemIt != _X[nr]->end(); elemIt++)
+          for (NICE::SparseVector::const_iterator elemIt = _features[nr]->begin(); elemIt != _features[nr]->end(); elemIt++)
           {
             //elemIt->first: dim, elemIt->second: value
             this->features[elemIt->first].insert( (T) elemIt->second, nr);

+ 2 - 2
GPHIKClassifier.cpp

@@ -276,7 +276,7 @@ void GPHIKClassifier::classify ( const NICE::Vector * _example,
   {
     //do nothing
     _uncertainty = std::numeric_limits<double>::max();
-  }  
+  }
 }
 
 /** training process */
@@ -743,4 +743,4 @@ void GPHIKClassifier::addMultipleExamples( const std::vector< const NICE::Sparse
   {
     this->gphyper->addMultipleExamples( _newExamples, _newLabels, _performOptimizationAfterIncrement );     
   }
-}
+}

+ 2 - 2
quantization/Quantization1DAequiDist0To1.cpp

@@ -49,7 +49,7 @@ uint Quantization1DAequiDist0To1::quantize ( double _value,
   else if ( _value >= 1.0 ) 
     return this->ui_numBins-1;
   else 
-    return (uint)( _value * (this->ui_numBins-1) + 0.5 );
+    return static_cast<uint> ( _value * (this->ui_numBins-1) + 0.5 );
 }
 
 void Quantization1DAequiDist0To1::computeParametersFromData ( const NICE::FeatureMatrix *  _fm )
@@ -111,4 +111,4 @@ void Quantization1DAequiDist0To1::store ( std::ostream & _os,
     
   // done
   _os << this->createEndTag( "Quantization1DAequiDist0To1" ) << std::endl;
-}
+}

+ 2 - 2
quantization/Quantization1DAequiDist0ToMax.cpp

@@ -53,7 +53,7 @@ uint Quantization1DAequiDist0ToMax::quantize ( double _value,
   else if ( _value >= this->v_upperBounds[0] ) 
     return this->ui_numBins-1;
   else 
-    return (uint)( _value/this->v_upperBounds[0]  * (this->ui_numBins-1) + 0.5 );
+    return static_cast<uint> ( floor( _value/this->v_upperBounds[0]  * (this->ui_numBins-1) + 0.5 ) );
 }
 
 
@@ -119,4 +119,4 @@ void Quantization1DAequiDist0ToMax::store ( std::ostream & _os,
     
   // done
   _os << this->createEndTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
-}
+}

+ 2 - 2
quantization/QuantizationNDAequiDist0ToMax.cpp

@@ -49,7 +49,7 @@ uint QuantizationNDAequiDist0ToMax::quantize ( double _value,
   else if ( _value >= this->v_upperBounds[_dim] ) 
     return this->ui_numBins-1;
   else 
-    return (uint)( _value/this->v_upperBounds[_dim]  * (this->ui_numBins-1) + 0.5 );
+      return static_cast<uint> ( floor( _value/this->v_upperBounds[_dim]  * (this->ui_numBins-1) + 0.5 ) );
 }
 
 
@@ -124,4 +124,4 @@ void QuantizationNDAequiDist0ToMax::store ( std::ostream & _os,
     
   // done
   _os << this->createEndTag( "QuantizationNDAequiDist0ToMax" ) << std::endl;
-}
+}