Struct rv::dist::NegBinomial
source · pub struct NegBinomial { /* private fields */ }
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§
source§impl NegBinomial
impl NegBinomial
sourcepub fn new(r: f64, p: f64) -> Result<Self, NegBinomialError>
pub fn new(r: f64, p: f64) -> Result<Self, NegBinomialError>
Create a new Negative Binomial distribution
sourcepub fn new_unchecked(r: f64, p: f64) -> Self
pub fn new_unchecked(r: f64, p: f64) -> Self
Create a new Negative Binomial distribution without input validation.
sourcepub fn set_r(&mut self, r: f64) -> Result<(), NegBinomialError>
pub fn set_r(&mut self, r: f64) -> Result<(), NegBinomialError>
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(f64::INFINITY).is_err());
assert!(nbin.set_r(f64::NEG_INFINITY).is_err());
assert!(nbin.set_r(f64::NAN).is_err());
sourcepub fn set_r_unchecked(&mut self, r: f64)
pub fn set_r_unchecked(&mut self, r: f64)
Set the value of r without input validation
sourcepub fn set_p(&mut self, p: f64) -> Result<(), NegBinomialError>
pub fn set_p(&mut self, p: f64) -> Result<(), NegBinomialError>
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(f64::INFINITY).is_err());
assert!(nbin.set_p(f64::NEG_INFINITY).is_err());
assert!(nbin.set_p(f64::NAN).is_err());
sourcepub fn set_p_unchecked(&mut self, p: f64)
pub fn set_p_unchecked(&mut self, p: f64)
Set the value of p without input validation
Trait Implementations§
source§impl Cdf<u16> for NegBinomial
impl Cdf<u16> for NegBinomial
source§impl Cdf<u32> for NegBinomial
impl Cdf<u32> for NegBinomial
source§impl Cdf<u8> for NegBinomial
impl Cdf<u8> for NegBinomial
source§impl Clone for NegBinomial
impl Clone for NegBinomial
source§fn clone(&self) -> NegBinomial
fn clone(&self) -> NegBinomial
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for NegBinomial
impl Debug for NegBinomial
source§impl<'de> Deserialize<'de> for NegBinomial
impl<'de> Deserialize<'de> for NegBinomial
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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<u16> for NegBinomial
impl DiscreteDistr<u16> for NegBinomial
source§impl DiscreteDistr<u32> for NegBinomial
impl DiscreteDistr<u32> for NegBinomial
source§impl DiscreteDistr<u8> for NegBinomial
impl DiscreteDistr<u8> for NegBinomial
source§impl HasDensity<u16> for NegBinomial
impl HasDensity<u16> for NegBinomial
source§impl HasDensity<u32> for NegBinomial
impl HasDensity<u32> for NegBinomial
source§impl HasDensity<u8> for NegBinomial
impl HasDensity<u8> for NegBinomial
source§impl Mean<f64> for NegBinomial
impl Mean<f64> for NegBinomial
source§impl Parameterized for NegBinomial
impl Parameterized for NegBinomial
type Parameters = NegBinomialParameters
fn emit_params(&self) -> Self::Parameters
fn from_params(params: Self::Parameters) -> Self
source§impl PartialEq for NegBinomial
impl PartialEq for NegBinomial
source§fn eq(&self, other: &NegBinomial) -> bool
fn eq(&self, other: &NegBinomial) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Sampleable<u16> for NegBinomial
impl Sampleable<u16> for NegBinomial
source§impl Sampleable<u32> for NegBinomial
impl Sampleable<u32> for NegBinomial
source§impl Sampleable<u8> for NegBinomial
impl Sampleable<u8> for NegBinomial
source§impl Serialize for NegBinomial
impl Serialize for NegBinomial
source§impl Support<u16> for NegBinomial
impl Support<u16> for NegBinomial
source§impl Support<u32> for NegBinomial
impl Support<u32> for NegBinomial
source§impl Support<u8> for NegBinomial
impl Support<u8> for NegBinomial
Auto Trait Implementations§
impl !Freeze for NegBinomial
impl RefUnwindSafe for NegBinomial
impl Send for NegBinomial
impl Sync for NegBinomial
impl Unpin for NegBinomial
impl UnwindSafe for NegBinomial
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.