Struct rusty_machine::stats::dist::gaussian::Gaussian
[−]
[src]
pub struct Gaussian { /* fields omitted */ }
A Gaussian random variable.
This struct stores both the variance and the standard deviation. This is to minimize the computation required for computing the distribution functions and sampling.
It is most efficient to construct the struct using the from_std_dev
constructor.
Methods
impl Gaussian
[src]
fn new(mean: f64, variance: f64) -> Gaussian
Creates a new Gaussian random variable from a given mean and variance.
fn from_std_dev(mean: f64, std_dev: f64) -> Gaussian
Creates a new Gaussian random variable from a given mean and standard deviation.
Trait Implementations
impl Debug for Gaussian
[src]
impl Clone for Gaussian
[src]
fn clone(&self) -> Gaussian
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Gaussian
[src]
impl Default for Gaussian
[src]
The default Gaussian random variable. This is the Standard Normal random variable.
The defaults are:
- mean = 0
- variance = 1
impl Distribution<f64> for Gaussian
[src]
The distribution of the gaussian random variable.
Accurately computes the PDF and log PDF. Estimates the CDF accurate only to 0.003.
fn pdf(&self, x: f64) -> f64
The pdf of the normal distribution
Examples
use rusty_machine::stats::dist::Gaussian; use rusty_machine::stats::dist::Distribution; use rusty_machine::stats::dist::consts; let gauss = Gaussian::default(); let lpdf_zero = gauss.pdf(0f64); // The value should be very close to 1/sqrt(2 * pi) assert!((lpdf_zero - (1f64/consts::SQRT_2_PI).abs()) < 1e-20);
fn logpdf(&self, x: f64) -> f64
The log pdf of the normal distribution.
Examples
use rusty_machine::stats::dist::Gaussian; use rusty_machine::stats::dist::Distribution; use rusty_machine::stats::dist::consts; let gauss = Gaussian::default(); let lpdf_zero = gauss.logpdf(0f64); // The value should be very close to -0.5*Ln(2 * pi) assert!((lpdf_zero + 0.5*consts::LN_2_PI).abs() < 1e-20);
fn cdf(&self, x: f64) -> f64
Rough estimate for the cdf of the gaussian distribution. Accurate to 0.003.
Examples
use rusty_machine::stats::dist::Gaussian; use rusty_machine::stats::dist::Distribution; let gauss = Gaussian::new(10f64, 5f64); let cdf_mid = gauss.cdf(10f64); assert!((0.5 - cdf_mid).abs() < 0.004);
A slightly more involved test:
use rusty_machine::stats::dist::Gaussian; use rusty_machine::stats::dist::Distribution; let gauss = Gaussian::new(10f64, 4f64); let cdf = gauss.cdf(9f64); assert!((0.5*(1f64 - 0.382924922548) - cdf).abs() < 0.004);
impl Sample<f64> for Gaussian
[src]
fn sample<R: Rng>(&mut self, rng: &mut R) -> f64
Generate a random value of Support
, using rng
as the source of randomness. Read more
impl IndependentSample<f64> for Gaussian
[src]
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64
Generate a random value.