Struct rv::dist::NegBinomial [−][src]
pub struct NegBinomial { /* fields omitted */ }
Expand description
Negative Binomial distribution NBin(r, p).
Notes
This crate uses the parameterization found on Wolfram Mathworld, which is also the parameterization used in scipy.
Parameters
- r: The number of successes before the trials are stopped
- p: The success probability
Implementations
Create a new Negative Binomial distribution
Create a new Negative Binomial distribution without input validation.
Change the value of the r parameter
Example
use rv::dist::NegBinomial; let mut nbin = NegBinomial::new(4.0, 0.8).unwrap(); assert!((nbin.r() - 4.0).abs() < 1E-10); nbin.set_r(2.5).unwrap(); assert!((nbin.r() - 2.5).abs() < 1E-10);
Will error for invalid values
assert!(nbin.set_r(2.0).is_ok()); assert!(nbin.set_r(1.0).is_ok()); // r must be >= 1.0 assert!(nbin.set_r(0.99).is_err()); assert!(nbin.set_r(std::f64::INFINITY).is_err()); assert!(nbin.set_r(std::f64::NEG_INFINITY).is_err()); assert!(nbin.set_r(std::f64::NAN).is_err());
Set the value of r without input validation
Change the value of the p parameter
Example
use rv::dist::NegBinomial; let mut nbin = NegBinomial::new(4.0, 0.8).unwrap(); assert!((nbin.p() - 0.8).abs() < 1E-10); nbin.set_p(0.51).unwrap(); assert!((nbin.p() - 0.51).abs() < 1E-10);
Will error for invalid values
// OK values in [0, 1] assert!(nbin.set_p(0.51).is_ok()); assert!(nbin.set_p(0.0).is_ok()); assert!(nbin.set_p(1.0).is_ok()); // Too low, not in [0, 1] assert!(nbin.set_p(-0.1).is_err()); // Too high, not in [0, 1] assert!(nbin.set_p(-1.1).is_err()); assert!(nbin.set_p(std::f64::INFINITY).is_err()); assert!(nbin.set_p(std::f64::NEG_INFINITY).is_err()); assert!(nbin.set_p(std::f64::NAN).is_err());
Set the value of p without input validation
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NegBinomial
impl Send for NegBinomial
impl Sync for NegBinomial
impl Unpin for NegBinomial
impl UnwindSafe for NegBinomial
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
pub fn vzip(self) -> V