Gaussian

Struct Gaussian 

Source
pub struct Gaussian<T: Real> {
    pub mean: T,
    pub variance: T,
}
Expand description

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.

Implementations§

Source§

impl<T: Real> Gaussian<T>

Source

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

Source

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

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.

Source§

impl<T: Real> Gaussian<T>
where for<'a> &'a T: RealRef<T>,

Source

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

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.

Source

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

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

Source

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

👎Deprecated since 1.1.0: renamed to probability

Trait Implementations§

Source§

impl<T: Clone + Real> Clone for Gaussian<T>

Source§

fn clone(&self) -> Gaussian<T>

Returns a duplicate 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<T: Debug + Real> Debug for Gaussian<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Gaussian<T>
where T: Freeze,

§

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§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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.