pub struct Skellam { /* private fields */ }
Expand description
Skellam distribution over x in {.., -2, -1, 0, 1, … }.
§Example
use rv::prelude::*;
// Create Skellam(μ_1=5.3, μ_2=2.5)
let skel = Skellam::new(5.3, 2.5).unwrap();
// Draw 100 samples
let mut rng = rand::thread_rng();
let xs: Vec<i32> = skel.sample(100, &mut rng);
assert_eq!(xs.len(), 100)
Implementations§
source§impl Skellam
impl Skellam
sourcepub fn new(mu_1: f64, mu_2: f64) -> Result<Self, SkellamError>
pub fn new(mu_1: f64, mu_2: f64) -> Result<Self, SkellamError>
Create a new Skellam distribution with given rates
sourcepub fn new_unchecked(mu_1: f64, mu_2: f64) -> Self
pub fn new_unchecked(mu_1: f64, mu_2: f64) -> Self
Creates a new Skellam without checking whether the parameters are valid.
sourcepub fn mu_1(&self) -> f64
pub fn mu_1(&self) -> f64
Get the mu_1 parameter
§Example
let skel = Skellam::new(2.0, 3.0).unwrap();
assert_eq!(skel.mu_1(), 2.0);
sourcepub fn set_mu_1(&mut self, mu_1: f64) -> Result<(), SkellamError>
pub fn set_mu_1(&mut self, mu_1: f64) -> Result<(), SkellamError>
Set the mu_1 (first rate) parameter
§Example
use rv::dist::Skellam;
let mut skel = Skellam::new(2.0, 1.0).unwrap();
assert_eq!(skel.mu_1(), 2.0);
skel.set_mu_1(1.1).unwrap();
assert_eq!(skel.mu_1(), 1.1);
Will error for invalid values
assert!(skel.set_mu_1(1.1).is_ok());
assert!(skel.set_mu_1(0.0).is_err());
assert!(skel.set_mu_1(-1.0).is_err());
assert!(skel.set_mu_1(std::f64::INFINITY).is_err());
assert!(skel.set_mu_1(std::f64::NEG_INFINITY).is_err());
assert!(skel.set_mu_1(std::f64::NAN).is_err());
sourcepub fn set_mu_1_unchecked(&mut self, mu_1: f64)
pub fn set_mu_1_unchecked(&mut self, mu_1: f64)
Set the mu_1 (first rate) parameter without input validation
sourcepub fn mu_2(&self) -> f64
pub fn mu_2(&self) -> f64
Get the mu_2 parameter
§Example
let skel = Skellam::new(2.0, 3.0).unwrap();
assert_eq!(skel.mu_2(), 3.0);
sourcepub fn set_mu_2(&mut self, mu_2: f64) -> Result<(), SkellamError>
pub fn set_mu_2(&mut self, mu_2: f64) -> Result<(), SkellamError>
Set the mu_2 (second rate) parameter
§Example
use rv::dist::Skellam;
let mut skel = Skellam::new(2.0, 1.0).unwrap();
assert_eq!(skel.mu_2(), 1.0);
skel.set_mu_2(1.1).unwrap();
assert_eq!(skel.mu_2(), 1.1);
Will error for invalid values
assert!(skel.set_mu_2(1.1).is_ok());
assert!(skel.set_mu_2(0.0).is_err());
assert!(skel.set_mu_2(-1.0).is_err());
assert!(skel.set_mu_2(std::f64::INFINITY).is_err());
assert!(skel.set_mu_2(std::f64::NEG_INFINITY).is_err());
assert!(skel.set_mu_2(std::f64::NAN).is_err());
sourcepub fn set_mu_2_unchecked(&mut self, mu_2: f64)
pub fn set_mu_2_unchecked(&mut self, mu_2: f64)
Set the mu_2 (first rate) parameter without input validation
sourcepub fn set_cache_cap(&self, cap: usize)
pub fn set_cache_cap(&self, cap: usize)
Trait Implementations§
source§impl<'de> Deserialize<'de> for Skellam
impl<'de> Deserialize<'de> for Skellam
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<i16> for Skellam
impl DiscreteDistr<i16> for Skellam
source§impl DiscreteDistr<i32> for Skellam
impl DiscreteDistr<i32> for Skellam
source§impl DiscreteDistr<i8> for Skellam
impl DiscreteDistr<i8> for Skellam
source§impl PartialEq for Skellam
impl PartialEq for Skellam
source§impl Rv<i16> for Skellam
impl Rv<i16> for Skellam
source§impl Rv<i32> for Skellam
impl Rv<i32> for Skellam
Auto Trait Implementations§
impl !Freeze for Skellam
impl !RefUnwindSafe for Skellam
impl Send for Skellam
impl !Sync for Skellam
impl Unpin for Skellam
impl UnwindSafe for Skellam
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<Fx> Rv<Datum> for Fxwhere
Fx: RvDatum,
impl<Fx> Rv<Datum> for Fxwhere
Fx: RvDatum,
source§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.