[Paper Review] Understanding Entropy Coding With Asymmetric Numeral Systems (ANS): a Statistician's Perspective
This paper presents a statistical, latent variable model-based perspective on Asymmetric Numeral Systems (ANS) entropy coding, enabling machine learning researchers to understand and implement ANS more intuitively. It introduces a novel implementation in Python, generalizes ANS via the bits-back trick, and evaluates a high-performance open-source library (constriction) that achieves near-optimal compression with significantly faster runtime than Arithmetic Coding.
Entropy coding is the backbone data compression. Novel machine-learning based compression methods often use a new entropy coder called Asymmetric Numeral Systems (ANS) [Duda et al., 2015], which provides very close to optimal bitrates and simplifies [Townsend et al., 2019] advanced compression techniques such as bits-back coding. However, researchers with a background in machine learning often struggle to understand how ANS works, which prevents them from exploiting its full versatility. This paper is meant as an educational resource to make ANS more approachable by presenting it from a new perspective of latent variable models and the so-called bits-back trick. We guide the reader step by step to a complete implementation of ANS in the Python programming language, which we then generalize for more advanced use cases. We also present and empirically evaluate an open-source library of various entropy coders designed for both research and production use. Related teaching videos and problem sets are available online.
Motivation & Objective
- To make Asymmetric Numeral Systems (ANS) more accessible to machine learning and statistical researchers unfamiliar with algorithmic compression.
- To reframe ANS using latent variable models and the bits-back trick, providing a conceptual bridge between declarative modeling and procedural coding.
- To enable novel ANS variants by decomposing the algorithm into three steps of the bits-back framework.
- To develop and empirically evaluate an open-source, production-ready entropy coding library (constriction) for research and deployment.
- To demonstrate that ANS and Range Coding outperform Arithmetic Coding in speed while maintaining near-optimal compression performance.
Proposed method
- Reinterprets ANS as an application of the bits-back trick, decomposing it into three steps: encoding as posterior sampling, compression as bits-back, and decoding as inference.
- Presents a full, runnable Python implementation of ANS (Listing 3.3) that illustrates the algorithm step-by-step using real code.
- Generalizes ANS by recombining the three bits-back steps in new ways, enabling new compression patterns and model architectures.
- Introduces a lookup-table optimization for categorical entropy models to accelerate decoding in high-entropy regimes.
- Employs a binary search for symbol lookup in low-precision models and provides a configurable trade-off between memory and speed.
- Develops and benchmarks the constriction library, which supports both Python and Rust, and offers multiple entropy coders with binary compatibility.
Experimental results
Research questions
- RQ1How can ANS be understood and implemented from a statistical, latent variable modeling perspective?
- RQ2Can the bits-back trick framework be used to generalize ANS and enable new compression techniques?
- RQ3How does the performance of ANS compare to Arithmetic Coding and Range Coding in terms of bitrate and speed across varying entropy levels?
- RQ4What are the practical trade-offs in implementing ANS with different precision settings and lookup strategies?
- RQ5Can a unified, high-performance entropy coding library be built that supports both research prototyping and production deployment?
Key findings
- The constriction library achieves near-optimal compression performance with bitrates very close to the theoretical entropy limit.
- ANS and Range Coding are significantly faster than Arithmetic Coding, especially in high-entropy regimes where Arithmetic Coding degrades due to bit-level operations.
- Decoding with ANS slows down in high-entropy regimes due to binary search over symbol intervals, but this is mitigated by using precomputed lookup tables for low-precision models.
- The lookup table approach reduces decoding time to constant time but increases memory usage and hurts performance in low-entropy regimes due to poor cache behavior.
- The library’s default configuration offers a strong balance between speed, memory, and compression efficiency, making it suitable for initial prototyping.
- The bits-back perspective enables new ANS variants by recombining the three algorithmic steps, opening new pathways for research in structured compression.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.