IT++ Logo Newcom Logo

vq.h

Go to the documentation of this file.
00001 
00033 #ifndef VQ_H
00034 #define VQ_H
00035 
00036 #include <itpp/base/vec.h>
00037 #include <itpp/base/sort.h>
00038 
00039 
00040 namespace itpp {
00041 
00042 
00065 class Vector_Quantizer {
00066 public:
00068         Vector_Quantizer();
00070         Vector_Quantizer(const char *Name);
00072         int encode(const vec &x);
00074         ivec encode(const vec &x, int num);
00076         vec decode(int Index) const;
00078         Array<vec> decode(const ivec &Index) const;
00080         vec Q(const vec &x);
00082         vec operator()(const vec &x);
00084         void set_codebook(const mat &CB);
00086         mat get_codebook() const;
00088         void set_codevector(int Index, const vec &indata);
00090         vec get_codevector(int Index) const;
00092         void modify_codevector(int no, double mul, const vec &add);
00094         int size() const;
00096         int dim() const;
00098         int nobits() const;
00105         void load(const char *Name);
00112         void save(const char *Name) const;
00114         double latest_distortion();
00115 protected:
00117         vec CodeBook;
00119         int Size,Dim;
00121         double LatestDist;
00122 };
00123 
00124 // INLINE FUNCTIONS
00125 
00126 inline int Vector_Quantizer::size() const { return Size; }
00127 inline int Vector_Quantizer::nobits() const { return levels2bits(Size); }
00128 inline int Vector_Quantizer::dim() const { return Dim; }
00129 inline double Vector_Quantizer::latest_distortion()     { return LatestDist; }
00130 inline vec Vector_Quantizer::decode(int Index) const { return get_codevector(Index); }
00131 inline vec Vector_Quantizer::Q(const vec &x) { return decode(encode(x)); }
00132 inline vec Vector_Quantizer::operator()(const vec &x) { return Q(x); }
00133 
00134 
00153 class Scalar_Quantizer {
00154 public:
00156         Scalar_Quantizer();
00158         Scalar_Quantizer(const char *Name);
00160         int encode(double x) const;
00162         ivec encode(const vec &x) const;
00164         double decode(int Index) const;
00166         vec decode(const ivec &Index) const;
00168         double Q(double x) const;
00170         vec Q(const vec &x) const;
00172         double operator()(double x) const;
00174         vec operator()(const vec &x) const;
00176         void set_levels(const vec &L);
00178         vec get_levels() const;
00180         int size() const;
00181 protected:
00183         vec Levels;
00185         double LatestDist;
00186 };
00187 
00188 inline int Scalar_Quantizer::size() const { return Levels.length(); }
00189 inline double Scalar_Quantizer::decode(int Index) const { return Levels(Index); }
00190 inline double Scalar_Quantizer::Q(double x) const { return decode(encode(x)); }
00191 inline double Scalar_Quantizer::operator()(double x) const { return Q(x); }
00192 inline vec Scalar_Quantizer::operator()(const vec &x)  const { return Q(x); }
00193 inline void Scalar_Quantizer::set_levels(const vec &L) {Levels=L;sort(Levels); }
00194 inline vec Scalar_Quantizer::get_levels() const {return Levels; }
00195 
00196 
00197 int scalar_encode(double x, vec &Levels) ;
00198 ivec scalar_encode(vec &x, vec &Levels);
00199 inline double scalar_quantize(double x, vec &Levels) { return Levels(scalar_encode(x,Levels)); }
00200 inline vec scalar_quantize(vec &x, vec &Levels) { return Levels(scalar_encode(x,Levels)); }
00201 
00202 
00203 } // namespace itpp
00204 
00205 #endif // #ifndef VQ_H
SourceForge Logo

Generated on Thu Apr 19 14:19:55 2007 for IT++ by Doxygen 1.4.6