[][src]Struct easy_ml::distributions::Gaussian

pub struct Gaussian<T: Numeric + Real> {
    pub mean: T,
    pub variance: T,
}

A Gaussian probability density function of a normally distributed random variable with expected value / mean μ, and variance σ2.

See: https://en.wikipedia.org/wiki/Gaussian_function

Fields

mean: T

The mean is the expected value of this gaussian.

variance: T

The variance is a measure of the spread of values around the mean, high variance means one standard deviation encompasses a larger spread of values from the mean.

Methods

impl<T: Numeric + Real> Gaussian<T>[src]

pub fn new(mean: T, variance: T) -> Gaussian<T>[src]

pub fn approximating<I>(data: I) -> Gaussian<T> where
    I: Iterator<Item = T>, 
[src]

Creates a Gaussian approximating the mean and variance in the provided data.

Note that this will always be an approximation, if you generate some data according to some mean and variance then construct a Gaussian from the mean and variance of that generated data the approximated mean and variance is unlikely to be exactly the same as the parameters the data was generated with, though as the amout of data increases you can expect the approximation to be more close.

impl<T: Numeric + Real> Gaussian<T> where
    &'a T: NumericRef<T> + RealRef<T>, 
[src]

pub fn probability(&self, x: &T) -> T[src]

Computes g(x) for some x, the probability density of a normally distributed random variable x, or in other words how likely x is to be drawn from this normal distribution.

g(x) is largest for x equal to this distribution's mean and g(x) will tend towards zero as x is further from this distribution's mean, at a rate corresponding to this distribution's variance.

pub fn draw<I>(&self, source: &mut I, max_samples: usize) -> Option<Vec<T>> where
    I: Iterator<Item = T>, 
[src]

Given a source of random variables in the uniformly distributed range [0, 1] inclusive, draws max_samples of independent random numbers according to this Gaussian distribution's mean and variance using the Box-Muller transform:

https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

The source of random variables must provide at least as many values as max_samples if max_samples is even, and one more than max_samples if max_samples is odd. If fewer are provided None is returned.

As all randomness is provided to this method, this code is deterministic and will always compute the same samples given the same random source of numbers.

Example of generating and feeding random numbers

pub fn map(&self, x: &T) -> T[src]

Deprecated since 1.1.0:

renamed to probability

Trait Implementations

impl<T: Debug + Numeric + Real> Debug for Gaussian<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Gaussian<T> where
    T: RefUnwindSafe

impl<T> Send for Gaussian<T> where
    T: Send

impl<T> Sync for Gaussian<T> where
    T: Sync

impl<T> Unpin for Gaussian<T> where
    T: Unpin

impl<T> UnwindSafe for Gaussian<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.