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

source

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

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.

source

pub fn ndims(&self) -> usize

Get the number of dimensions

source

pub fn mu(&self) -> &DVector<f64>

Get a reference to the mu vector

source

pub fn k(&self) -> f64

Get the k parameter

source

pub fn set_k(&mut self, k: f64) -> Result<(), NormalInvWishartError>

Set the value of k

source

pub fn set_k_unchecked(&mut self, k: f64)

Set the value of k without input validation

source

pub fn df(&self) -> usize

Get the degrees of freedom, df

source

pub fn set_df(&mut self, df: usize) -> Result<(), NormalInvWishartError>

Set the value of df

source

pub fn set_df_unchecked(&mut self, df: usize)

Set the value of df without input validation

source

pub fn scale(&self) -> &DMatrix<f64>

Get a reference to the scale matrix

source

pub fn set_scale( &mut self, scale: DMatrix<f64> ) -> Result<(), NormalInvWishartError>

Set the scale parameter

source

pub fn set_scale_unnchecked(&mut self, scale: DMatrix<f64>)

source

pub fn set_mu(&mut self, mu: DVector<f64>) -> Result<(), NormalInvWishartError>

Set the scale parameter

source

pub fn set_mu_unchecked(&mut self, mu: DVector<f64>)

Trait Implementations§

source§

impl Clone for NormalInvWishart

source§

fn clone(&self) -> NormalInvWishart

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ConjugatePrior<Matrix<f64, Dyn, Const<1>, VecStorage<f64, Dyn, Const<1>>>, MvGaussian> for NormalInvWishart

§

type Posterior = NormalInvWishart

Type of the posterior distribution
§

type LnMCache = f64

Type of the ln_m cache
§

type LnPpCache = (NormalInvWishart, f64)

Type of the ln_pp cache
source§

fn posterior( &self, x: &DataOrSuffStat<'_, DVector<f64>, MvGaussian> ) -> NormalInvWishart

Computes the posterior distribution from the data
source§

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

Log marginal likelihood with supplied cache.
source§

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

Log posterior predictive of y given x with supplied ln(norm)
source§

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

Log posterior predictive of y given x
source§

fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64

Marginal likelihood of x
source§

fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64

Posterior Predictive distribution
source§

impl ContinuousDistr<MvGaussian> for NormalInvWishart

source§

fn pdf(&self, x: &X) -> f64

The value of the Probability Density Function (PDF) at x Read more
source§

fn ln_pdf(&self, x: &X) -> f64

The value of the log Probability Density Function (PDF) at x Read more
source§

impl Debug for NormalInvWishart

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for NormalInvWishart

source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&NormalInvWishart> for String

source§

fn from(niw: &NormalInvWishart) -> String

Converts to this type from the input type.
source§

impl PartialEq<NormalInvWishart> for NormalInvWishart

source§

fn eq(&self, other: &NormalInvWishart) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rv<MvGaussian> for NormalInvWishart

source§

fn ln_f(&self, x: &MvGaussian) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> MvGaussian

Single draw from the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Serialize for NormalInvWishart

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Support<MvGaussian> for NormalInvWishart

source§

fn supports(&self, x: &MvGaussian) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl StructuralPartialEq for NormalInvWishart

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

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

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> DeserializeOwnedAlias for Twhere T: DeserializeOwned,

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq<T> + Debug,

source§

impl<T> SendAlias for T

§

impl<T> SendSyncUnwindSafe for Twhere T: Send + Sync + UnwindSafe + ?Sized,

source§

impl<T> SerializeAlias for Twhere T: Serialize,

source§

impl<T> SyncAlias for T