Struct cont_arith_code::distribution::gaussian::Gaussian

source ·
pub struct Gaussian {
    pub s0: usize,
    pub s1: i64,
    pub s2: u128,
    pub ddof: u8,
    pub mean: f64,
    pub stdev: f64,
}
Expand description

Numerically stable Gaussian distribution

Fields§

§s0: usize

Number of values

§s1: i64

Sum of values

§s2: u128

Sum of squares

§ddof: u8

0 if values are population, 1 if sample

§mean: f64

s1 / s0

§stdev: f64

sqrt( (s2 - (s1^2)/s0) / s0 - ddof )

Implementations§

source§

impl Gaussian

source

pub fn variance(&self) -> f64

source

pub fn mle<I>(data: I, ddof: u8) -> Self
where I: Iterator<Item = i64>,

One pass fit (Max Likelihood Estimation) of a Gaussian to given data, given the desired delta-degree-of-freedom (0 if data is the whole population, 1 if data is a sample)

source

pub fn pdf(&self, x: f64) -> f64

PDF of the normal

source

pub fn cdf(&self, x: f64) -> f64

CDF of the normal

source

pub fn log_cdf(&self, x: f64) -> f64

log-CDF of the normal

source

pub fn log_pdf(&self, x: f64) -> f64

source

pub fn log_survival(&self, x: f64) -> f64

Log of the complement of the CDF of the normal

source

pub fn log_probability(&self, lo: f64, hi: f64) -> f64

Returns a numerically stable log(abs(cdf(hi) - cdf(lo)))

source

pub fn quantile(&self, cp: f64) -> f64

source

pub fn q_cdf(&self, q: usize, x: f64) -> usize

Returns the index of the bin from a division of the curve into q subsets of equal probability

source

pub fn q_quantile(&self, q: usize, i: usize) -> f64

Returns the i’th q’tile of self, i.e. the value at the boundary between the ith and the i+1th bin of equal 1/q probability for this Gaussian. Input i should be between 1 and q-1 for a real value: i=0 will return f64::NEG_INFINITY and i=q will return f64::INFINITY. Call with q*2 and i*2 + 1 to get the middle of the bin above the boundary

source

pub fn lerp(&self, lo: f64, hi: f64, cp: f64) -> f64

Does a linear interpolation on the area under the curve of the PDF of the gaussian between two points. Does the computation in log-scale so we’re numerically stable in the tails

source

pub fn definite_integral(&self, lo: f64, hi: f64) -> f64

Definite integral (equiv. to self.cdf(hi) - self.cdf(lo))

source

pub fn translate(&self, d: f64) -> Gaussian

Translate the distribution to the right (positive) or to the left (negative) by adding a given amount to the mean

source

pub fn bits(&self, s: Index) -> f64

Count the information (bits) of a given index in the Gaussian, i.e. the log-probability of the +/-0.5 interval around an integer, in base 2

Trait Implementations§

source§

impl Clone for Gaussian

source§

fn clone(&self) -> Gaussian

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Gaussian

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Model<i64> for Gaussian

source§

fn push(&mut self, s: i64) -> Option<i64>

Push a value into the model and updates its state. Returns a values once it’s been fully described by a series of indexes.
source§

fn next_distr(&mut self) -> Box<dyn UnivariateDistribution>

Get the distribution for the next symbol from the model.
source§

impl PartialEq for Gaussian

source§

fn eq(&self, other: &Gaussian) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Gaussian

source§

fn partial_cmp(&self, other: &Gaussian) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl UnivariateDistribution for Gaussian

source§

impl Copy for Gaussian

source§

impl StructuralPartialEq for Gaussian

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,