[−][src]Struct rv::dist::NormalGamma
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]
fn clone(&self) -> NormalGamma
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl ConjugatePrior<f64, Gaussian> for NormalGamma
[src]
type Posterior = Self
fn posterior(&self, x: &DataOrSuffStat<f64, Gaussian>) -> Self
[src]
fn ln_m(&self, x: &DataOrSuffStat<f64, Gaussian>) -> f64
[src]
fn ln_pp(&self, y: &f64, x: &DataOrSuffStat<f64, Gaussian>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl ContinuousDistr<Gaussian> for NormalGamma
[src]
impl Debug for NormalGamma
[src]
impl Display for NormalGamma
[src]
impl<'_> From<&'_ NormalGamma> for String
[src]
fn from(ng: &NormalGamma) -> String
[src]
impl HasSuffStat<f64> for NormalGamma
[src]
type Stat = GaussianSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl PartialEq<NormalGamma> for NormalGamma
[src]
fn eq(&self, other: &NormalGamma) -> bool
[src]
fn ne(&self, other: &NormalGamma) -> bool
[src]
impl Rv<Gaussian> for NormalGamma
[src]
fn ln_f(&self, x: &Gaussian) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Gaussian
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl StructuralPartialEq for NormalGamma
[src]
impl Support<Gaussian> for NormalGamma
[src]
Auto Trait Implementations
impl RefUnwindSafe for NormalGamma
impl Send for NormalGamma
impl Sync for NormalGamma
impl Unpin for NormalGamma
impl UnwindSafe for NormalGamma
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Fx, X> ContinuousDistr<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: ContinuousDistr<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: ContinuousDistr<X>,
impl<T> From<T> for T
[src]
impl<Fx, X> HasSuffStat<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: HasSuffStat<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: HasSuffStat<X>,
type Stat = <<Fx as Deref>::Target as HasSuffStat<X>>::Stat
fn empty_suffstat(&Self) -> <Fx as HasSuffStat<X>>::Stat
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Fx, X> Rv<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
fn ln_f(&Self, &X) -> f64
[src]
fn f(&Self, &X) -> f64
[src]
fn draw<R>(&Self, &mut R) -> X where
R: Rng,
[src]
R: Rng,
fn sample<R>(&Self, usize, &mut R) -> Vec<X> where
R: Rng,
[src]
R: Rng,
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<Fx, X> Support<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,