vq.h
Go to the documentation of this file.
#ifndef VQ_H
#define VQ_H
#include <itpp/base/vec.h>
#include <itpp/base/sort.h>
#include <itpp/base/math/log_exp.h>
#include <itpp/itexports.h>
namespace itpp
{
class ITPP_EXPORT Vector_Quantizer
{
public:
Vector_Quantizer();
Vector_Quantizer(const char *Name);
int encode(const vec &x);
ivec encode(const vec &x, int num);
vec decode(int Index) const;
Array<vec> decode(const ivec &Index) const;
vec Q(const vec &x);
vec operator()(const vec &x);
void set_codebook(const mat &CB);
mat get_codebook() const;
void set_codevector(int Index, const vec &indata);
vec get_codevector(int Index) const;
void modify_codevector(int no, double mul, const vec &add);
int size() const;
int dim() const;
int nobits() const;
void load(const char *Name);
void save(const char *Name) const;
double latest_distortion();
protected:
vec CodeBook;
int Size;
int Dim;
double LatestDist;
};
// INLINE FUNCTIONS
inline int Vector_Quantizer::size() const { return Size; }
inline int Vector_Quantizer::nobits() const { return levels2bits(Size); }
inline int Vector_Quantizer::dim() const { return Dim; }
inline double Vector_Quantizer::latest_distortion() { return LatestDist; }
inline vec Vector_Quantizer::decode(int Index) const { return get_codevector(Index); }
inline vec Vector_Quantizer::Q(const vec &x) { return decode(encode(x)); }
inline vec Vector_Quantizer::operator()(const vec &x) { return Q(x); }
class ITPP_EXPORT Scalar_Quantizer
{
public:
Scalar_Quantizer();
Scalar_Quantizer(const char *Name);
int encode(double x) const;
ivec encode(const vec &x) const;
double decode(int Index) const;
vec decode(const ivec &Index) const;
double Q(double x) const;
vec Q(const vec &x) const;
double operator()(double x) const;
vec operator()(const vec &x) const;
void set_levels(const vec &L);
vec get_levels() const;
int size() const;
protected:
vec Levels;
double LatestDist;
};
inline int Scalar_Quantizer::size() const { return Levels.length(); }
inline double Scalar_Quantizer::decode(int Index) const { return Levels(Index); }
inline double Scalar_Quantizer::Q(double x) const { return decode(encode(x)); }
inline double Scalar_Quantizer::operator()(double x) const { return Q(x); }
inline vec Scalar_Quantizer::operator()(const vec &x) const { return Q(x); }
inline void Scalar_Quantizer::set_levels(const vec &L) {Levels = L;sort(Levels); }
inline vec Scalar_Quantizer::get_levels() const {return Levels; }
ITPP_EXPORT int scalar_encode(double x, vec &Levels) ;
ITPP_EXPORT ivec scalar_encode(vec &x, vec &Levels);
inline double scalar_quantize(double x, vec &Levels) { return Levels(scalar_encode(x, Levels)); }
inline vec scalar_quantize(vec &x, vec &Levels) { return Levels(scalar_encode(x, Levels)); }
} // namespace itpp
#endif // #ifndef VQ_H
itpp::Array< vec >
itpp::Name
Automatic naming when saving.
Definition: itfile.h:429
itpp::Scalar_Quantizer
Class for vector quantization.
Definition: vq.h:153
itpp::Scalar_Quantizer::size
int size() const
Returns the size (number of codevectors) of the VQ.
Definition: vq.h:188
itpp::Scalar_Quantizer::encode
ivec encode(const vec &x) const
Encode the input vector.
itpp::Scalar_Quantizer::LatestDist
double LatestDist
The distortion at the latest time a vector was encoded.
Definition: vq.h:185
itpp::Scalar_Quantizer::encode
int encode(double x) const
Encode.
itpp::Scalar_Quantizer::Q
vec Q(const vec &x) const
Quantize the input vector.
itpp::Scalar_Quantizer::set_levels
void set_levels(const vec &L)
Initialize the codebook by a matrix.
Definition: vq.h:193
itpp::Scalar_Quantizer::Q
double Q(double x) const
Quantize.
Definition: vq.h:190
itpp::Scalar_Quantizer::decode
double decode(int Index) const
Decode the index.
Definition: vq.h:189
itpp::Scalar_Quantizer::decode
vec decode(const ivec &Index) const
Decode the indices.
itpp::Scalar_Quantizer::Scalar_Quantizer
Scalar_Quantizer(const char *Name)
Create a VQ from a VQ file.
itpp::Scalar_Quantizer::Levels
vec Levels
The vector containing the code book.
Definition: vq.h:183
itpp::Scalar_Quantizer::operator()
double operator()(double x) const
Quantize.
Definition: vq.h:191
itpp::Scalar_Quantizer::Scalar_Quantizer
Scalar_Quantizer()
Default constructor.
itpp::Scalar_Quantizer::get_levels
vec get_levels() const
Returns the codebook.
Definition: vq.h:194
itpp::Vector_Quantizer
Class for vector quantization.
Definition: vq.h:63
itpp::Vector_Quantizer::modify_codevector
void modify_codevector(int no, double mul, const vec &add)
Rescale and translate a codevector.
itpp::Vector_Quantizer::dim
int dim() const
Returns the dimension of the VQ.
Definition: vq.h:128
itpp::Vector_Quantizer::operator()
vec operator()(const vec &x)
Quantize the input vector.
Definition: vq.h:132
itpp::Vector_Quantizer::get_codevector
vec get_codevector(int Index) const
Returns the codevector at the given index.
itpp::Vector_Quantizer::nobits
int nobits() const
Returns the number of bits of the VQ [log2(size)/dim].
Definition: vq.h:127
itpp::Vector_Quantizer::decode
vec decode(int Index) const
Decode the index.
Definition: vq.h:130
itpp::Vector_Quantizer::set_codebook
void set_codebook(const mat &CB)
Initialize the codebook by a matrix.
itpp::Vector_Quantizer::encode
int encode(const vec &x)
Encode the input vector.
itpp::Vector_Quantizer::encode
ivec encode(const vec &x, int num)
Encode the input vector, and return the num best indices.
itpp::Vector_Quantizer::Q
vec Q(const vec &x)
Quantize the input vector.
Definition: vq.h:131
itpp::Vector_Quantizer::set_codevector
void set_codevector(int Index, const vec &indata)
Set a codevector in the codebook.
itpp::Vector_Quantizer::Size
int Size
The size of the code book.
Definition: vq.h:117
itpp::Vector_Quantizer::load
void load(const char *Name)
Load the codebook from a file.
itpp::Vector_Quantizer::latest_distortion
double latest_distortion()
Returns the distortion at the latest time a vector was encoded.
Definition: vq.h:129
itpp::Vector_Quantizer::save
void save(const char *Name) const
Save the codebook to a file.
itpp::Vector_Quantizer::Vector_Quantizer
Vector_Quantizer(const char *Name)
Create a VQ from a VQ file.
itpp::Vector_Quantizer::get_codebook
mat get_codebook() const
Returns the codebook.
itpp::Vector_Quantizer::Vector_Quantizer
Vector_Quantizer()
Default constructor.
itpp::Vector_Quantizer::size
int size() const
Returns the size (number of codevectors) of the VQ.
Definition: vq.h:126
itpp::Vector_Quantizer::CodeBook
vec CodeBook
The vector containing the code book.
Definition: vq.h:115
itpp::Vector_Quantizer::LatestDist
double LatestDist
The distortion at the latest time a vector was encoded.
Definition: vq.h:121
itpp::Vector_Quantizer::Dim
int Dim
The dimension of the code book.
Definition: vq.h:119
itpp::Vector_Quantizer::decode
Array< vec > decode(const ivec &Index) const
Decode the indices.
itpp::levels2bits
int levels2bits(int n)
Calculate the number of bits needed to represent n different values (levels).
Definition: log_exp.h:92
itpp::size
int size(const Vec< T > &v)
Length of vector.
Definition: matfunc.h:55
log_exp.h
Logarithmic and exponenential functions - header file.
itpp
itpp namespace
Definition: itmex.h:37
itpp::scalar_encode
ITPP_EXPORT int scalar_encode(double x, vec &Levels)
ADD DOCUMENTATION HERE.
itpp::scalar_quantize
double scalar_quantize(double x, vec &Levels)
ADD DOCUMENTATION HERE.
Definition: vq.h:201
sort.h
Sorting functions.
vec.h
Templated Vector Class Definitions.

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.1