[][src]Struct rv::dist::Bernoulli

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

Methods

impl Bernoulli[src]

pub fn set_p(&mut self, val: f64) -> &mut Self[src]

Probability of a success (x=1)

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

impl Clone for Bernoulli[src]

impl<X: Booleable> ConjugatePrior<X, Bernoulli> for Beta[src]

type Posterior = Self

impl ConjugatePrior<bool, Bernoulli> for Beta[src]

type Posterior = Self

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 DiscreteDistr<bool> for Bernoulli[src]

impl Display for Bernoulli[src]

impl Entropy for Bernoulli[src]

impl<'_> From<&'_ Bernoulli> for String[src]

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

impl HasSuffStat<bool> 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 Mode<bool> 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 Rv<bool> 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 Support<bool> 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<Fx, X> Cdf<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Cdf<X>, 
[src]

impl<Fx, X> DiscreteDistr<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: DiscreteDistr<X>, 
[src]

impl<Fx> Entropy for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Entropy
[src]

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

impl<Fx, X> HasSuffStat<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: HasSuffStat<X>, 
[src]

type Stat = <<Fx as Deref>::Target as HasSuffStat<X>>::Stat

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

impl<Fx> KlDivergence for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: KlDivergence
[src]

impl<Fx> Kurtosis for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Kurtosis
[src]

impl<Fx, X> Mean<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Mean<X>, 
[src]

impl<Fx, X> Median<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Median<X>, 
[src]

impl<Fx, X> Mode<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Mode<X>, 
[src]

impl<Fx, X> Rv<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Rv<X>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<Fx> Skewness for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Skewness
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<Fx, X> Support<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Support<X>, 
[src]

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>, 

impl<Fx, X> Variance<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Variance<X>, 
[src]