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]

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> Cdf<X> for Bernoulli[src]

impl Clone for Bernoulli[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

impl ContinuousDistr<Bernoulli> for Beta[src]

impl Debug for Bernoulli[src]

impl Default for Bernoulli[src]

impl<X: Booleable> DiscreteDistr<X> for Bernoulli[src]

impl Display for Bernoulli[src]

impl Entropy for Bernoulli[src]

impl<X: Booleable> HasSuffStat<X> for Bernoulli[src]

impl KlDivergence for Bernoulli[src]

impl Kurtosis for Bernoulli[src]

impl Mean<f64> for Bernoulli[src]

impl Median<f64> for Bernoulli[src]

impl<X: Booleable> Mode<X> for Bernoulli[src]

impl PartialEq<Bernoulli> for Bernoulli[src]

impl PartialOrd<Bernoulli> for Bernoulli[src]

impl Rv<Bernoulli> for Beta[src]

impl<X: Booleable> Rv<X> for Bernoulli[src]

impl Skewness for Bernoulli[src]

impl StructuralPartialEq for Bernoulli[src]

impl Support<Bernoulli> for Beta[src]

impl<X: Booleable> Support<X> for Bernoulli[src]

impl Variance<f64> for Bernoulli[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,