Struct rv::dist::Poisson [−][src]
pub struct Poisson { /* fields omitted */ }
Possion distribution over x in {0, 1, … }.
Example
use rv::prelude::*; // Create Poisson(λ=5.3) let pois = Poisson::new(5.3).unwrap(); // CDF at 5 assert!((pois.cdf(&5_u16) - 0.56347339228807169).abs() < 1E-12); // Draw 100 samples let mut rng = rand::thread_rng(); let xs: Vec<u32> = pois.sample(100, &mut rng); assert_eq!(xs.len(), 100)
The Poisson can have two modes. The modes are distinct only if the rate is an integer.
{ let pois = Poisson::new(2.0).unwrap(); let modes: (u32, u32) = pois.mode().unwrap(); assert_eq!(modes, (1, 2)) } { let pois = Poisson::new(2.1).unwrap(); let modes: (u32, u32) = pois.mode().unwrap(); assert_eq!(modes, (2, 2)) }
If we know that the rate is not an integer, or we only care about one of the modes, we can call mode for an unsigned type, which will return the leftmost (lowest) mode.
let pois = Poisson::new(2.1).unwrap(); let mode: u32 = pois.mode().unwrap(); assert_eq!(mode, 2)
Implementations
impl Poisson
[src]
impl Poisson
[src]pub fn new(rate: f64) -> Result<Self, PoissonError>
[src]
Create a new Poisson distribution with given rate
pub fn new_unchecked(rate: f64) -> Self
[src]
Creates a new Poisson without checking whether the parameter is valid.
pub fn rate(&self) -> f64
[src]
pub fn set_rate(&mut self, rate: f64) -> Result<(), PoissonError>
[src]
Set the rate parameter
Example
use rv::dist::Poisson; let mut pois = Poisson::new(1.0).unwrap(); assert_eq!(pois.rate(), 1.0); pois.set_rate(1.1).unwrap(); assert_eq!(pois.rate(), 1.1);
Will error for invalid values
assert!(pois.set_rate(1.1).is_ok()); assert!(pois.set_rate(0.0).is_err()); assert!(pois.set_rate(-1.0).is_err()); assert!(pois.set_rate(std::f64::INFINITY).is_err()); assert!(pois.set_rate(std::f64::NEG_INFINITY).is_err()); assert!(pois.set_rate(std::f64::NAN).is_err());
pub fn set_rate_unchecked(&mut self, rate: f64)
[src]
Set the rate parameter without input validation
Trait Implementations
impl Clone for Poisson
[src]
impl Clone for Poisson
[src]fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl ConjugatePrior<u16, Poisson> for Gamma
[src]
impl ConjugatePrior<u16, Poisson> for Gamma
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (f64, f64, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u16, Poisson>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u16, Poisson>
) -> f64
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u16, Poisson>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u16) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl ConjugatePrior<u32, Poisson> for Gamma
[src]
impl ConjugatePrior<u32, Poisson> for Gamma
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (f64, f64, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u32, Poisson>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u32, Poisson>
) -> f64
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u32, Poisson>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u32) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl ConjugatePrior<u8, Poisson> for Gamma
[src]
impl ConjugatePrior<u8, Poisson> for Gamma
[src]type Posterior = Self
Type of the posterior distribution
type LnMCache = f64
Type of the ln_m
cache
type LnPpCache = (f64, f64, f64)
Type of the ln_pp
cache
fn posterior(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self
[src]
fn ln_m_cache(&self) -> Self::LnMCache
[src]
fn ln_m_with_cache(
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u8, Poisson>
) -> f64
[src]
&self,
cache: &Self::LnMCache,
x: &DataOrSuffStat<'_, u8, Poisson>
) -> f64
fn ln_pp_cache(&self, x: &DataOrSuffStat<'_, u8, Poisson>) -> Self::LnPpCache
[src]
fn ln_pp_with_cache(&self, cache: &Self::LnPpCache, y: &u8) -> f64
[src]
fn ln_m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn ln_pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn m(&self, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
fn pp(&self, y: &X, x: &DataOrSuffStat<'_, X, Fx>) -> f64
[src]
impl ContinuousDistr<Poisson> for Gamma
[src]
impl ContinuousDistr<Poisson> for Gamma
[src]impl DiscreteDistr<u16> for Poisson
[src]
impl DiscreteDistr<u16> for Poisson
[src]impl DiscreteDistr<u32> for Poisson
[src]
impl DiscreteDistr<u32> for Poisson
[src]impl DiscreteDistr<u8> for Poisson
[src]
impl DiscreteDistr<u8> for Poisson
[src]impl HasSuffStat<u16> for Poisson
[src]
impl HasSuffStat<u16> for Poisson
[src]type Stat = PoissonSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl HasSuffStat<u32> for Poisson
[src]
impl HasSuffStat<u32> for Poisson
[src]type Stat = PoissonSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl HasSuffStat<u8> for Poisson
[src]
impl HasSuffStat<u8> for Poisson
[src]type Stat = PoissonSuffStat
fn empty_suffstat(&self) -> Self::Stat
[src]
impl KlDivergence for Poisson
[src]
impl KlDivergence for Poisson
[src]Auto Trait Implementations
impl RefUnwindSafe for Poisson
impl RefUnwindSafe for Poisson
impl UnwindSafe for Poisson
impl UnwindSafe for Poisson
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>,