Struct constriction::stream::model::LeakilyQuantizedDistribution [−][src]
pub struct LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, const PRECISION: usize> { /* fields omitted */ }
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
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
Probability: BitArray + Into<F>,
Symbol: PrimInt + AsPrimitive<Probability> + WrappingSub + WrappingAdd,
F: Float, [src]
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
Probability: BitArray + Into<F>,
Symbol: PrimInt + AsPrimitive<Probability> + WrappingSub + WrappingAdd,
F: Float, [src]pub fn quantizer(&self) -> &'q LeakyQuantizer<F, Symbol, Probability, PRECISION>[src]
pub fn quantizer(&self) -> &'q LeakyQuantizer<F, Symbol, Probability, PRECISION>[src]Returns the quantizer that was used to create this entropy model.
You may want to reuse this quantizer to quantize further probability distributions.
pub fn inner(&self) -> &D[src]
pub fn inner(&self) -> &D[src]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
pub fn inner_mut(&mut self) -> &mut D[src]
pub fn inner_mut(&mut self) -> &mut D[src]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
pub fn into_inner(self) -> D[src]
pub fn into_inner(self) -> D[src]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
pub fn support(&self) -> RangeInclusive<Symbol>[src]
pub fn support(&self) -> RangeInclusive<Symbol>[src]Returns the exact range of symbols that have nonzero probability.
Trait Implementations
impl<'q, F: Clone, Symbol: Clone, Probability: Clone, D: Clone, const PRECISION: usize> Clone for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]
impl<'q, F: Clone, Symbol: Clone, Probability: Clone, D: Clone, const PRECISION: usize> Clone for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]fn clone(
&self
) -> LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]
fn clone(
&self
) -> LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]Performs copy-assignment from source. Read more
impl<'q, F: Debug, Symbol: Debug, Probability: Debug, D: Debug, const PRECISION: usize> Debug for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]
impl<'q, F: Debug, Symbol: Debug, Probability: Debug, D: Debug, const PRECISION: usize> Debug for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]impl<'q, Symbol, Probability, D, const PRECISION: usize> DecoderModel<PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]
impl<'q, Symbol, Probability, D, const PRECISION: usize> DecoderModel<PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]impl<'q, Symbol, Probability, D, const PRECISION: usize> EncoderModel<PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]
impl<'q, Symbol, Probability, D, const PRECISION: usize> EncoderModel<PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]fn left_cumulative_and_probability(
&self,
symbol: impl Borrow<Symbol>
) -> Option<(Probability, Probability::NonZero)>[src]
fn left_cumulative_and_probability(
&self,
symbol: impl Borrow<Symbol>
) -> Option<(Probability, Probability::NonZero)>[src]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).
fn floating_point_probability<F>(&self, symbol: Self::Symbol) -> F where
F: Float,
Self::Probability: Into<F>, [src]
fn floating_point_probability<F>(&self, symbol: Self::Symbol) -> F where
F: Float,
Self::Probability: Into<F>, [src]Returns the probability of the given symbol in floating point representation. Read more
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> EntropyModel<PRECISION> for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
Probability: BitArray, [src]
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> EntropyModel<PRECISION> for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
Probability: BitArray, [src]type Probability = Probability
type Probability = ProbabilityThe type used to represent probabilities, cumulatives, and quantiles. Read more
impl<'m, 'q: 'm, Symbol, Probability, D, const PRECISION: usize> IterableEntropyModel<'m, PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]
impl<'m, 'q: 'm, Symbol, Probability, D, const PRECISION: usize> IterableEntropyModel<'m, PRECISION> for LeakilyQuantizedDistribution<'q, 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>, [src]type Iter = LeakilyQuantizedDistributionIter<Symbol, Probability, &'m Self, PRECISION>
type Iter = LeakilyQuantizedDistributionIter<Symbol, Probability, &'m Self, PRECISION>The type of the iterator returned by symbol_table. Read more
fn symbol_table(&'m self) -> Self::Iter[src]
fn symbol_table(&'m self) -> Self::Iter[src]Iterates over all symbols in the unique order that is consistent with the cumulative distribution. Read more
fn floating_point_symbol_table<F>(
&'m self
) -> FloatingPointSymbolTable<F, Self::Iter, PRECISION>ⓘNotable traits for FloatingPointSymbolTable<F, I, PRECISION>
impl<F, Symbol, Probability, I, const PRECISION: usize> Iterator for FloatingPointSymbolTable<F, I, PRECISION> where
F: Float,
Probability: BitArray + Into<F>,
I: Iterator<Item = (Symbol, Probability, <Probability as BitArray>::NonZero)>, type Item = (Symbol, F, F); where
F: From<Self::Probability>, [src]
fn floating_point_symbol_table<F>(
&'m self
) -> FloatingPointSymbolTable<F, Self::Iter, PRECISION>ⓘNotable traits for FloatingPointSymbolTable<F, I, PRECISION>
impl<F, Symbol, Probability, I, const PRECISION: usize> Iterator for FloatingPointSymbolTable<F, I, PRECISION> where
F: Float,
Probability: BitArray + Into<F>,
I: Iterator<Item = (Symbol, Probability, <Probability as BitArray>::NonZero)>, type Item = (Symbol, F, F); where
F: From<Self::Probability>, [src]Similar to symbol_table, but yields both cumulatives and probabilities in
floating point representation. Read more
fn entropy_base2<F>(&'m self) -> F where
F: Float + Sum,
Self::Probability: Into<F>, [src]
fn entropy_base2<F>(&'m self) -> F where
F: Float + Sum,
Self::Probability: Into<F>, [src]Returns the entropy in units of bits (i.e., base 2). Read more
fn to_generic_encoder_model(
&'m self
) -> NonContiguousCategoricalEncoderModel<Self::Symbol, Self::Probability, PRECISION> where
Self::Symbol: Hash + Eq, [src]
fn to_generic_encoder_model(
&'m self
) -> NonContiguousCategoricalEncoderModel<Self::Symbol, Self::Probability, PRECISION> where
Self::Symbol: Hash + Eq, [src]Creates an EncoderModel from this EntropyModel Read more
fn to_generic_decoder_model(
&'m self
) -> NonContiguousCategoricalDecoderModel<Self::Symbol, Self::Probability, Vec<(Self::Probability, Self::Symbol)>, PRECISION> where
Self::Symbol: Clone, [src]
fn to_generic_decoder_model(
&'m self
) -> NonContiguousCategoricalDecoderModel<Self::Symbol, Self::Probability, Vec<(Self::Probability, Self::Symbol)>, PRECISION> where
Self::Symbol: Clone, [src]Creates a DecoderModel from this EntropyModel Read more
fn to_generic_lookup_decoder_model(
&'m self
) -> LookupDecoderModel<Self::Symbol, Self::Probability, NonContiguousSymbolTable<Vec<(Self::Probability, Self::Symbol)>>, Box<[Self::Probability]>, PRECISION> where
Self::Probability: Into<usize>,
usize: AsPrimitive<Self::Probability>,
Self::Symbol: Copy + Default, [src]
fn to_generic_lookup_decoder_model(
&'m self
) -> LookupDecoderModel<Self::Symbol, Self::Probability, NonContiguousSymbolTable<Vec<(Self::Probability, Self::Symbol)>>, Box<[Self::Probability]>, PRECISION> where
Self::Probability: Into<usize>,
usize: AsPrimitive<Self::Probability>,
Self::Symbol: Copy + Default, [src]Creates a DecoderModel from this EntropyModel Read more
impl<'q, F: Copy, Symbol: Copy, Probability: Copy, D: Copy, const PRECISION: usize> Copy for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION>[src]
Auto Trait Implementations
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> RefUnwindSafe for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
D: RefUnwindSafe,
F: RefUnwindSafe,
Probability: RefUnwindSafe,
Symbol: RefUnwindSafe,
D: RefUnwindSafe,
F: RefUnwindSafe,
Probability: RefUnwindSafe,
Symbol: RefUnwindSafe,
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> Send for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
D: Send,
F: Sync,
Probability: Sync,
Symbol: Sync,
D: Send,
F: Sync,
Probability: Sync,
Symbol: Sync,
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> Sync for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
D: Sync,
F: Sync,
Probability: Sync,
Symbol: Sync,
D: Sync,
F: Sync,
Probability: Sync,
Symbol: Sync,
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> Unpin for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
D: Unpin,
D: Unpin,
impl<'q, F, Symbol, Probability, D, const PRECISION: usize> UnwindSafe for LeakilyQuantizedDistribution<'q, F, Symbol, Probability, D, PRECISION> where
D: UnwindSafe,
F: RefUnwindSafe,
Probability: RefUnwindSafe,
Symbol: RefUnwindSafe,
D: UnwindSafe,
F: RefUnwindSafe,
Probability: RefUnwindSafe,
Symbol: RefUnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more