XaBerr / generalized-lloyd-max-methods

Linde, Buzo, and Gray algorithm for vector quantization.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo

LGB-methods

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 -


Installation

  • 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
    )

Inclusion

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;

Usage

These are the algorithms implemented until now:

  • LGB
  • LGB-random
  • LGB-split

LGB

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);

LGB-random

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);

LGB-split

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);

The LGB parameters

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;

Exiting status for the run method

  • -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

Example

Also check out the example in apps/example.cpp.

About

Linde, Buzo, and Gray algorithm for vector quantization.

License:MIT License


Languages

Language:C++ 92.1%Language:CMake 7.9%