[−][src]Struct rv::dist::NegBinomial
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
impl NegBinomial
[src]
pub fn new(r: f64, p: f64) -> Result<Self, NegBinomialError>
[src]
Create a new Negative Binomial distribution
pub fn new_unchecked(r: f64, p: f64) -> Self
[src]
Create a new Negative Binomial distribution without input validation.
pub fn r(&self) -> f64
[src]
Get the value of the r
parameter
pub fn set_r(&mut self, r: f64) -> Result<(), NegBinomialError>
[src]
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());
pub fn set_r_unchecked(&mut self, r: f64)
[src]
Set the value of r without input validation
pub fn p(&self) -> f64
[src]
Get the value of the p
parameter
pub fn set_p(&mut self, p: f64) -> Result<(), NegBinomialError>
[src]
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());
pub fn set_p_unchecked(&mut self, p: f64)
[src]
Set the value of p without input validation
Trait Implementations
impl Cdf<u16> for NegBinomial
[src]
impl Cdf<u32> for NegBinomial
[src]
impl Cdf<u8> for NegBinomial
[src]
impl Clone for NegBinomial
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for NegBinomial
[src]
impl DiscreteDistr<u16> for NegBinomial
[src]
impl DiscreteDistr<u32> for NegBinomial
[src]
impl DiscreteDistr<u8> for NegBinomial
[src]
impl Kurtosis for NegBinomial
[src]
impl Mean<f64> for NegBinomial
[src]
impl PartialEq<NegBinomial> for NegBinomial
[src]
fn eq(&self, other: &NegBinomial) -> bool
[src]
#[must_use]fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl Rv<u16> for NegBinomial
[src]
fn ln_f(&self, x: &u16) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u16
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u16>
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl Rv<u32> for NegBinomial
[src]
fn ln_f(&self, x: &u32) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u32
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u32>
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl Rv<u8> for NegBinomial
[src]
fn ln_f(&self, x: &u8) -> f64
[src]
fn draw<R: Rng>(&self, rng: &mut R) -> u8
[src]
fn sample<R: Rng>(&self, n: usize, rng: &mut R) -> Vec<u8>
[src]
fn f(&self, x: &X) -> f64
[src]
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl Skewness for NegBinomial
[src]
impl Support<u16> for NegBinomial
[src]
impl Support<u32> for NegBinomial
[src]
impl Support<u8> for NegBinomial
[src]
impl Variance<f64> for NegBinomial
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
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<Fx, X> Cdf<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Cdf<X>,
impl<Fx, X> DiscreteDistr<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: DiscreteDistr<X>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Fx> Kurtosis for Fx where
Fx: Deref,
<Fx as Deref>::Target: Kurtosis,
[src]
Fx: Deref,
<Fx as Deref>::Target: Kurtosis,
impl<Fx, X> Mean<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Mean<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Mean<X>,
impl<Fx, X> Rv<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Rv<X>,
fn ln_f(&Self, &X) -> f64
[src]
fn f(&Self, &X) -> f64
[src]
fn draw<R>(&Self, &mut R) -> X where
R: Rng,
[src]
R: Rng,
fn sample<R>(&Self, usize, &mut R) -> Vec<X> where
R: Rng,
[src]
R: Rng,
fn sample_stream<'r, R: Rng>(
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
[src]
&'r self,
rng: &'r mut R
) -> Box<dyn Iterator<Item = X> + 'r>
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<Fx> Skewness for Fx where
Fx: Deref,
<Fx as Deref>::Target: Skewness,
[src]
Fx: Deref,
<Fx as Deref>::Target: Skewness,
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<Fx, X> Support<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Support<X>,
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, 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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<Fx, X> Variance<X> for Fx where
Fx: Deref,
<Fx as Deref>::Target: Variance<X>,
[src]
Fx: Deref,
<Fx as Deref>::Target: Variance<X>,