00001 00029 #ifndef VQ_H 00030 #define VQ_H 00031 00032 #include <itpp/base/vec.h> 00033 #include <itpp/base/sort.h> 00034 #include <itpp/base/math/log_exp.h> 00035 00036 namespace itpp 00037 { 00038 00039 00062 class Vector_Quantizer 00063 { 00064 public: 00066 Vector_Quantizer(); 00068 Vector_Quantizer(const char *Name); 00070 int encode(const vec &x); 00072 ivec encode(const vec &x, int num); 00074 vec decode(int Index) const; 00076 Array<vec> decode(const ivec &Index) const; 00078 vec Q(const vec &x); 00080 vec operator()(const vec &x); 00082 void set_codebook(const mat &CB); 00084 mat get_codebook() const; 00086 void set_codevector(int Index, const vec &indata); 00088 vec get_codevector(int Index) const; 00090 void modify_codevector(int no, double mul, const vec &add); 00092 int size() const; 00094 int dim() const; 00096 int nobits() const; 00103 void load(const char *Name); 00110 void save(const char *Name) const; 00112 double latest_distortion(); 00113 protected: 00115 vec CodeBook; 00117 int Size; 00119 int 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 00152 class Scalar_Quantizer 00153 { 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 00197 int scalar_encode(double x, vec &Levels) ; 00199 ivec scalar_encode(vec &x, vec &Levels); 00201 inline double scalar_quantize(double x, vec &Levels) { return Levels(scalar_encode(x, Levels)); } 00203 inline vec scalar_quantize(vec &x, vec &Levels) { return Levels(scalar_encode(x, Levels)); } 00204 00205 00206 } // namespace itpp 00207 00208 #endif // #ifndef VQ_H
Generated on Wed Jul 27 2011 16:27:05 for IT++ by Doxygen 1.7.4