Struct rv::dist::Bernoulli [−][src]
pub struct Bernoulli { /* fields omitted */ }
Bernoulli distribution with success probability p
Example
let b = Bernoulli::new(0.75).unwrap(); assert::close(b.pmf(&true), 0.75, 1E-12);
The following example panics because 2 is out of outside the Bernoulli support
ⓘ
let b = Bernoulli::new(0.75).unwrap(); assert!(!b.supports(&2_u8)); b.pmf(&2_u8); // panics
Implementations
impl Bernoulli
[src]
impl Bernoulli
[src]pub fn new(p: f64) -> Result<Self, BernoulliError>
[src]
Create a new Bernoulli distribution.
Examples
let b = Bernoulli::new(0.5).unwrap(); let coin_flips: Vec<bool> = b.sample(5, &mut rng); assert_eq!(coin_flips.len(), 5);
Bernoulli::new
will return an Error
type if given an invalid
paramter.
assert!(Bernoulli::new(-1.0).is_err()); assert!(Bernoulli::new(1.1).is_err());
pub fn new_unchecked(p: f64) -> Self
[src]
Creates a new Bernoulli without checking whether parameter value is valid.
pub fn uniform() -> Self
[src]
A Bernoulli distribution with a 50% chance of success
Example
let b = Bernoulli::uniform(); assert_eq!(b.p(), 0.5); assert_eq!(b.q(), 0.5);
pub fn p(&self) -> f64
[src]
Get p, the probability of success.
Example
let b = Bernoulli::new(0.2).unwrap(); assert_eq!(b.p(), 0.2);
pub fn set_p(&mut self, p: f64) -> Result<(), BernoulliError>
[src]
Set p, the probability of success.
Example
let mut b = Bernoulli::new(0.2).unwrap(); b.set_p(0.5).unwrap(); assert_eq!(b.p(), 0.5);
Will error for invalid values
assert!(b.set_p(0.0).is_ok()); assert!(b.set_p(1.0).is_ok()); assert!(b.set_p(-1.0).is_err()); assert!(b.set_p(1.1).is_err()); assert!(b.set_p(std::f64::INFINITY).is_err()); assert!(b.set_p(std::f64::NEG_INFINITY).is_err()); assert!(b.set_p(std::f64::NAN).is_err());
pub fn set_p_unchecked(&mut self, p: f64)
[src]
Set p without input validation
pub fn q(&self) -> f64
[src]
The complement of p
, i.e. (1 - p)
.
Example
let b = Bernoulli::new(0.2).unwrap(); assert_eq!(b.q(), 0.8);
Trait Implementations
impl<X: Booleable> ConjugatePrior<X, Bernoulli> for Beta
[src]
impl<X: Booleable> ConjugatePrior<X, Bernoulli> for Beta
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (f64, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> Self
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, X, Bernoulli>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, X, Bernoulli>
) -> f64
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, X, Bernoulli>) -> 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 ContinuousDistr<Bernoulli> for Beta
[src]
impl ContinuousDistr<Bernoulli> for Beta
[src]impl<X: Booleable> DiscreteDistr<X> for Bernoulli
[src]
impl<X: Booleable> DiscreteDistr<X> for Bernoulli
[src]impl<X: Booleable> HasSuffStat<X> for Bernoulli
[src]
impl<X: Booleable> HasSuffStat<X> for Bernoulli
[src]type Stat = BernoulliSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl KlDivergence for Bernoulli
[src]
impl KlDivergence for Bernoulli
[src]impl PartialOrd<Bernoulli> for Bernoulli
[src]
impl PartialOrd<Bernoulli> for Bernoulli
[src]impl StructuralPartialEq for Bernoulli
[src]
impl StructuralPartialEq for Bernoulli
[src]Auto Trait Implementations
impl RefUnwindSafe for Bernoulli
impl RefUnwindSafe for Bernoulli
impl UnwindSafe for Bernoulli
impl UnwindSafe for Bernoulli
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>,