Struct easy_ml::distributions::Gaussian
source · [−]Expand description
A Gaussian probability density function of a normally distributed random variable with expected value / mean μ, and variance σ2.
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
sourceimpl<T: Numeric + Real> Gaussian<T>
impl<T: Numeric + Real> Gaussian<T>
pub fn new(mean: T, variance: T) -> Gaussian<T>
sourcepub fn approximating<I>(data: I) -> Gaussian<T> where
I: Iterator<Item = T>,
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.
sourceimpl<T: Numeric + Real> Gaussian<T> where
for<'a> &'a T: NumericRef<T> + RealRef<T>,
impl<T: Numeric + Real> Gaussian<T> where
for<'a> &'a T: NumericRef<T> + RealRef<T>,
sourcepub fn probability(&self, x: &T) -> T
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.
sourcepub fn draw<I>(&self, source: &mut I, max_samples: usize) -> Option<Vec<T>> where
I: Iterator<Item = T>,
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.
pub fn map(&self, x: &T) -> T
renamed to probability
Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more