[−][src]Struct rv::dist::Binomial
Binomial distribution with success probability p
Examples
use rv::prelude::*; let binom = Binomial::new(4, 0.5).unwrap(); let cdf = binom.cdf(&2_u8); assert_eq!(cdf, binom.pmf(&0_u8) + binom.pmf(&1_u8) + binom.pmf(&2_u8))
Values outside the support of [0, n] can cause panics in certain functions
let n = 4; let binom = Binomial::new(n, 0.5).unwrap(); assert!(!binom.supports(&5_u8))
The maximum allowed value is 4, so the PMF of 5 cannot be computed
binom.pmf(&5_u8); // panics
Methods
impl Binomial
[src]
pub fn set_n(&mut self, val: u64) -> &mut Self
[src]
Total number of trials
pub fn set_p(&mut self, val: f64) -> &mut Self
[src]
Probability of a success
impl Binomial
[src]
pub fn new(n: u64, p: f64) -> Result<Self>
[src]
Create a new Binomial distribution
Arguments
- n: the total number of trials
- p: the pobability of success
pub fn new_unchecked(n: u64, p: f64) -> Self
[src]
Creates a new Binomial without checking whether the parameters are valid.
pub fn uniform(n: u64) -> Self
[src]
A Binomial distribution with a 50% chance of success
Example
let binom = Binomial::uniform(11); assert_eq!(binom.p(), 0.5);
pub fn n(&self) -> u64
[src]
Get the number of trials
Example
let binom = Binomial::uniform(11); assert_eq!(binom, Binomial::new(11, 0.5).unwrap());
pub fn p(&self) -> f64
[src]
Get the probability of success
Example
let binom = Binomial::new(10, 0.2).unwrap(); assert_eq!(binom.p(), 0.2);
pub fn q(&self) -> f64
[src]
The complement of p
, i.e. (1 - p)
.
Example
let binom = Binomial::new(10, 0.2).unwrap(); assert_eq!(binom.q(), 0.8);
Trait Implementations
impl Rv<u8> for Binomial
[src]
fn ln_f(&self, k: &u8) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u8
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<u16> for Binomial
[src]
fn ln_f(&self, k: &u16) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u16
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<u32> for Binomial
[src]
fn ln_f(&self, k: &u32) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u32
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<u64> for Binomial
[src]
fn ln_f(&self, k: &u64) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u64
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<usize> for Binomial
[src]
fn ln_f(&self, k: &usize) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> usize
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<i8> for Binomial
[src]
fn ln_f(&self, k: &i8) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> i8
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<i16> for Binomial
[src]
fn ln_f(&self, k: &i16) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> i16
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<i32> for Binomial
[src]
fn ln_f(&self, k: &i32) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> i32
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Rv<i64> for Binomial
[src]
fn ln_f(&self, k: &i64) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> i64
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<X>
[src]
impl Support<u8> for Binomial
[src]
impl Support<u16> for Binomial
[src]
impl Support<u32> for Binomial
[src]
impl Support<u64> for Binomial
[src]
impl Support<usize> for Binomial
[src]
impl Support<i8> for Binomial
[src]
impl Support<i16> for Binomial
[src]
impl Support<i32> for Binomial
[src]
impl Support<i64> for Binomial
[src]
impl Cdf<u8> for Binomial
[src]
impl Cdf<u16> for Binomial
[src]
impl Cdf<u32> for Binomial
[src]
impl Cdf<u64> for Binomial
[src]
impl Cdf<usize> for Binomial
[src]
impl Cdf<i8> for Binomial
[src]
impl Cdf<i16> for Binomial
[src]
impl Cdf<i32> for Binomial
[src]
impl Cdf<i64> for Binomial
[src]
impl DiscreteDistr<u8> for Binomial
[src]
impl DiscreteDistr<u16> for Binomial
[src]
impl DiscreteDistr<u32> for Binomial
[src]
impl DiscreteDistr<u64> for Binomial
[src]
impl DiscreteDistr<usize> for Binomial
[src]
impl DiscreteDistr<i8> for Binomial
[src]
impl DiscreteDistr<i16> for Binomial
[src]
impl DiscreteDistr<i32> for Binomial
[src]
impl DiscreteDistr<i64> for Binomial
[src]
impl Mean<f64> for Binomial
[src]
impl Variance<f64> for Binomial
[src]
impl Skewness for Binomial
[src]
impl Kurtosis for Binomial
[src]
impl<'_> From<&'_ Binomial> for String
[src]
impl Clone for Binomial
[src]
impl PartialEq<Binomial> for Binomial
[src]
impl PartialOrd<Binomial> for Binomial
[src]
fn partial_cmp(&self, other: &Binomial) -> Option<Ordering>
[src]
fn lt(&self, other: &Binomial) -> bool
[src]
fn le(&self, other: &Binomial) -> bool
[src]
fn gt(&self, other: &Binomial) -> bool
[src]
fn ge(&self, other: &Binomial) -> bool
[src]
impl Display for Binomial
[src]
impl Debug for Binomial
[src]
Auto Trait Implementations
impl Send for Binomial
impl Sync for Binomial
impl Unpin for Binomial
impl UnwindSafe for Binomial
impl RefUnwindSafe for Binomial
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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<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<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,