Struct rv::dist::Categorical [−][src]
Distribution over unordered values in [0, k)
Fields
ln_weights: Vec<f64>
Methods
impl Categorical
[src]
impl Categorical
pub fn new(weights: &[f64]) -> Result<Self>
[src]
pub fn new(weights: &[f64]) -> Result<Self>
Construct a new Categorical distribution from weights
Examples
extern crate assert; extern crate rv; use rv::traits::*; use rv::dist::Categorical; let weights: Vec<f64> = vec![4.0, 2.0, 3.0, 1.0]; let cat = Categorical::new(&weights).unwrap(); assert!(cat.contains(&0_u8)); assert!(cat.contains(&3_u8)); assert!(!cat.contains(&4_u8)); assert::close(cat.pmf(&0_u8), 0.4, 10E-12);
pub fn from_ln_weights(ln_weights: Vec<f64>) -> Result<Self>
[src]
pub fn from_ln_weights(ln_weights: Vec<f64>) -> Result<Self>
Build a Categorical distribution from normalized log weights
pub fn uniform(k: usize) -> Self
[src]
pub fn uniform(k: usize) -> Self
Creates a Categorical distribution over [0, k) with uniform weights
pub fn weights(&self) -> Vec<f64>
[src]
pub fn weights(&self) -> Vec<f64>
Return the weights (exp(ln_weights)
)
pub fn k(&self) -> usize
[src]
pub fn k(&self) -> usize
Trait Implementations
impl Debug for Categorical
[src]
impl Debug for Categorical
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for Categorical
[src]
impl Clone for Categorical
fn clone(&self) -> Categorical
[src]
fn clone(&self) -> Categorical
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<X: CategoricalDatum> Rv<X> for Categorical
[src]
impl<X: CategoricalDatum> Rv<X> for Categorical
fn ln_f(&self, x: &X) -> f64
[src]
fn ln_f(&self, x: &X) -> f64
Un-normalized probability function Read more
fn ln_normalizer(&self) -> f64
[src]
fn ln_normalizer(&self) -> f64
The log of the constant term in the PDF/PMF. Should not be a function of any of the parameters. 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
Un-normalized probability function Read more
fn normalizer(&self) -> f64
[src]
fn normalizer(&self) -> f64
The constant term in the PDF/PMF. Should not be a function of any of the parameters. Read more
impl<X: CategoricalDatum> Support<X> for Categorical
[src]
impl<X: CategoricalDatum> Support<X> for Categorical
impl<X: CategoricalDatum> DiscreteDistr<X> for Categorical
[src]
impl<X: CategoricalDatum> DiscreteDistr<X> for Categorical
fn pmf(&self, x: &X) -> f64
[src]
fn pmf(&self, x: &X) -> f64
Probability mass function (PMF) at x
Read more
fn ln_pmf(&self, x: &X) -> f64
[src]
fn ln_pmf(&self, x: &X) -> f64
Natural logarithm of the probability mass function (PMF) Read more
impl<X: CategoricalDatum> Mode<X> for Categorical
[src]
impl<X: CategoricalDatum> Mode<X> for Categorical
impl Entropy for Categorical
[src]
impl Entropy for Categorical
impl<X: CategoricalDatum> HasSuffStat<X> for Categorical
[src]
impl<X: CategoricalDatum> HasSuffStat<X> for Categorical
type Stat = CategoricalSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
fn empty_suffstat(&self) -> Self::Stat
impl Rv<Categorical> for SymmetricDirichlet
[src]
impl Rv<Categorical> for SymmetricDirichlet
fn ln_f(&self, x: &Categorical) -> f64
[src]
fn ln_f(&self, x: &Categorical) -> f64
Un-normalized probability function Read more
fn ln_normalizer(&self) -> f64
[src]
fn ln_normalizer(&self) -> f64
The log of the constant term in the PDF/PMF. Should not be a function of any of the parameters. Read more
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
Single draw from the Rv
Read more
fn f(&self, x: &X) -> f64
[src]
fn f(&self, x: &X) -> f64
Un-normalized probability function Read more
fn normalizer(&self) -> f64
[src]
fn normalizer(&self) -> f64
The constant term in the PDF/PMF. Should not be a function of any of the parameters. 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
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for SymmetricDirichlet
[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for SymmetricDirichlet
type Posterior = Dirichlet
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
[src]
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
Computes the posterior distribution from the data
fn ln_m(&self, x: &CategoricalData<X>) -> f64
[src]
fn ln_m(&self, x: &CategoricalData<X>) -> f64
Log marginal likelihood
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> f64
Log posterior predictive of y given x
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
Marginal likelihood of x
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
Posterior Predictive distribution
impl Rv<Categorical> for Dirichlet
[src]
impl Rv<Categorical> for Dirichlet
fn ln_f(&self, x: &Categorical) -> f64
[src]
fn ln_f(&self, x: &Categorical) -> f64
Un-normalized probability function Read more
fn ln_normalizer(&self) -> f64
[src]
fn ln_normalizer(&self) -> f64
The log of the constant term in the PDF/PMF. Should not be a function of any of the parameters. Read more
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
Single draw from the Rv
Read more
fn f(&self, x: &X) -> f64
[src]
fn f(&self, x: &X) -> f64
Un-normalized probability function Read more
fn normalizer(&self) -> f64
[src]
fn normalizer(&self) -> f64
The constant term in the PDF/PMF. Should not be a function of any of the parameters. 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
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for Dirichlet
[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for Dirichlet
type Posterior = Self
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
[src]
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
Computes the posterior distribution from the data
fn ln_m(&self, x: &CategoricalData<X>) -> f64
[src]
fn ln_m(&self, x: &CategoricalData<X>) -> f64
Log marginal likelihood
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> f64
Log posterior predictive of y given x
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
Marginal likelihood of x
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
Posterior Predictive distribution
Auto Trait Implementations
impl Send for Categorical
impl Send for Categorical
impl Sync for Categorical
impl Sync for Categorical