Skip to main content

Module lloyd

Module lloyd 

Source
Expand description

Lloyd-Max optimal scalar quantizer tables for N(0,1), precomputed offline.

Centroids and decision boundaries are computed via Lloyd’s algorithm (2000 iterations, convergence tolerance 1e-12) on the standard normal distribution, then embedded as constants. No runtime training pass.

4-bit: 16 centroids / 15 boundaries. 2-bit: 4 centroids / 3 boundaries.

Constants§

BOUNDARIES_4BIT
4-bit decision boundaries (index i separates centroid i-1 and i).
BOUNDARIES_5BIT
5-bit decision boundaries.
BOUNDARIES_6BIT
6-bit decision boundaries.
CENTROIDS_4BIT
4-bit Lloyd-Max centroids for N(0,1).
CENTROIDS_5BIT
5-bit Lloyd-Max centroids for N(0,1).
CENTROIDS_6BIT
6-bit Lloyd-Max centroids for N(0,1).

Functions§

boundaries
Decision boundaries for a bit width.
centroids
Codebook centroids for a bit width (alias of the per-width constants).
dequantize
Dequantize a code at the given bit width (direct centroid index).
dequantize_4bit
Dequantize a 4-bit index back to its centroid value.
levels
Number of codebook levels for a supported bit width (4 -> 16, 5 -> 32, 6 -> 64).
quantize
Quantize one N(0,1) value at the given bit width via binary search.
quantize_4bit
Quantize one N(0,1)-distributed value to a 4-bit index via binary search over the decision boundaries.