[−][src]Struct rv::dist::Categorical
Categorical distribution over unordered values in [0, k).
Implementations
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 Clone for Categorical
[src]
fn clone(&self) -> Categorical
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<X: CategoricalDatum> ConjugatePrior<X, Categorical> for SymmetricDirichlet
[src]
type Posterior = Dirichlet
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
[src]
fn ln_m(&self, x: &CategoricalData<X>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> 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]
type Posterior = Self
fn posterior(&self, x: &CategoricalData<X>) -> Self::Posterior
[src]
fn ln_m(&self, x: &CategoricalData<X>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &CategoricalData<X>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<X, Fx>) -> f64
[src]
impl Debug for Categorical
[src]
impl<X: CategoricalDatum> DiscreteDistr<X> for Categorical
[src]
impl Display for Categorical
[src]
impl Entropy for Categorical
[src]
impl<'_> From<&'_ Categorical> for String
[src]
fn from(cat: &Categorical) -> String
[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<X: CategoricalDatum> Mode<X> 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]
fn partial_cmp(&self, other: &Categorical) -> Option<Ordering>
[src]
fn lt(&self, other: &Categorical) -> bool
[src]
fn le(&self, other: &Categorical) -> bool
[src]
fn gt(&self, other: &Categorical) -> bool
[src]
fn ge(&self, other: &Categorical) -> bool
[src]
impl Rv<Categorical> for SymmetricDirichlet
[src]
fn ln_f(&self, x: &Categorical) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl Rv<Categorical> for Dirichlet
[src]
fn ln_f(&self, x: &Categorical) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> Categorical
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl<X: CategoricalDatum> Rv<X> for Categorical
[src]
fn ln_f(&self, x: &X) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> X
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl StructuralPartialEq for Categorical
[src]
impl<X: CategoricalDatum> Support<X> for Categorical
[src]
Auto Trait Implementations
impl RefUnwindSafe for Categorical
impl Send for Categorical
impl Sync for Categorical
impl Unpin for Categorical
impl UnwindSafe for Categorical
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<Fx, X> Cdf<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
impl<Fx, X> DiscreteDistr<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
impl<Fx> Entropy for Fx where
Fx: Deref,
<Fx as Deref>::Target: Entropy,
[src]
Fx: Deref,
<Fx as Deref>::Target: Entropy,
impl<T> From<T> for T
[src]
impl<Fx, X> HasSuffStat<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: HasSuffStat<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: HasSuffStat<X>,
type Stat = <<Fx as Deref>::Target as HasSuffStat<X>>::Stat
fn empty_suffstat(&Self) -> <Fx as HasSuffStat<X>>::Stat
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Fx> KlDivergence for Fx where
Fx: Deref,
<Fx as Deref>::Target: KlDivergence,
[src]
Fx: Deref,
<Fx as Deref>::Target: KlDivergence,
impl<Fx, X> Mode<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Mode<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Mode<X>,
impl<Fx, X> Rv<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
fn ln_f(&Self, &X) -> f64
[src]
fn f(&Self, &X) -> f64
[src]
fn draw<R>(&Self, &mut R) -> X where
R: Rng,
[src]
R: Rng,
fn sample<R>(&Self, usize, &mut R) -> Vec<X> where
R: Rng,
[src]
R: Rng,
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<Fx, X> Support<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,