Struct rv::dist::Gaussian[][src]

pub struct Gaussian { /* fields omitted */ }

Gaussian / Normal distribution, N(μ, σ) over real values.

Examples

Compute the KL Divergence between two Gaussians.

use rv::prelude::*;

let gauss_1 = Gaussian::new(0.1, 2.3).unwrap();
let gauss_2 = Gaussian::standard();

// KL is not symmetric
let kl_12 = gauss_1.kl(&gauss_2);
let kl_21 = gauss_2.kl(&gauss_1);

// ... but kl_sym is because it's the sum of KL(P|Q) and KL(Q|P)
let kl_sym = gauss_1.kl_sym(&gauss_2);
assert!((kl_sym - (kl_12 + kl_21)).abs() < 1E-12);

Implementations

impl Gaussian[src]

pub fn new(mu: f64, sigma: f64) -> Result<Self, GaussianError>[src]

Create a new Gaussian distribution

Aruments

  • mu: mean
  • sigma: standard deviation

pub fn new_unchecked(mu: f64, sigma: f64) -> Self[src]

Creates a new Gaussian without checking whether the parameters are valid.

pub fn standard() -> Self[src]

Standard normal

Example

let gauss = Gaussian::standard();

assert_eq!(gauss, Gaussian::new(0.0, 1.0).unwrap());

pub fn mu(&self) -> f64[src]

Get mu parameter

Example

let gauss = Gaussian::new(2.0, 1.5).unwrap();

assert_eq!(gauss.mu(), 2.0);

pub fn set_mu(&mut self, mu: f64) -> Result<(), GaussianError>[src]

Set the value of mu

Example

let mut gauss = Gaussian::new(2.0, 1.5).unwrap();
assert_eq!(gauss.mu(), 2.0);

gauss.set_mu(1.3).unwrap();
assert_eq!(gauss.mu(), 1.3);

Will error for invalid values

assert!(gauss.set_mu(1.3).is_ok());
assert!(gauss.set_mu(std::f64::NEG_INFINITY).is_err());
assert!(gauss.set_mu(std::f64::INFINITY).is_err());
assert!(gauss.set_mu(std::f64::NAN).is_err());

pub fn set_mu_unchecked(&mut self, mu: f64)[src]

Set the value of mu without input validation

pub fn sigma(&self) -> f64[src]

Get sigma parameter

Example

let gauss = Gaussian::new(2.0, 1.5).unwrap();

assert_eq!(gauss.sigma(), 1.5);

pub fn set_sigma(&mut self, sigma: f64) -> Result<(), GaussianError>[src]

Set the value of sigma

Example

let mut gauss = Gaussian::standard();
assert_eq!(gauss.sigma(), 1.0);

gauss.set_sigma(2.3).unwrap();
assert_eq!(gauss.sigma(), 2.3);

Will error for invalid values

assert!(gauss.set_sigma(2.3).is_ok());
assert!(gauss.set_sigma(0.0).is_err());
assert!(gauss.set_sigma(-1.0).is_err());
assert!(gauss.set_sigma(std::f64::INFINITY).is_err());
assert!(gauss.set_sigma(std::f64::NEG_INFINITY).is_err());
assert!(gauss.set_sigma(std::f64::NAN).is_err());

pub fn set_sigma_unchecked(&mut self, sigma: f64)[src]

Set the value of sigma

Trait Implementations

impl Cdf<f32> for Gaussian[src]

impl Cdf<f64> for Gaussian[src]

impl Clone for Gaussian[src]

impl ConjugatePrior<f64, Gaussian> for NormalGamma[src]

type Posterior = Self

Type of the posterior distribution

type LnMCache = f64

Type of the ln_m cache

type LnPpCache = (GaussianSuffStat, f64)

Type of the ln_pp cache

impl ConjugatePrior<f64, Gaussian> for NormalInvChiSquared[src]

type Posterior = Self

Type of the posterior distribution

type LnMCache = f64

Type of the ln_m cache

type LnPpCache = (GaussianSuffStat, f64)

Type of the ln_pp cache

impl ConjugatePrior<f64, Gaussian> for NormalInvGamma[src]

type Posterior = Self

Type of the posterior distribution

type LnMCache = f64

Type of the ln_m cache

type LnPpCache = (GaussianSuffStat, f64)

Type of the ln_pp cache

impl ContinuousDistr<Gaussian> for NormalGamma[src]

impl ContinuousDistr<f32> for Gaussian[src]

impl ContinuousDistr<f64> for Gaussian[src]

impl Debug for Gaussian[src]

impl Default for Gaussian[src]

impl Display for Gaussian[src]

impl Entropy for Gaussian[src]

impl GewekeTestable<Gaussian, f64> for NormalGamma[src]

impl GewekeTestable<Gaussian, f64> for NormalInvChiSquared[src]

impl GewekeTestable<Gaussian, f64> for NormalInvGamma[src]

impl HasSuffStat<f32> for Gaussian[src]

impl HasSuffStat<f64> for Gaussian[src]

impl InverseCdf<f32> for Gaussian[src]

impl InverseCdf<f64> for Gaussian[src]

impl KlDivergence for Gaussian[src]

impl Kurtosis for Gaussian[src]

impl Mean<f32> for Gaussian[src]

impl Mean<f64> for Gaussian[src]

impl Median<f32> for Gaussian[src]

impl Median<f64> for Gaussian[src]

impl Mode<f32> for Gaussian[src]

impl Mode<f64> for Gaussian[src]

impl PartialEq<Gaussian> for Gaussian[src]

impl QuadBounds for Gaussian[src]

impl Rv<Gaussian> for NormalGamma[src]

impl Rv<Gaussian> for NormalInvChiSquared[src]

impl Rv<Gaussian> for NormalInvGamma[src]

impl Rv<f32> for Gaussian[src]

impl Rv<f64> for Gaussian[src]

impl Skewness for Gaussian[src]

impl Support<Gaussian> for NormalGamma[src]

impl Support<f32> for Gaussian[src]

impl Support<f64> for Gaussian[src]

impl Variance<f64> for Gaussian[src]

Auto Trait Implementations

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> Same<T> for T

type Output = T

Should always be Self

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.

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