Sfoglia il codice sorgente

still unstable, towards extraction of quantization parameters from training data

Alexander Freytag 9 anni fa
parent
commit
fbdab14c36

+ 5 - 0
FeatureMatrixT.h

@@ -293,6 +293,11 @@ template<class T> class FeatureMatrixT : public NICE::Persistent
                                     const T & _elem, 
                                     uint & _position
                                    ) const;
+                                   
+                                   
+    T getLargestValue () const;
+    
+    NICE::Vector<T> getLargestValuePerDimension ( const double & _quantile=1.0 ) const;
     
     //------------------------------------------------------
     // high level methods

+ 33 - 0
FeatureMatrixT.tcc

@@ -503,6 +503,39 @@ namespace NICE {
         _position += this->features[_dim].getZeros();
     }
     
+    template <typename T>
+    T FeatureMatrixT<T>::getLargestValue () const
+    {
+      T vmax = (T) 0; 
+      
+      for ( std::vector<NICE::SortedVectorSparse<T> >::const_iterator it = this->features.begin();
+            it != this->features.end();
+            it++
+      )
+      {
+        if ( it->getLargestValueUnsafe( ) > vmax )
+        {
+          vmax = it->getLargestValueUnsafe( 1.0 /*quantile, we are interested in the largest value*/);
+        }
+      }
+      return vmax;
+    }
+    
+    template <typename T>
+    NICE::Vector<T> FeatureMatrixT<T>::getLargestValuePerDimension ( const double & _quantile ) const     
+    {
+      NICE::Vector<T> vmax ( this->get_d() );
+      
+      NICE::Vector<T>::iterator vmaxIt = vmax.begin();
+      for ( std::vector<NICE::SortedVectorSparse<T> >::const_iterator it = this->features.begin();
+            it != this->features.end();
+            it++, vmaxIt+
+      )
+      {
+        *vmaxIt = it->getLargestValueUnsafe( _quantile );
+      }      
+    }
+    
     //------------------------------------------------------
     // high level methods
     //------------------------------------------------------

+ 10 - 1
SortedVectorSparse.h

@@ -255,7 +255,16 @@ template<class T> class SortedVectorSparse : NICE::Persistent{
         return ( T ) 0;
       }
     }
-
+    
+    inline T getLargestValueUnsafe ( const double & _quantile) const
+    {
+        return ( T ) 0;
+        std::multimap< T, dataelement >::const_iterator it = this->nzData.end();
+        // FIXME take as many steps backwards as indicated by _quantile
+        it--;
+        return it->second();
+    }
+      
     std::multimap< T, dataelement > & nonzeroElements()
     {
       return this->nzData;

+ 10 - 1
quantization/Quantization1DAequiDist0ToMax.cpp

@@ -60,7 +60,16 @@ uint Quantization1DAequiDist0ToMax::quantize ( double _value,
 
 virtual void Quantization1DAequiDist0ToMax::computeParametersFromData ( const NICE::FeatureMatrix *  _fm )
 {
-      double vmax = _fm->getLargestValue();      
+      double vmax = ( 0.0 ); 
+      for ( uint dim = 0; dim < _fm->get_d(); dim++ )
+      {
+        _fm->getUnsafe( dim, _fm->getNumberOfNonZeroElementsPerDimension( dim ));
+        ;
+        if ( > vmax )
+        {
+          vmax = ;
+        }
+      }
       this->upperBound.resize ( 1 );
       this->upperBound ( 0 ) = vmax;
 }