Struct rv::dist::NormalInvGamma[][src]

pub struct NormalInvGamma { /* fields omitted */ }

Prior for Gaussian

Given x ~ N(μ, σ), the Normal Inverse Gamma prior implies that μ ~ N(m, sqrt(v)σ) and ρ ~ InvGamma(a, b).

Implementations

impl NormalInvGamma[src]

pub fn new(m: f64, v: f64, a: f64, b: f64) -> Result<Self, NormalInvGammaError>[src]

Create a new Normal Inverse Gamma distribution

Arguments

  • m: The prior mean
  • v: Relative variance of μ versus data
  • a: The mean of variance is b / (a - 1)
  • b: Degrees of freedom of the variance

pub fn new_unchecked(m: f64, v: f64, a: f64, b: f64) -> Self[src]

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

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

Returns (m, v, a, b)

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

Get the m parameter

pub fn set_m(&mut self, m: f64) -> Result<(), NormalInvGammaError>[src]

Set the value of m

Example

use rv::dist::NormalInvGamma;

let mut nig = NormalInvGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(nig.m(), 0.0);

nig.set_m(-1.1).unwrap();
assert_eq!(nig.m(), -1.1);

Will error for invalid values

assert!(nig.set_m(-1.1).is_ok());
assert!(nig.set_m(std::f64::INFINITY).is_err());
assert!(nig.set_m(std::f64::NEG_INFINITY).is_err());
assert!(nig.set_m(std::f64::NAN).is_err());

pub fn set_m_unchecked(&mut self, m: f64)[src]

Set the value of m without input validation

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

Get the v parameter

pub fn set_v(&mut self, v: f64) -> Result<(), NormalInvGammaError>[src]

Set the value of v

Example

use rv::dist::NormalInvGamma;

let mut nig = NormalInvGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(nig.v(), 1.2);

nig.set_v(4.3).unwrap();
assert_eq!(nig.v(), 4.3);

Will error for invalid values

assert!(nig.set_v(2.1).is_ok());

// must be greater than zero
assert!(nig.set_v(0.0).is_err());
assert!(nig.set_v(-1.0).is_err());


assert!(nig.set_v(std::f64::INFINITY).is_err());
assert!(nig.set_v(std::f64::NEG_INFINITY).is_err());
assert!(nig.set_v(std::f64::NAN).is_err());

pub fn set_v_unchecked(&mut self, v: f64)[src]

Set the value of v without input validation

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

Get the a parameter

pub fn set_a(&mut self, a: f64) -> Result<(), NormalInvGammaError>[src]

Set the value of a

Example

use rv::dist::NormalInvGamma;

let mut nig = NormalInvGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(nig.a(), 2.3);

nig.set_a(4.3).unwrap();
assert_eq!(nig.a(), 4.3);

Will error for invalid values

assert!(nig.set_a(2.1).is_ok());

// must be greater than zero
assert!(nig.set_a(0.0).is_err());
assert!(nig.set_a(-1.0).is_err());


assert!(nig.set_a(std::f64::INFINITY).is_err());
assert!(nig.set_a(std::f64::NEG_INFINITY).is_err());
assert!(nig.set_a(std::f64::NAN).is_err());

pub fn set_a_unchecked(&mut self, a: f64)[src]

Set the value of a without input validation

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

Get the b parameter

pub fn set_b(&mut self, b: f64) -> Result<(), NormalInvGammaError>[src]

Set the value of b

Example

use rv::dist::NormalInvGamma;

let mut nig = NormalInvGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(nig.b(), 3.4);

nig.set_b(4.3).unwrap();
assert_eq!(nig.b(), 4.3);

Will error for invalid values

assert!(nig.set_b(2.1).is_ok());

// must be greater than zero
assert!(nig.set_b(0.0).is_err());
assert!(nig.set_b(-1.0).is_err());


assert!(nig.set_b(std::f64::INFINITY).is_err());
assert!(nig.set_b(std::f64::NEG_INFINITY).is_err());
assert!(nig.set_b(std::f64::NAN).is_err());

pub fn set_b_unchecked(&mut self, b: f64)[src]

Set the value of b without input validation

Trait Implementations

impl Clone for NormalInvGamma[src]

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 Debug for NormalInvGamma[src]

impl Display for NormalInvGamma[src]

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

impl PartialEq<NormalInvGamma> for NormalInvGamma[src]

impl Rv<Gaussian> for NormalInvGamma[src]

impl StructuralPartialEq for NormalInvGamma[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>,