Struct rv::dist::BetaBinomial [−][src]
pub struct BetaBinomial { /* fields omitted */ }
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));
The following will panic because 21 is out of the support
ⓘ
beta_binom.pmf(&21_u32); // panics
Implementations
impl BetaBinomial
[src]
impl BetaBinomial
[src]pub fn new(n: u32, alpha: f64, beta: f64) -> Result<Self, BetaBinomialError>
[src]
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
pub fn new_unchecked(n: u32, alpha: f64, beta: f64) -> Self
[src]
Creates a new BetaBinomial without checking whether the parameters are valid.
pub fn n(&self) -> u32
[src]
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);
pub fn alpha(&self) -> f64
[src]
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);
pub fn set_alpha(&mut self, alpha: f64) -> Result<(), BetaBinomialError>
[src]
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());
pub fn set_alpha_unchecked(&mut self, alpha: f64)
[src]
Set alpha without input validation
pub fn beta(&self) -> f64
[src]
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);
pub fn set_beta(&mut self, beta: f64) -> Result<(), BetaBinomialError>
[src]
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());
pub fn set_beta_unchecked(&mut self, beta: f64)
[src]
Set beta without input validation
pub fn set_n(&mut self, n: u32) -> Result<(), BetaBinomialError>
[src]
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());
pub fn set_n_unchecked(&mut self, n: u32)
[src]
Set the value of n without input validation
Trait Implementations
impl Cdf<i16> for BetaBinomial
[src]
impl Cdf<i16> for BetaBinomial
[src]impl Cdf<i32> for BetaBinomial
[src]
impl Cdf<i32> for BetaBinomial
[src]impl Cdf<i64> for BetaBinomial
[src]
impl Cdf<i64> for BetaBinomial
[src]impl Cdf<u16> for BetaBinomial
[src]
impl Cdf<u16> for BetaBinomial
[src]impl Cdf<u32> for BetaBinomial
[src]
impl Cdf<u32> for BetaBinomial
[src]impl Cdf<u64> for BetaBinomial
[src]
impl Cdf<u64> for BetaBinomial
[src]impl Cdf<usize> for BetaBinomial
[src]
impl Cdf<usize> for BetaBinomial
[src]impl Clone for BetaBinomial
[src]
impl Clone for BetaBinomial
[src]fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl DiscreteDistr<i16> for BetaBinomial
[src]
impl DiscreteDistr<i16> for BetaBinomial
[src]impl DiscreteDistr<i32> for BetaBinomial
[src]
impl DiscreteDistr<i32> for BetaBinomial
[src]impl DiscreteDistr<i64> for BetaBinomial
[src]
impl DiscreteDistr<i64> for BetaBinomial
[src]impl DiscreteDistr<i8> for BetaBinomial
[src]
impl DiscreteDistr<i8> for BetaBinomial
[src]impl DiscreteDistr<u16> for BetaBinomial
[src]
impl DiscreteDistr<u16> for BetaBinomial
[src]impl DiscreteDistr<u32> for BetaBinomial
[src]
impl DiscreteDistr<u32> for BetaBinomial
[src]impl DiscreteDistr<u64> for BetaBinomial
[src]
impl DiscreteDistr<u64> for BetaBinomial
[src]impl DiscreteDistr<u8> for BetaBinomial
[src]
impl DiscreteDistr<u8> for BetaBinomial
[src]impl DiscreteDistr<usize> for BetaBinomial
[src]
impl DiscreteDistr<usize> for BetaBinomial
[src]impl PartialEq<BetaBinomial> for BetaBinomial
[src]
impl PartialEq<BetaBinomial> for BetaBinomial
[src]impl Rv<i16> for BetaBinomial
[src]
impl Rv<i16> for BetaBinomial
[src]impl Rv<i32> for BetaBinomial
[src]
impl Rv<i32> for BetaBinomial
[src]impl Rv<i64> for BetaBinomial
[src]
impl Rv<i64> for BetaBinomial
[src]impl Rv<i8> for BetaBinomial
[src]
impl Rv<i8> for BetaBinomial
[src]impl Rv<u16> for BetaBinomial
[src]
impl Rv<u16> for BetaBinomial
[src]impl Rv<u32> for BetaBinomial
[src]
impl Rv<u32> for BetaBinomial
[src]impl Rv<u64> for BetaBinomial
[src]
impl Rv<u64> for BetaBinomial
[src]impl Rv<u8> for BetaBinomial
[src]
impl Rv<u8> for BetaBinomial
[src]impl Rv<usize> for BetaBinomial
[src]
impl Rv<usize> for BetaBinomial
[src]Auto Trait Implementations
impl RefUnwindSafe for BetaBinomial
impl RefUnwindSafe for BetaBinomial
impl Send for BetaBinomial
impl Send for BetaBinomial
impl Sync for BetaBinomial
impl Sync for BetaBinomial
impl Unpin for BetaBinomial
impl Unpin for BetaBinomial
impl UnwindSafe for BetaBinomial
impl UnwindSafe for BetaBinomial
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>,