Browse Source

unstable commit towards flexible quantizations

Alexander Freytag 9 years ago
parent
commit
788b83e9a4

+ 7 - 16
Quantization.cpp

@@ -16,9 +16,10 @@ Quantization::Quantization( )
   this->ui_numBins = 1;
 }
 
-Quantization::Quantization( uint _numBins )
+Quantization::Quantization( uint _numBins,
+                            NICE::Vector * v_upperBounds = NULL
+                          )
 {
-  this->ui_numBins = _numBins;
 }
 
 Quantization::~Quantization()
@@ -29,22 +30,12 @@ uint Quantization::size() const
 {
   return this->ui_numBins;
 }
-  
-double Quantization::getPrototype (uint _bin) const
-{
-  return _bin / (double)(this->ui_numBins-1);
-}
-  
-uint Quantization::quantize (double _value) const
+
+uint Quantization::getNumberOfBins() const
 {
-  if ( _value <= 0.0 ) 
-    return 0;
-  else if ( _value >= 1.0 ) 
-    return this->ui_numBins-1;
-  else 
-    return (uint)( _value * (this->ui_numBins-1) + 0.5 );
+  return this->ui_numBins;
 }
-
+ 
 // ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
 
 void Quantization::restore ( std::istream & _is, 

+ 17 - 4
Quantization.h

@@ -10,6 +10,8 @@
 // NICE-core includes
 #include <core/basics/types.h>
 #include <core/basics/Persistent.h>
+// 
+#include <core/vector/VectorT.h>
 
 namespace NICE {
   
@@ -31,6 +33,12 @@ class Quantization  : public NICE::Persistent
   protected:
 
     uint ui_numBins;
+    
+    // NOTE: we do not need lower bounds, 
+    // since our features are required to be non-negative 
+    // (for applying the HIK as kernel function)
+    NICE::Vector v_upperBounds;    
+    
 
   public:
 
@@ -47,8 +55,10 @@ class Quantization  : public NICE::Persistent
    * @author Erik Rodner
    * @date 
    */
-  Quantization( uint _numBins );
-    
+  Quantization( uint _numBins, 
+                NICE::Vector * v_upperBounds = NULL
+              );
+
   /** simple destructor */
   virtual ~Quantization();
 
@@ -56,6 +66,7 @@ class Quantization  : public NICE::Persistent
   * @brief get the size of the vocabulary, i.e. the number of bins
   */
   virtual uint size() const;
+  virtual uint getNumberOfBins() const;  
 
   /**
   * @brief get specific word or prototype element of the quantization
@@ -64,7 +75,7 @@ class Quantization  : public NICE::Persistent
   *
   * @return value of the prototype
   */
-  virtual double getPrototype (uint _bin) const;
+  virtual double getPrototype (uint _bin) const = 0;
 
   /**
   * @brief Determine for a given signal value the bin in the vocabulary. This is not the corresponding prototype, which 
@@ -74,7 +85,9 @@ class Quantization  : public NICE::Persistent
   *
   * @return index of the bin entry corresponding to the given signal value
   */
-  virtual uint quantize (double _value) const;
+  virtual uint quantize ( double _value, 
+                          const uint & _dim
+                        ) const = 0;
   
   ///////////////////// INTERFACE PERSISTENT /////////////////////
   // interface specific methods for store and restore

+ 114 - 0
quantization/Quantization1DAequiDist0To1.cpp

@@ -0,0 +1,114 @@
+/** 
+* @file Quantization1DAequiDist0To1.cpp
+* @brief Quantization1DAequiDist0To1 of one-dimensional signals with a standard range of [0,1] (Implementation)
+* @author Erik Rodner, Alexander Freytag
+* @date 01/09/2012
+
+*/
+#include <iostream>
+
+#include "Quantization1DAequiDist0To1.h"
+
+using namespace NICE;
+
+Quantization1DAequiDist0To1::Quantization1DAequiDist0To1( ) 
+{
+  this->ui_numBins = 1;
+}
+
+Quantization1DAequiDist0To1::Quantization1DAequiDist0To1( 
+                               uint _numBins, 
+                               NICE::Vector * v_upperBounds
+                             )
+{
+  this->ui_numBins = _numBins;
+  //
+  // this class does not require any upper bounds...
+}
+
+Quantization1DAequiDist0To1::~Quantization1DAequiDist0To1()
+{
+}
+
+uint Quantization1DAequiDist0To1::size() const
+{
+  return this->ui_numBins;
+}
+  
+double Quantization1DAequiDist0To1::getPrototype (uint _bin) const
+{
+  return _bin / (double)(this->ui_numBins-1);
+}
+  
+uint Quantization1DAequiDist0To1::quantize ( double _value,
+                                             const uint & _dim
+                                           ) const
+{
+  //  _dim will be ignored for this type of quantization. all dimensions are treated equally...
+  
+  if ( _value <= 0.0 ) 
+    return 0;
+  else if ( _value >= 1.0 ) 
+    return this->ui_numBins-1;
+  else 
+    return (uint)( _value * (this->ui_numBins-1) + 0.5 );
+}
+
+// ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
+
+void Quantization1DAequiDist0To1::restore ( std::istream & _is, 
+                             int _format 
+                           )
+{
+  if ( _is.good() )
+  {    
+    std::string tmp;    
+
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      _is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "Quantization1DAequiDist0To1" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }                  
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( tmp.compare("Quantization") == 0 )
+      {
+        // restore parent object
+        Quantization::restore(is);
+      }       
+      else
+      {
+        std::cerr << "WARNING -- unexpected Quantization1DAequiDist0To1 object -- " << tmp << " -- for restoration... aborting" << std::endl;
+        throw;  
+      }
+      
+      _is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );      
+    }
+   }
+  else
+  {
+    std::cerr << "Quantization1DAequiDist0To1::restore -- InStream not initialized - restoring not possible!" << std::endl;
+  }
+}
+
+void Quantization1DAequiDist0To1::store ( std::ostream & _os, 
+                           int _format 
+                         ) const
+{
+  // show starting point
+  _os << this->createStartTag( "Quantization1DAequiDist0To1" ) << std::endl;
+  
+  // store parent object
+  Quantization::store(os); 
+    
+  // done
+  _os << this->createEndTag( "Quantization1DAequiDist0To1" ) << std::endl;
+}

+ 73 - 0
quantization/Quantization1DAequiDist0To1.h

@@ -0,0 +1,73 @@
+/** 
+* @file Quantization1DAequiDist0To1.h
+* @brief Quantization of one-dimensional signals with a standard range of [0,1] (Interface)
+* @author Erik Rodner, Alexander Freytag
+* @date 01/09/2012
+*/
+#ifndef _NICE_QUANTIZATIONINCLUDE
+#define _NICE_QUANTIZATIONINCLUDE
+
+// NICE-core includes
+#include <core/basics/types.h>
+#include <core/basics/Persistent.h>
+
+#include "gp-hik-core/Quantization.h"
+
+namespace NICE {
+  
+ /** 
+ * @class Quantization
+ * @brief Quantization of one-dimensional signals with a standard range of [0,1]
+ * @author Erik Rodner, Alexander Freytag
+ */
+ 
+class Quantization1DAequiDist0To1  : public NICE::Quantization
+{
+
+  /** TODO
+   * The current implementation only provides uniform quantization. We could extend this
+   * by giving a ParameterizedFunction object to the constructor, which would allow us to inverse transform function values
+   * before performing the binning.
+   */
+
+  protected:
+
+  public:
+
+  /** 
+   * @brief default constructor
+   * @author Alexander Freytag
+   * @date 06-02-2014
+   */
+  
+  Quantization1DAequiDist0To1( );
+  
+  /**
+   * @brief simple constructor
+   * @author Erik Rodner
+   * @date 
+   */
+  Quantization1DAequiDist0To1( uint _numBins, 
+                               NICE::Vector * v_upperBounds = NULL
+                              );
+    
+  /** simple destructor */
+  virtual ~Quantization1DAequiDist0To1();
+  
+  ///////////////////// INTERFACE PERSISTENT /////////////////////
+  // interface specific methods for store and restore
+  ///////////////////// INTERFACE PERSISTENT /////////////////////
+  virtual void restore ( std::istream & _is, 
+                         int _format = 0 
+                       );
+  virtual void store ( std::ostream & _os, 
+                       int _format = 0 
+                     ) const; 
+  virtual void clear () {};    
+
+ 
+};
+
+}
+
+#endif

+ 117 - 0
quantization/Quantization1DAequiDist0ToMax.cpp

@@ -0,0 +1,117 @@
+/** 
+* @file Quantization1DAequiDist0ToMax.cpp
+* @brief Quantization1DAequiDist0ToMax of one-dimensional signals with a standard range of [0,1] (Implementation)
+* @author Erik Rodner, Alexander Freytag
+* @date 01/09/2012
+
+*/
+#include <iostream>
+
+#include "Quantization1DAequiDist0ToMax.h"
+
+using namespace NICE;
+
+Quantization1DAequiDist0ToMax::Quantization1DAequiDist0ToMax( ) 
+{
+  this->ui_numBins = 1;
+}
+
+Quantization1DAequiDist0ToMax::Quantization1DAequiDist0ToMax( 
+                               uint _numBins, 
+                               NICE::Vector * _upperBounds
+                             )
+{
+  this->ui_numBins = _numBins;
+  this->v_upperBounds.resize ( 1 );
+  if ( (_upperBounds != NULL)  && (_upperBounds->size() > 0) )
+    this->v_upperBounds(0) = *_upperBounds(0);
+  else
+    this->v_upperBounds(0) = 1.0;
+}
+
+Quantization1DAequiDist0ToMax::~Quantization1DAequiDist0ToMax()
+{
+}
+
+uint Quantization1DAequiDist0ToMax::size() const
+{
+  return this->ui_numBins;
+}
+  
+double Quantization1DAequiDist0ToMax::getPrototype (uint _bin) const
+{
+  return _bin / (double)(this->ui_numBins-1);
+}
+  
+uint Quantization1DAequiDist0ToMax::quantize ( double _value,
+                                             const uint & _dim
+                                           ) const
+{
+  //  _dim will be ignored for this type of quantization. all dimensions are treated equally...
+  
+  if ( _value <= 0.0 ) 
+    return 0;
+  else if ( _value >= 1.0 ) 
+    return this->ui_numBins-1;
+  else 
+    return (uint)( _value * (this->ui_numBins-1) + 0.5 );
+}
+
+// ---------------------- STORE AND RESTORE FUNCTIONS ----------------------
+
+void Quantization1DAequiDist0ToMax::restore ( std::istream & _is, 
+                             int _format 
+                           )
+{
+  if ( _is.good() )
+  {    
+    std::string tmp;    
+
+    bool b_endOfBlock ( false ) ;
+    
+    while ( !b_endOfBlock )
+    {
+      _is >> tmp; // start of block 
+      
+      if ( this->isEndTag( tmp, "Quantization1DAequiDist0ToMax" ) )
+      {
+        b_endOfBlock = true;
+        continue;
+      }                  
+      
+      tmp = this->removeStartTag ( tmp );
+      
+      if ( tmp.compare("Quantization") == 0 )
+      {
+        // restore parent object
+        Quantization::restore(is);
+      }       
+      else
+      {
+        std::cerr << "WARNING -- unexpected Quantization1DAequiDist0ToMax object -- " << tmp << " -- for restoration... aborting" << std::endl;
+        throw;  
+      }
+      
+      _is >> tmp; // end of block 
+      tmp = this->removeEndTag ( tmp );      
+    }
+   }
+  else
+  {
+    std::cerr << "Quantization1DAequiDist0ToMax::restore -- InStream not initialized - restoring not possible!" << std::endl;
+  }
+}
+
+void Quantization1DAequiDist0ToMax::store ( std::ostream & _os, 
+                           int _format 
+                         ) const
+{
+  // show starting point
+  _os << this->createStartTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
+  
+  // store parent object
+  Quantization::store(os); 
+    
+  // done
+  _os << this->createEndTag( "Quantization1DAequiDist0ToMax" ) << std::endl;
+}

+ 73 - 0
quantization/Quantization1DAequiDist0ToMax.h

@@ -0,0 +1,73 @@
+/** 
+* @file Quantization1DAequiDist0ToMax.h
+* @brief Quantization of one-dimensional signals with a standard range of [0,1] (Interface)
+* @author Erik Rodner, Alexander Freytag
+* @date 01/09/2012
+*/
+#ifndef _NICE_QUANTIZATIONINCLUDE
+#define _NICE_QUANTIZATIONINCLUDE
+
+// NICE-core includes
+#include <core/basics/types.h>
+#include <core/basics/Persistent.h>
+
+#include "gp-hik-core/Quantization.h"
+
+namespace NICE {
+  
+ /** 
+ * @class Quantization
+ * @brief Quantization of one-dimensional signals with a standard range of [0,1]
+ * @author Erik Rodner, Alexander Freytag
+ */
+ 
+class Quantization1DAequiDist0ToMax  : public NICE::Quantization
+{
+
+  /** TODO
+   * The current implementation only provides uniform quantization. We could extend this
+   * by giving a ParameterizedFunction object to the constructor, which would allow us to inverse transform function values
+   * before performing the binning.
+   */
+
+  protected:
+
+  public:
+
+  /** 
+   * @brief default constructor
+   * @author Alexander Freytag
+   * @date 06-02-2014
+   */
+  
+  Quantization1DAequiDist0ToMax( );
+  
+  /**
+   * @brief simple constructor
+   * @author Erik Rodner
+   * @date 
+   */
+  Quantization1DAequiDist0ToMax( uint _numBins, 
+                               NICE::Vector * v_upperBounds = NULL
+                              );
+    
+  /** simple destructor */
+  virtual ~Quantization1DAequiDist0ToMax();
+  
+  ///////////////////// INTERFACE PERSISTENT /////////////////////
+  // interface specific methods for store and restore
+  ///////////////////// INTERFACE PERSISTENT /////////////////////
+  virtual void restore ( std::istream & _is, 
+                         int _format = 0 
+                       );
+  virtual void store ( std::ostream & _os, 
+                       int _format = 0 
+                     ) const; 
+  virtual void clear () {};    
+
+ 
+};
+
+}
+
+#endif