Struct rv::ConjugateModel

source ·
pub struct ConjugateModel<X, Fx, Pr>where
    Fx: Rv<X> + HasSuffStat<X>,
    Pr: ConjugatePrior<X, Fx>,
{ /* private fields */ }
Expand description

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, π(θ)

Implementations§

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);

Log marginal likelihood, f(obs)

Log posterior predictive, f(y|obs)

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::new(3.0, 5.0).unwrap());

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Probability function Read more
Single draw from the Rv Read more
Multiple draws of the Rv Read more
Probability function Read more
Create a never-ending iterator of samples Read more
Returns the number of observations
Assimilate the datum x into the statistic
Remove the datum x from the statistic
Assimilate several observations
Forget several observations

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.