Struct constriction::stream::model::LeakilyQuantizedDistribution
source · pub struct LeakilyQuantizedDistribution<F, Symbol, Probability, D, const PRECISION: usize> { /* private fields */ }
Expand description
An EntropyModel
that approximates a parameterized probability Distribution
.
A LeakilyQuantizedDistribution
can be created with a LeakyQuantizer
. It can be
used for encoding and decoding with any of the stream codes provided by the
constriction
crate (it can only be used for decoding if the underlying
Distribution
implements the the trait Inverse
from the probability
crate).
When Should I Use This Type of Entropy Model?
Use a LeakilyQuantizedDistribution
when you have a probabilistic model that is defined
through some analytic expression (e.g., a mathematical formula for the probability
density function of a continuous probability distribution, or a mathematical formula for
the probability mass functions of some discrete probability distribution). Examples of
probabilistic models that lend themselves to being quantized are continuous
distributions such as Gaussian
, Laplace
, or Exponential
, as well as discrete
distributions with some analytic expression, such as Binomial
.
Do not use a LeakilyQuantizedDistribution
if your probabilistic model can only be
presented as an explicit probability table. While you could, in principle, apply a
LeakyQuantizer
to such a Categorical
distribution, you will get better
computational performance (and also slightly better compression effectiveness) if you
instead use one of the dedicated types ContiguousCategoricalEntropyModel
,
NonContiguousCategoricalEncoderModel
, NonContiguousCategoricalDecoderModel
, or
LookupDecoderModel
.
Examples
See examples for LeakyQuantizer
.
Computational Efficiency
Implementations§
source§impl<F, Symbol, Probability, D, const PRECISION: usize> LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>where
Probability: BitArray + Into<F>,
Symbol: PrimInt + AsPrimitive<Probability> + WrappingSub + WrappingAdd,
F: FloatCore,
impl<F, Symbol, Probability, D, const PRECISION: usize> LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>where
Probability: BitArray + Into<F>,
Symbol: PrimInt + AsPrimitive<Probability> + WrappingSub + WrappingAdd,
F: FloatCore,
sourcepub fn quantizer(self) -> LeakyQuantizer<F, Symbol, Probability, PRECISION>
pub fn quantizer(self) -> LeakyQuantizer<F, Symbol, Probability, PRECISION>
Returns the quantizer that was used to create this entropy model.
You may want to reuse this quantizer to quantize further probability distributions.
sourcepub fn inner(&self) -> &D
pub fn inner(&self) -> &D
Returns a reference to the underlying (floating-point) probability Distribution
.
Returns the floating-point probability distribution which this
LeakilyQuantizedDistribution
approximates in fixed-point arithmetic.
See also
sourcepub fn inner_mut(&mut self) -> &mut D
pub fn inner_mut(&mut self) -> &mut D
Returns a mutable reference to the underlying (floating-point) probability
Distribution
.
You can use this method to mutate parameters of the underlying Distribution
after it was already quantized. This is safe and cheap since quantization is done
lazily anyway. Note that you can’t mutate the support
since it is a
property of the LeakyQuantizer
, not of the Distribution
. If you want to modify
the support
then you have to create a new LeakyQuantizer
with a different support.
See also
sourcepub fn into_inner(self) -> D
pub fn into_inner(self) -> D
Consumes the entropy model and returns the underlying (floating-point) probability
Distribution
.
Returns the floating-point probability distribution which this
LeakilyQuantizedDistribution
approximates in fixed-point arithmetic.
See also
sourcepub fn support(&self) -> RangeInclusive<Symbol>
pub fn support(&self) -> RangeInclusive<Symbol>
Returns the exact range of symbols that have nonzero probability.
Trait Implementations§
source§impl<F: Clone, Symbol: Clone, Probability: Clone, D: Clone, const PRECISION: usize> Clone for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
impl<F: Clone, Symbol: Clone, Probability: Clone, D: Clone, const PRECISION: usize> Clone for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
source§fn clone(
&self
) -> LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
fn clone( &self ) -> LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<F: Debug, Symbol: Debug, Probability: Debug, D: Debug, const PRECISION: usize> Debug for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
impl<F: Debug, Symbol: Debug, Probability: Debug, D: Debug, const PRECISION: usize> Debug for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>
source§impl<Symbol, Probability, D, const PRECISION: usize> DecoderModel<PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + Into<f64> + WrappingSub + WrappingAdd,
Probability: BitArray + Into<f64>,
D: Inverse,
D::Value: AsPrimitive<Symbol>,
impl<Symbol, Probability, D, const PRECISION: usize> DecoderModel<PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + Into<f64> + WrappingSub + WrappingAdd,
Probability: BitArray + Into<f64>,
D: Inverse,
D::Value: AsPrimitive<Symbol>,
source§impl<Symbol, Probability, D, const PRECISION: usize> EncoderModel<PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + Into<f64> + WrappingSub,
Probability: BitArray + Into<f64>,
D: Distribution,
D::Value: AsPrimitive<Symbol>,
impl<Symbol, Probability, D, const PRECISION: usize> EncoderModel<PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + Into<f64> + WrappingSub,
Probability: BitArray + Into<f64>,
D: Distribution,
D::Value: AsPrimitive<Symbol>,
source§fn left_cumulative_and_probability(
&self,
symbol: impl Borrow<Symbol>
) -> Option<(Probability, Probability::NonZero)>
fn left_cumulative_and_probability( &self, symbol: impl Borrow<Symbol> ) -> Option<(Probability, Probability::NonZero)>
Performs (one direction of) the quantization.
Panics
Panics if it detects some invalidity in the underlying probability distribution.
This means that there is a bug in the implementation of Distribution
for the
distribution D
: the cumulative distribution function is either not monotonically
nondecreasing, returns NaN, or its values exceed the interval [0.0, 1.0]
at some
point.
More precisely, this method panics if the quantization procedure leads to a zero
probability despite the added leakiness (and despite the fact that the constructor
checks that min_symbol_inclusive < max_symbol_inclusive
, i.e., that there are at
least two symbols with nonzero probability and therefore the probability of a single
symbol should not be able to overflow).
source§fn floating_point_probability<F>(&self, symbol: Self::Symbol) -> F
fn floating_point_probability<F>(&self, symbol: Self::Symbol) -> F
source§impl<F, Symbol, Probability, D, const PRECISION: usize> EntropyModel<PRECISION> for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>where
Probability: BitArray,
impl<F, Symbol, Probability, D, const PRECISION: usize> EntropyModel<PRECISION> for LeakilyQuantizedDistribution<F, Symbol, Probability, D, PRECISION>where
Probability: BitArray,
source§impl<'m, 'q: 'm, Symbol, Probability, D, const PRECISION: usize> IterableEntropyModel<'m, PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + AsPrimitive<usize> + Into<f64> + WrappingSub,
Probability: BitArray + Into<f64>,
D: Distribution + 'm,
D::Value: AsPrimitive<Symbol>,
impl<'m, 'q: 'm, Symbol, Probability, D, const PRECISION: usize> IterableEntropyModel<'m, PRECISION> for LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>where
f64: AsPrimitive<Probability>,
Symbol: PrimInt + AsPrimitive<Probability> + AsPrimitive<usize> + Into<f64> + WrappingSub,
Probability: BitArray + Into<f64>,
D: Distribution + 'm,
D::Value: AsPrimitive<Symbol>,
§type Iter = LeakilyQuantizedDistributionIter<Symbol, Probability, &'m LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>, PRECISION>
type Iter = LeakilyQuantizedDistributionIter<Symbol, Probability, &'m LeakilyQuantizedDistribution<f64, Symbol, Probability, D, PRECISION>, PRECISION>
symbol_table
. Read moresource§fn symbol_table(&'m self) -> Self::Iter
fn symbol_table(&'m self) -> Self::Iter
source§fn floating_point_symbol_table<F>(
&'m self
) -> FloatingPointSymbolTable<F, Self::Iter, PRECISION> ⓘwhere
F: From<Self::Probability>,
fn floating_point_symbol_table<F>(
&'m self
) -> FloatingPointSymbolTable<F, Self::Iter, PRECISION> ⓘwhere
F: From<Self::Probability>,
symbol_table
, but yields both cumulatives and probabilities in
floating point representation. Read more