Struct rv::dist::BetaBinomial

source ·
pub struct BetaBinomial { /* private fields */ }
Expand description

Beta Binomial distribution over k in {0, …, n}

§Example

use std::f64;
use rv::prelude::*;

let a = 3.0;
let b = 2.0;
let n = 20;

let beta = Beta::new(a, b).unwrap();
let beta_binom = BetaBinomial::new(n, a, b).unwrap();

let beta_mean: f64 = beta.mean().unwrap();
let beta_binom_mean: f64 = beta_binom.mean().unwrap();
assert!( (beta_mean * f64::from(n) - beta_binom_mean).abs() < 1E-12 );

Some functions will panic when given data outside the supported range: [0, n]

let beta_binom = BetaBinomial::new(20, 3.0, 2.0).unwrap();
assert!(!beta_binom.supports(&21_u32));

PMF calls will return 0 for out-of-support data

let f = beta_binom.pmf(&21_u32);
assert_eq!(f, 0.0);

Implementations§

source§

impl BetaBinomial

source

pub fn new(n: u32, alpha: f64, beta: f64) -> Result<Self, BetaBinomialError>

Create a beta-binomal distirbution

§Arguments
  • n: the total number of trials
  • alpha: the prior pseudo obersvations of success
  • beta: the prior pseudo obersvations of failure
source

pub fn new_unchecked(n: u32, alpha: f64, beta: f64) -> Self

Creates a new BetaBinomial without checking whether the parameters are valid.

source

pub fn n(&self) -> u32

Get n, the number of trials.

§Example
use rv::dist::BetaBinomial;
let bb = BetaBinomial::new(10, 1.0, 2.0).unwrap();
assert_eq!(bb.n(), 10);
source

pub fn alpha(&self) -> f64

Get the alpha parameter

§Example
use rv::dist::BetaBinomial;
let bb = BetaBinomial::new(10, 1.0, 2.0).unwrap();
assert_eq!(bb.alpha(), 1.0);
source

pub fn set_alpha(&mut self, alpha: f64) -> Result<(), BetaBinomialError>

Set the alpha parameter

§Example
use rv::dist::BetaBinomial;

let mut bb = BetaBinomial::new(10, 1.0, 5.0).unwrap();

bb.set_alpha(2.0).unwrap();
assert_eq!(bb.alpha(), 2.0);

Will error for invalid values

assert!(bb.set_alpha(0.1).is_ok());
assert!(bb.set_alpha(0.0).is_err());
assert!(bb.set_alpha(-1.0).is_err());
assert!(bb.set_alpha(std::f64::INFINITY).is_err());
assert!(bb.set_alpha(std::f64::NAN).is_err());
source

pub fn set_alpha_unchecked(&mut self, alpha: f64)

Set alpha without input validation

source

pub fn beta(&self) -> f64

Get the beta parameter

§Example
use rv::dist::BetaBinomial;
let bb = BetaBinomial::new(10, 1.0, 2.0).unwrap();
assert_eq!(bb.beta(), 2.0);
source

pub fn set_beta(&mut self, beta: f64) -> Result<(), BetaBinomialError>

Set the beta parameter

§Example
let mut bb = BetaBinomial::new(10, 1.0, 5.0).unwrap();

bb.set_beta(2.0).unwrap();
assert_eq!(bb.beta(), 2.0);

Will error for invalid values

assert!(bb.set_beta(0.1).is_ok());
assert!(bb.set_beta(0.0).is_err());
assert!(bb.set_beta(-1.0).is_err());
assert!(bb.set_beta(std::f64::INFINITY).is_err());
assert!(bb.set_beta(std::f64::NAN).is_err());
source

pub fn set_beta_unchecked(&mut self, beta: f64)

Set beta without input validation

source

pub fn set_n(&mut self, n: u32) -> Result<(), BetaBinomialError>

Set the value of the n parameter

§Example
use rv::dist::BetaBinomial;

let mut bb = BetaBinomial::new(10, 0.5, 0.5).unwrap();

bb.set_n(11).unwrap();

assert_eq!(bb.n(), 11);

Will error for invalid values

assert!(bb.set_n(11).is_ok());
assert!(bb.set_n(1).is_ok());
assert!(bb.set_n(0).is_err());
source

pub fn set_n_unchecked(&mut self, n: u32)

Set the value of n without input validation

Trait Implementations§

source§

impl Cdf<i16> for BetaBinomial

source§

fn cdf(&self, k: &i16) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<i32> for BetaBinomial

source§

fn cdf(&self, k: &i32) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<i64> for BetaBinomial

source§

fn cdf(&self, k: &i64) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<i8> for BetaBinomial

source§

fn cdf(&self, k: &i8) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<u16> for BetaBinomial

source§

fn cdf(&self, k: &u16) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<u32> for BetaBinomial

source§

fn cdf(&self, k: &u32) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<u64> for BetaBinomial

source§

fn cdf(&self, k: &u64) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<u8> for BetaBinomial

source§

fn cdf(&self, k: &u8) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Cdf<usize> for BetaBinomial

source§

fn cdf(&self, k: &usize) -> f64

The value of the Cumulative Density Function at x Read more
source§

fn sf(&self, x: &X) -> f64

Survival function, 1 - CDF(x)
source§

impl Clone for BetaBinomial

source§

fn clone(&self) -> BetaBinomial

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for BetaBinomial

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for BetaBinomial

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl DiscreteDistr<i16> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<i32> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<i64> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<i8> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<u16> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<u32> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<u64> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<u8> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl DiscreteDistr<usize> for BetaBinomial

source§

fn pmf(&self, x: &X) -> f64

Probability mass function (PMF) at x Read more
source§

fn ln_pmf(&self, x: &X) -> f64

Natural logarithm of the probability mass function (PMF) Read more
source§

impl Display for BetaBinomial

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&BetaBinomial> for String

source§

fn from(bb: &BetaBinomial) -> String

Converts to this type from the input type.
source§

impl Mean<f64> for BetaBinomial

source§

fn mean(&self) -> Option<f64>

Returns None if the mean is undefined
source§

impl PartialEq for BetaBinomial

source§

fn eq(&self, other: &BetaBinomial) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rv<i16> for BetaBinomial

source§

fn ln_f(&self, k: &i16) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> i16

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<i16>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<i32> for BetaBinomial

source§

fn ln_f(&self, k: &i32) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> i32

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<i32>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<i64> for BetaBinomial

source§

fn ln_f(&self, k: &i64) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> i64

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<i64>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<i8> for BetaBinomial

source§

fn ln_f(&self, k: &i8) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> i8

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<i8>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<u16> for BetaBinomial

source§

fn ln_f(&self, k: &u16) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> u16

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u16>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<u32> for BetaBinomial

source§

fn ln_f(&self, k: &u32) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> u32

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u32>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<u64> for BetaBinomial

source§

fn ln_f(&self, k: &u64) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> u64

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u64>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<u8> for BetaBinomial

source§

fn ln_f(&self, k: &u8) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> u8

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u8>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Rv<usize> for BetaBinomial

source§

fn ln_f(&self, k: &usize) -> f64

Probability function Read more
source§

fn draw<R: Rng>(&self, rng: &mut R) -> usize

Single draw from the Rv Read more
source§

fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<usize>

Multiple draws of the Rv Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

fn sample_stream<'r, R: Rng>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = X> + 'r>

Create a never-ending iterator of samples Read more
source§

impl Serialize for BetaBinomial

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Support<i16> for BetaBinomial

source§

fn supports(&self, k: &i16) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<i32> for BetaBinomial

source§

fn supports(&self, k: &i32) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<i64> for BetaBinomial

source§

fn supports(&self, k: &i64) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<i8> for BetaBinomial

source§

fn supports(&self, k: &i8) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<u16> for BetaBinomial

source§

fn supports(&self, k: &u16) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<u32> for BetaBinomial

source§

fn supports(&self, k: &u32) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<u64> for BetaBinomial

source§

fn supports(&self, k: &u64) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<u8> for BetaBinomial

source§

fn supports(&self, k: &u8) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Support<usize> for BetaBinomial

source§

fn supports(&self, k: &usize) -> bool

Returns true if x is in the support of the Rv Read more
source§

impl Variance<f64> for BetaBinomial

source§

fn variance(&self) -> Option<f64>

Returns None if the variance is undefined

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Fx> Rv<Datum> for Fx
where Fx: RvDatum,

source§

fn ln_f(&self, x: &Datum) -> f64

Probability function Read more
source§

fn draw<R>(&self, rng: &mut R) -> Datum
where R: Rng,

Single draw from the Rv Read more
source§

fn sample<R>(&self, n: usize, rng: &mut R) -> Vec<Datum>
where R: Rng,

Multiple draws of the Rv Read more
source§

fn sample_stream<'r, R>( &'r self, rng: &'r mut R ) -> Box<dyn Iterator<Item = Datum> + 'r>
where R: Rng,

Create a never-ending iterator of samples Read more
source§

fn f(&self, x: &X) -> f64

Probability function Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> DeserializeOwnedAlias for T

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

impl<T> SendAlias for T

source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,

source§

impl<T> SerializeAlias for T
where T: Serialize,

source§

impl<T> SyncAlias for T