Struct rv::ConjugateModel [−][src]
pub struct ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>, { /* fields omitted */ }
A wrapper for a complete conjugate model
Paramters
X
: The type of the data/observations to be modeled
Fx
: The type of the likelihood, f(x|θ)
Pr
: The type of the prior on the parameters of Fx
, π(θ)
Methods
impl<X, Fx, Pr> ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
[src]
impl<X, Fx, Pr> ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
pub fn new(fx: &Fx, pr: Arc<Pr>) -> Self
[src]
pub fn new(fx: &Fx, pr: Arc<Pr>) -> Self
Create a new conjugate model
Arguments
fx:
Example
use std::sync::Arc; use rv::prelude::*; use rv::ConjugateModel; let pr = Arc::new(Beta::jeffreys()); let fx = Bernoulli::uniform(); let model = ConjugateModel::<bool, Bernoulli, Beta>::new(&fx, pr);
pub fn ln_m(&self) -> f64
[src]
pub fn ln_m(&self) -> f64
Log marginal likelihood, f(obs)
pub fn ln_pp(&self, y: &X) -> f64
[src]
pub fn ln_pp(&self, y: &X) -> f64
Log posterior predictive, f(y|obs)
pub fn posterior(&self) -> Pr::Posterior
[src]
pub fn posterior(&self) -> Pr::Posterior
Return the posterior distribution
Example
use std::sync::Arc; use rv::prelude::*; use rv::ConjugateModel; let flips: Vec<bool> = vec![true, false, true, false, false, false]; let pr = Arc::new(Beta::new(1.0, 1.0).unwrap()); let fx = Bernoulli::uniform(); let mut model = ConjugateModel::<bool, Bernoulli, Beta>::new(&fx, pr); model.observe_many(&flips); let post = model.posterior(); assert_eq!(post, Beta { alpha: 3.0, beta: 5.0 });
Trait Implementations
impl<X, Fx, Pr> SuffStat<X> for ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
[src]
impl<X, Fx, Pr> SuffStat<X> for ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
fn n(&self) -> usize
[src]
fn n(&self) -> usize
Returns the number of observations
fn observe(&mut self, x: &X)
[src]
fn observe(&mut self, x: &X)
Assimilate the datum x
into the statistic
fn forget(&mut self, x: &X)
[src]
fn forget(&mut self, x: &X)
Remove the datum x
from the statistic
fn observe_many(&mut self, xs: &[X])
[src]
fn observe_many(&mut self, xs: &[X])
Assimilate several observations
fn forget_many(&mut self, xs: &[X])
[src]
fn forget_many(&mut self, xs: &[X])
Forget several observations
impl<X, Fx, Pr> Rv<X> for ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
[src]
impl<X, Fx, Pr> Rv<X> for ConjugateModel<X, Fx, Pr> where
X: Debug,
Fx: Rv<X> + HasSuffStat<X>,
Pr: ConjugatePrior<X, Fx>,
fn ln_f(&self, x: &X) -> f64
[src]
fn ln_f(&self, x: &X) -> f64
Probability function Read more
fn draw<R: Rng>(&self, rng: &mut R) -> X
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> X
Single draw from the Rv
Read more
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
Multiple draws of the Rv
Read more
fn f(&self, x: &X) -> f64
[src]
fn f(&self, x: &X) -> f64
Probability function Read more
Auto Trait Implementations
impl<X, Fx, Pr> Send for ConjugateModel<X, Fx, Pr> where
Pr: Send + Sync,
X: Send,
<Fx as HasSuffStat<X>>::Stat: Send,
impl<X, Fx, Pr> Send for ConjugateModel<X, Fx, Pr> where
Pr: Send + Sync,
X: Send,
<Fx as HasSuffStat<X>>::Stat: Send,
impl<X, Fx, Pr> Sync for ConjugateModel<X, Fx, Pr> where
Pr: Send + Sync,
X: Sync,
<Fx as HasSuffStat<X>>::Stat: Sync,
impl<X, Fx, Pr> Sync for ConjugateModel<X, Fx, Pr> where
Pr: Send + Sync,
X: Sync,
<Fx as HasSuffStat<X>>::Stat: Sync,