[][src]Struct rv::dist::NormalGamma

pub struct NormalGamma { /* fields omitted */ }

Prior for Gaussian

Given x ~ N(μ, σ), the Normal Gamma prior implies that μ ~ N(m, 1/(rρ)) and ρ ~ Gamma(ν/2, s/2).

Implementations

impl NormalGamma[src]

pub fn new(m: f64, r: f64, s: f64, v: f64) -> Result<Self, NormalGammaError>[src]

Create a new Normal Gamma distribution

Arguments

  • m: The prior mean
  • r: Relative precision of μ versus data
  • s: The mean of rho (the precision) is v/s.
  • v: Degrees of freedom of precision of rho

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

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

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

Get the m parameter

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

Set the value of m

Example

use rv::dist::NormalGamma;

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

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

Will error for invalid values

assert!(ng.set_m(-1.1).is_ok());
assert!(ng.set_m(std::f64::INFINITY).is_err());
assert!(ng.set_m(std::f64::NEG_INFINITY).is_err());
assert!(ng.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 r(&self) -> f64[src]

Get the r parameter

pub fn set_r(&mut self, r: f64) -> Result<(), NormalGammaError>[src]

Set the value of r

Example

use rv::dist::NormalGamma;

let mut ng = NormalGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(ng.r(), 1.2);

ng.set_r(2.1).unwrap();
assert_eq!(ng.r(), 2.1);

Will error for invalid values

assert!(ng.set_r(2.1).is_ok());

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


assert!(ng.set_r(std::f64::INFINITY).is_err());
assert!(ng.set_r(std::f64::NEG_INFINITY).is_err());
assert!(ng.set_r(std::f64::NAN).is_err());

pub fn set_r_unchecked(&mut self, r: f64)[src]

Set the value of r without input validation

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

Get the s parameter

pub fn set_s(&mut self, s: f64) -> Result<(), NormalGammaError>[src]

Set the value of s

Example

use rv::dist::NormalGamma;

let mut ng = NormalGamma::new(0.0, 1.2, 2.3, 3.4).unwrap();
assert_eq!(ng.s(), 2.3);

ng.set_s(3.2).unwrap();
assert_eq!(ng.s(), 3.2);

Will error for invalid values

assert!(ng.set_s(2.1).is_ok());

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


assert!(ng.set_s(std::f64::INFINITY).is_err());
assert!(ng.set_s(std::f64::NEG_INFINITY).is_err());
assert!(ng.set_s(std::f64::NAN).is_err());

pub fn set_s_unchecked(&mut self, s: f64)[src]

Set the value of s without input validation

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

Get the v parameter

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

Set the value of v

Example

use rv::dist::NormalGamma;

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

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

Will error for invalid values

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

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


assert!(ng.set_v(std::f64::INFINITY).is_err());
assert!(ng.set_v(std::f64::NEG_INFINITY).is_err());
assert!(ng.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

Trait Implementations

impl Clone for NormalGamma[src]

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

type Posterior = Self

impl ContinuousDistr<Gaussian> for NormalGamma[src]

impl Debug for NormalGamma[src]

impl Display for NormalGamma[src]

impl<'_> From<&'_ NormalGamma> for String[src]

impl HasSuffStat<f64> for NormalGamma[src]

impl PartialEq<NormalGamma> for NormalGamma[src]

impl Rv<Gaussian> for NormalGamma[src]

impl StructuralPartialEq for NormalGamma[src]

impl Support<Gaussian> for NormalGamma[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<Fx, X> ContinuousDistr<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: ContinuousDistr<X>, 
[src]

impl<T> From<T> for T[src]

impl<Fx, X> HasSuffStat<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: HasSuffStat<X>, 
[src]

type Stat = <<Fx as Deref>::Target as HasSuffStat<X>>::Stat

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Fx, X> Rv<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Rv<X>, 
[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<Fx, X> Support<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Support<X>, 
[src]

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