Module rice

Source
Expand description

Rice codes.

Rice codes (AKA Golomb−Rice codes) are a form of approximated Golomb codes in which the parameter b is a power of two. This restriction makes the code less precise in modeling data with a geometric distribution, but encoding and decoding can be performed without any integer arithmetic, and thus much more quickly.

The implied distribution of a Rice code is the same as that of a Golomb code with the same parameter.

For natural numbers distributed with a geometric distribution with base p, the base-2 logarithm of the optimal b is ⌈log₂(ln((√5 + 1)/2) / ln(1 - p))⌉.

§References

Robert F. Rice, “Some practical universal noiseless coding techniques”. Jet Propulsion Laboratory, Pasadena, CA, Tech. Rep. JPL-79-22, JPL-83-17, and JPL-91-3, March 1979.

Aaron Kiely. “Selecting the Golomb parameter in Rice coding”. Interplanetary Network Progress report 42-159, Jet Propulsion Laboratory, 2004.

Traits§

RiceRead
Trait for reading Rice codes.
RiceWrite
Trait for writing Rice codes.

Functions§

len_rice
Returns the length of the Rice code for n with parameter log2_b.
log2_b
Returns the optimal value of log₂b for a geometric distribution of base p, that is, ⌈log₂(ln((√5 + 1)/2) / ln(1 - p))⌉