Skip to main content

Module codebook

Module codebook 

Source
Expand description

Codebook lookup, Beta PDF, and pre-computed tables for Lloyd-Max quantization.

After applying a random rotation to a d-dimensional unit vector, each coordinate follows a Beta-type distribution on [-1, 1]:

f_X(x) = Gamma(d/2) / (sqrt(pi) * Gamma((d-1)/2)) * (1 - x^2)^((d-3)/2)

This module stores pre-computed Lloyd-Max codebooks for common (bits, dim) pairs and provides lookup / nearest-centroid queries. The generation algorithm itself lives in the [gen] sub-module.

Structs§

Codebook
A static codebook: sorted centroids and the decision boundaries between them. For k centroids there are k-1 interior boundaries; the outer boundaries are implicitly -1 and +1.

Functions§

beta_pdf
Evaluate the Beta-type PDF of a rotated unit-vector coordinate.
generate_codebook
Run the Lloyd-Max algorithm from scratch for arbitrary (bits, dim).
get_codebook
Return a pre-computed Codebook for the given (bits, dim) pair.
nearest_centroid
Find the index of the nearest centroid for a scalar value.