[][src]Struct rv::dist::NegBinomial

pub struct NegBinomial { /* fields omitted */ }

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]

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]

impl Rv<u16> for NegBinomial[src]

impl Rv<u32> for NegBinomial[src]

impl Rv<u8> for NegBinomial[src]

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Fx, X> Cdf<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Cdf<X>, 
[src]

impl<Fx, X> DiscreteDistr<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: DiscreteDistr<X>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Fx> Kurtosis for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Kurtosis
[src]

impl<Fx, X> Mean<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Mean<X>, 
[src]

impl<Fx, X> Rv<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Rv<X>, 
[src]

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]

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

impl<Fx, X> Support<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Support<X>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

impl<Fx, X> Variance<X> for Fx where
    Fx: Deref,
    <Fx as Deref>::Target: Variance<X>, 
[src]