Struct rv::dist::Categorical [−][src]
pub struct Categorical { /* fields omitted */ }
Categorical distribution over unordered values in [0, k).
Implementations
impl Categorical
[src]
impl Categorical
[src]pub fn new(weights: &[f64]) -> Result<Self, CategoricalError>
[src]
Construct a new Categorical distribution from weights
Arguments
- weights: A vector describing the proportional likelihood of each outcome. The weights must all be positive, but do not need to sum to 1 because they will be normalized in the constructor.
Examples
let weights: Vec<f64> = vec![4.0, 2.0, 3.0, 1.0]; let cat = Categorical::new(&weights).unwrap(); assert!(cat.supports(&0_u8)); assert!(cat.supports(&3_u8)); assert!(!cat.supports(&4_u8)); assert::close(cat.pmf(&0_u8), 0.4, 1E-12);
pub fn from_ln_weights(ln_weights: Vec<f64>) -> Result<Self, CategoricalError>
[src]
Build a Categorical distribution from normalized log weights
Arguments
- ln_weights: A vector describing the proportional likelihood of each outcome in log space. sum(exp(ln_weights)) must be equal to 1.
Example
let ln_weights: Vec<f64> = vec![ -2.3025850929940455, -1.6094379124341003, -1.2039728043259361, -0.916290731874155 ]; let cat = Categorical::from_ln_weights(ln_weights).unwrap(); assert::close(cat.pmf(&0_u8), 0.1, 1E-12); assert::close(cat.pmf(&1_u8), 0.2, 1E-12); assert::close(cat.pmf(&2_u8), 0.3, 1E-12); assert::close(cat.pmf(&3_u8), 0.4, 1E-12);
pub fn new_unchecked(ln_weights: Vec<f64>) -> Self
[src]
Creates a new Categorical without checking whether the ln weights are valid.
pub fn uniform(k: usize) -> Self
[src]
Creates a Categorical distribution over [0, k) with uniform weights
pub fn weights(&self) -> Vec<f64>
[src]
Return the weights (exp(ln_weights)
)
pub fn k(&self) -> usize
[src]
Get the number of possible outcomes
Example
let cat = Categorical::uniform(4); assert_eq!(cat.k(), 4);
pub fn ln_weights(&self) -> &Vec<f64>
[src]
Get a reference to the weights
Trait Implementations
impl<X: CategoricalDatum> Cdf<X> for Categorical
[src]
impl<X: CategoricalDatum> Cdf<X> for Categorical
[src]impl Clone for Categorical
[src]
impl Clone for Categorical
[src]fn clone(&self) -> Categorical
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for SymmetricDirichlet
[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for SymmetricDirichlet
[src]type Posterior = Dirichlet
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (Vec<f64>, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &CategoricalData<'_, X>) -> Self::Posterior
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &CategoricalData<'_, X>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &CategoricalData<'_, X>
) -> f64
fn ln_pp_cache(&self, x: &CategoricalData<'_, X>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &X) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for Dirichlet
[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for Dirichlet
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = (f64, f64)
Type of the ln_m
cache
type LnPpCache = (Vec<f64>, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &CategoricalData<'_, X>) -> Self::Posterior
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &CategoricalData<'_, X>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &CategoricalData<'_, X>
) -> f64
fn ln_pp_cache(&self, x: &CategoricalData<'_, X>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &X) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl<X: CategoricalDatum> DiscreteDistr<X> for Categorical
[src]
impl<X: CategoricalDatum> DiscreteDistr<X> for Categorical
[src]impl<X: CategoricalDatum> HasSuffStat<X> for Categorical
[src]
impl<X: CategoricalDatum> HasSuffStat<X> for Categorical
[src]type Stat = CategoricalSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl KlDivergence for Categorical
[src]
impl KlDivergence for Categorical
[src]impl<X: CategoricalDatum> Mode<X> for Categorical
[src]
impl<X: CategoricalDatum> Mode<X> for Categorical
[src]impl PartialEq<Categorical> for Categorical
[src]
impl PartialEq<Categorical> for Categorical
[src]fn eq(&self, other: &Categorical) -> bool
[src]
fn ne(&self, other: &Categorical) -> bool
[src]
impl PartialOrd<Categorical> for Categorical
[src]
impl PartialOrd<Categorical> for Categorical
[src]impl Rv<Categorical> for SymmetricDirichlet
[src]
impl Rv<Categorical> for SymmetricDirichlet
[src]impl Rv<Categorical> for Dirichlet
[src]
impl Rv<Categorical> for Dirichlet
[src]impl<X: CategoricalDatum> Rv<X> for Categorical
[src]
impl<X: CategoricalDatum> Rv<X> for Categorical
[src]impl StructuralPartialEq for Categorical
[src]
impl StructuralPartialEq for Categorical
[src]impl<X: CategoricalDatum> Support<X> for Categorical
[src]
impl<X: CategoricalDatum> Support<X> for Categorical
[src]Auto Trait Implementations
impl RefUnwindSafe for Categorical
impl RefUnwindSafe for Categorical
impl Send for Categorical
impl Send for Categorical
impl Sync for Categorical
impl Sync for Categorical
impl Unpin for Categorical
impl Unpin for Categorical
impl UnwindSafe for Categorical
impl UnwindSafe for Categorical
Blanket Implementations
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn is_in_subset(&self) -> bool
pub fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,