IT++ Logo

vq.h

Go to the documentation of this file.
00001 
00030 #ifndef VQ_H
00031 #define VQ_H
00032 
00033 #include <itpp/base/vec.h>
00034 #include <itpp/base/sort.h>
00035 #include <itpp/base/math/log_exp.h>
00036 
00037 namespace itpp {
00038 
00039 
00062   class Vector_Quantizer {
00063   public:
00065     Vector_Quantizer();
00067     Vector_Quantizer(const char *Name);
00069     int encode(const vec &x);
00071     ivec encode(const vec &x, int num);
00073     vec decode(int Index) const;
00075     Array<vec> decode(const ivec &Index) const;
00077     vec Q(const vec &x);
00079     vec operator()(const vec &x);
00081     void set_codebook(const mat &CB);
00083     mat get_codebook() const;
00085     void set_codevector(int Index, const vec &indata);
00087     vec get_codevector(int Index) const;
00089     void modify_codevector(int no, double mul, const vec &add);
00091     int size() const;
00093     int dim() const;
00095     int nobits() const;
00102     void load(const char *Name);
00109     void save(const char *Name) const;
00111     double latest_distortion();
00112   protected:
00114     vec CodeBook;
00116     int Size;
00118     int Dim;
00120     double LatestDist;
00121   };
00122 
00123   // INLINE FUNCTIONS
00124 
00125   inline int Vector_Quantizer::size() const { return Size; }
00126   inline int Vector_Quantizer::nobits() const { return levels2bits(Size); }
00127   inline int Vector_Quantizer::dim() const { return Dim; }
00128   inline double Vector_Quantizer::latest_distortion()   { return LatestDist; }
00129   inline vec Vector_Quantizer::decode(int Index) const { return get_codevector(Index); }
00130   inline vec Vector_Quantizer::Q(const vec &x) { return decode(encode(x)); }
00131   inline vec Vector_Quantizer::operator()(const vec &x) { return Q(x); }
00132 
00151   class Scalar_Quantizer {
00152   public:
00154     Scalar_Quantizer();
00156     Scalar_Quantizer(const char *Name);
00158     int encode(double x) const;
00160     ivec encode(const vec &x) const;
00162     double decode(int Index) const;
00164     vec decode(const ivec &Index) const;
00166     double Q(double x) const;
00168     vec Q(const vec &x) const;
00170     double operator()(double x) const;
00172     vec operator()(const vec &x) const;
00174     void set_levels(const vec &L);
00176     vec get_levels() const;
00178     int size() const;
00179   protected:
00181     vec Levels;
00183     double LatestDist;
00184   };
00185 
00186   inline int Scalar_Quantizer::size() const { return Levels.length(); }
00187   inline double Scalar_Quantizer::decode(int Index) const { return Levels(Index); }
00188   inline double Scalar_Quantizer::Q(double x) const { return decode(encode(x)); }
00189   inline double Scalar_Quantizer::operator()(double x) const { return Q(x); }
00190   inline vec Scalar_Quantizer::operator()(const vec &x)  const { return Q(x); }
00191   inline void Scalar_Quantizer::set_levels(const vec &L) {Levels=L;sort(Levels); }
00192   inline vec Scalar_Quantizer::get_levels() const {return Levels; }
00193 
00195   int scalar_encode(double x, vec &Levels) ;
00197   ivec scalar_encode(vec &x, vec &Levels);
00199   inline double scalar_quantize(double x, vec &Levels) { return Levels(scalar_encode(x,Levels)); }
00201   inline vec scalar_quantize(vec &x, vec &Levels) { return Levels(scalar_encode(x,Levels)); }
00202 
00203 
00204 } // namespace itpp
00205 
00206 #endif // #ifndef VQ_H
SourceForge Logo

Generated on Thu Apr 24 13:39:01 2008 for IT++ by Doxygen 1.5.5