In this repository there are various implementations of the Linde, Buzo, and Gray algorithm (generalize Lloyd-Max algorithm) for the calculation of vector quantizer.
- Requirements -
-
Manual
Download this repository:
git clone git@github.com:XaBerr/LGB-methods.git
and compile it running:
rm build/ -rf;cmake -S . -B build;make -C build;
-
CMake module
Module data:
FetchContent_Declare( "LGB-methods" GIT_REPOSITORY https://github.com/XaBerr/LGB-methods.git GIT_TAG 1.0.0 )
All include file are avaiable in the include
directory.
You can include each library individually:
#include <LGB-methods/LGB.h>
#include <LGB-methods/LGBrandom.h>
#include <LGB-methods/LGBsplit.h>
using namespace LGBm;
or using the single include:
#include <LGB-methods.h>
using namespace LGBm;
These are the algorithms implemented until now:
- LGB
- LGB-random
- LGB-split
First you need to initialize the quantizer.
LGB<float> quantizer;
std::vector<float> signal = {1, 0, 2, 0, 3, 0, 4, 0};
std::vector<std::vector<float>> initialPoints = {{1, 0}, {2, 0}, {3, 0}, {4, 0}};
quantizer.rate = 1;
quantizer.nDimension = 2;
Then you can import the signal.
quantizer.vectorize(signal);
In the end you can run the LGB algorithm and print the result.
quantizer.run(initialPoints);
quantizer.printVectorPoints(quantizer.codebook);
First you must initialize the quantizer.
LGBrandom<float> quantizer;
std::vector<float> signal = {1, 0, 2, 0, 3, 0, 4, 0};
std::vector<std::vector<float>> initialPoints = {{1, 0}, {2, 0}, {3, 0}, {4, 0}};
quantizer.rate = 1;
quantizer.nDimension = 2;
Then you can import the signal.
quantizer.vectorize(signal);
In the end you can run the LGB algorithm and print the result.
quantizer.run();
quantizer.printVectorPoints(quantizer.codebook);
First you must initialize the quantizer.
LGBsplit<float> quantizer;
std::vector<float> signal = {1, 0, 2, 0, 3, 0, 4, 0};
std::vector<std::vector<float>> initialPoints = {{1, 0}, {2, 0}, {3, 0}, {4, 0}};
quantizer.rate = 1;
quantizer.nDimension = 2;
Then you can import the signal.
quantizer.vectorize(signal);
In the end you can run the LGB algorithm and print the result.
quantizer.run();
quantizer.printVectorPoints(quantizer.codebook);
Here we have the parameters and theirs default values.
// number of bit per sample
rate = 2;
// the size of the vectors
nDimension = 2;
// the maximum error allowed
threshold = 0.01;
// max iteration limits
maxRuns = 10;
maxZeroRuns = 5;
In addition for the LGB-split we have this parameter.
// the size of the jump during the split
perturbation = 0.01;
- -2: Generated a cluster with zero elements
- -1: Biggest cluster has zero size
- +0: Finish without reaching distortion or threshold limit
- +1: Stopped because distortion start increasing
- +2: Stopped because threshold reached
Also check out the example in apps/example.cpp
.