Struct rv::dist::NormalInvWishart
source · pub struct NormalInvWishart { /* private fields */ }
Expand description
Common conjugate prior on the μ and Σ parameters in the Multivariate Gaussian, Ν(μ, Σ)
Ν(μ, Σ) ~ NIW(μ0, κ0, ν, Ψ) implies μ ~ N(μ0, Σ/k0) and Σ ~ W-1(Ψ, ν)
§Example
Draw a Multivariate Gaussian from GIW
use nalgebra::{DMatrix, DVector};
use rv::prelude::*;
let mu = DVector::zeros(3);
let k = 1.0;
let df = 3;
let scale = DMatrix::identity(3, 3);
let niw = NormalInvWishart::new(mu, k, df, scale).unwrap();
let mut rng = rand::thread_rng();
let mvg: MvGaussian = niw.draw(&mut rng);
Implementations§
source§impl NormalInvWishart
impl NormalInvWishart
sourcepub fn new(
mu: DVector<f64>,
k: f64,
df: usize,
scale: DMatrix<f64>
) -> Result<Self, NormalInvWishartError>
pub fn new( mu: DVector<f64>, k: f64, df: usize, scale: DMatrix<f64> ) -> Result<Self, NormalInvWishartError>
Create a new NormalInvWishart
distribution
§Arguments
- mu: The mean of μ, μ0
- k: A scale factor on Σ, κ0
- df: The degrees of freedom, ν > |μ| - 1
- scale The positive-definite scale matrix, Ψ
sourcepub fn new_unchecked(
mu: DVector<f64>,
k: f64,
df: usize,
scale: DMatrix<f64>
) -> Self
pub fn new_unchecked( mu: DVector<f64>, k: f64, df: usize, scale: DMatrix<f64> ) -> Self
Creates a new NormalInvWishart without checking whether the parameters are valid.
sourcepub fn set_k_unchecked(&mut self, k: f64)
pub fn set_k_unchecked(&mut self, k: f64)
Set the value of k without input validation
sourcepub fn set_df_unchecked(&mut self, df: usize)
pub fn set_df_unchecked(&mut self, df: usize)
Set the value of df without input validation
sourcepub fn set_scale(
&mut self,
scale: DMatrix<f64>
) -> Result<(), NormalInvWishartError>
pub fn set_scale( &mut self, scale: DMatrix<f64> ) -> Result<(), NormalInvWishartError>
Set the scale parameter
pub fn set_scale_unnchecked(&mut self, scale: DMatrix<f64>)
sourcepub fn set_mu(&mut self, mu: DVector<f64>) -> Result<(), NormalInvWishartError>
pub fn set_mu(&mut self, mu: DVector<f64>) -> Result<(), NormalInvWishartError>
Set the scale parameter
pub fn set_mu_unchecked(&mut self, mu: DVector<f64>)
Trait Implementations§
source§impl Clone for NormalInvWishart
impl Clone for NormalInvWishart
source§fn clone(&self) -> NormalInvWishart
fn clone(&self) -> NormalInvWishart
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl ConjugatePrior<Matrix<f64, Dyn, Const<1>, VecStorage<f64, Dyn, Const<1>>>, MvGaussian> for NormalInvWishart
impl ConjugatePrior<Matrix<f64, Dyn, Const<1>, VecStorage<f64, Dyn, Const<1>>>, MvGaussian> for NormalInvWishart
§type Posterior = NormalInvWishart
type Posterior = NormalInvWishart
Type of the posterior distribution
§type LnPpCache = (NormalInvWishart, f64)
type LnPpCache = (NormalInvWishart, f64)
Type of the
ln_pp
cachesource§fn posterior(
&self,
x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian>
) -> NormalInvWishart
fn posterior( &self, x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian> ) -> NormalInvWishart
Computes the posterior distribution from the data
source§fn ln_m_cache(&self) -> f64
fn ln_m_cache(&self) -> f64
Compute the cache for the log marginal likelihood.
source§fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian>
) -> f64
fn ln_m_with_cache( &self, cache: &Self::LnMCache, x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian> ) -> f64
Log marginal likelihood with supplied cache.
source§fn ln_pp_cache(
&self,
x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian>
) -> Self::LnPpCache
fn ln_pp_cache( &self, x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian> ) -> Self::LnPpCache
Compute the cache for the Log posterior predictive of y given x. Read more
source§fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &DVector<f64>) -> f64
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &DVector<f64>) -> f64
Log posterior predictive of y given x with supplied ln(norm)
source§fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
The log marginal likelihood
source§fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
Log posterior predictive of y given x
source§fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
Marginal likelihood of x
source§impl ContinuousDistr<MvGaussian> for NormalInvWishart
impl ContinuousDistr<MvGaussian> for NormalInvWishart
source§impl Debug for NormalInvWishart
impl Debug for NormalInvWishart
source§impl<'de> Deserialize<'de> for NormalInvWishart
impl<'de> Deserialize<'de> for NormalInvWishart
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for NormalInvWishart
impl Display for NormalInvWishart
source§impl From<&NormalInvWishart> for String
impl From<&NormalInvWishart> for String
source§fn from(niw: &NormalInvWishart) -> String
fn from(niw: &NormalInvWishart) -> String
Converts to this type from the input type.
source§impl PartialEq for NormalInvWishart
impl PartialEq for NormalInvWishart
source§fn eq(&self, other: &NormalInvWishart) -> bool
fn eq(&self, other: &NormalInvWishart) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Rv<MvGaussian> for NormalInvWishart
impl Rv<MvGaussian> for NormalInvWishart
source§impl Serialize for NormalInvWishart
impl Serialize for NormalInvWishart
source§impl Support<MvGaussian> for NormalInvWishart
impl Support<MvGaussian> for NormalInvWishart
impl StructuralPartialEq for NormalInvWishart
Auto Trait Implementations§
impl Freeze for NormalInvWishart
impl RefUnwindSafe for NormalInvWishart
impl Send for NormalInvWishart
impl Sync for NormalInvWishart
impl Unpin for NormalInvWishart
impl UnwindSafe for NormalInvWishart
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.