LEX: Fast scalar quantization by grouping and local exchanges
Least-squares scalar quantization represents N values by k bin means while minimizing squared error. Exact algorithms solve this problem in one dimension, but large inputs can still be costly in time or memory. The LEX algorithm merges adjacent values into a smaller set of coarse groups, partitions the groups' weighted means by an exact dynamic program (DP), and refines the resulting cuts through single and paired boundary moves. Merge steps are batched for speed, and values sharing a rounded key can be grouped to accelerate the merges. We compare LEX with a table-free exact solver on three synthetic distributions, an audio recording, and two neural-network weight matrices, with N up to about 8.4 million and k ≤ 512. Across 81 fits, the relative excess error was at most 0.0040% for full-precision LEX. Across 102 fits, it was at most 0.0056% for precision-grouped LEX. On four inputs of 8.2 to 8.4 million values, with k ∈ {16, 32, 64, 128, 256, 512}, precision-grouped LEX was 54 to 169 times faster than the exact solver, excluding the shared sort, and 5.8 to 20 times faster including it. On those inputs its peak process memory was 99 to 223 MiB, against 510 to 1,299 MiB for the exact solver. The LEX C++ library has a Scala port and Python and R interfaces.
Authors
- N. Sriram (ORCID: https://orcid.org/0009-0001-8909-0676)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-11-25
- DOI
- https://doi.org/10.5281/zenodo.24543219
- Primary Topic
- Advanced Clustering Algorithms Research
- Type
- preprint