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 
00040 
00063 class Vector_Quantizer
00064 {
00065 public:
00067   Vector_Quantizer();
00069   Vector_Quantizer(const char *Name);
00071   int encode(const vec &x);
00073   ivec encode(const vec &x, int num);
00075   vec decode(int Index) const;
00077   Array<vec> decode(const ivec &Index) const;
00079   vec Q(const vec &x);
00081   vec operator()(const vec &x);
00083   void set_codebook(const mat &CB);
00085   mat get_codebook() const;
00087   void set_codevector(int Index, const vec &indata);
00089   vec get_codevector(int Index) const;
00091   void modify_codevector(int no, double mul, const vec &add);
00093   int size() const;
00095   int dim() const;
00097   int nobits() const;
00104   void load(const char *Name);
00111   void save(const char *Name) const;
00113   double latest_distortion();
00114 protected:
00116   vec CodeBook;
00118   int Size;
00120   int Dim;
00122   double LatestDist;
00123 };
00124 
00125 // INLINE FUNCTIONS
00126 
00127 inline int Vector_Quantizer::size() const { return Size; }
00128 inline int Vector_Quantizer::nobits() const { return levels2bits(Size); }
00129 inline int Vector_Quantizer::dim() const { return Dim; }
00130 inline double Vector_Quantizer::latest_distortion() { return LatestDist; }
00131 inline vec Vector_Quantizer::decode(int Index) const { return get_codevector(Index); }
00132 inline vec Vector_Quantizer::Q(const vec &x) { return decode(encode(x)); }
00133 inline vec Vector_Quantizer::operator()(const vec &x) { return Q(x); }
00134 
00153 class Scalar_Quantizer
00154 {
00155 public:
00157   Scalar_Quantizer();
00159   Scalar_Quantizer(const char *Name);
00161   int encode(double x) const;
00163   ivec encode(const vec &x) const;
00165   double decode(int Index) const;
00167   vec decode(const ivec &Index) const;
00169   double Q(double x) const;
00171   vec Q(const vec &x) const;
00173   double operator()(double x) const;
00175   vec operator()(const vec &x) const;
00177   void set_levels(const vec &L);
00179   vec get_levels() const;
00181   int size() const;
00182 protected:
00184   vec Levels;
00186   double LatestDist;
00187 };
00188 
00189 inline int Scalar_Quantizer::size() const { return Levels.length(); }
00190 inline double Scalar_Quantizer::decode(int Index) const { return Levels(Index); }
00191 inline double Scalar_Quantizer::Q(double x) const { return decode(encode(x)); }
00192 inline double Scalar_Quantizer::operator()(double x) const { return Q(x); }
00193 inline vec Scalar_Quantizer::operator()(const vec &x)  const { return Q(x); }
00194 inline void Scalar_Quantizer::set_levels(const vec &L) {Levels = L;sort(Levels); }
00195 inline vec Scalar_Quantizer::get_levels() const {return Levels; }
00196 
00198 int scalar_encode(double x, vec &Levels) ;
00200 ivec scalar_encode(vec &x, vec &Levels);
00202 inline double scalar_quantize(double x, vec &Levels) { return Levels(scalar_encode(x, Levels)); }
00204 inline vec scalar_quantize(vec &x, vec &Levels) { return Levels(scalar_encode(x, Levels)); }
00205 
00206 
00207 } // namespace itpp
00208 
00209 #endif // #ifndef VQ_H
SourceForge Logo

Generated on Thu Apr 23 20:06:44 2009 for IT++ by Doxygen 1.5.8