pub struct Poisson<F>(/* private fields */)
where
F: Float + FloatConst,
StandardUniform: Distribution<F>;Expand description
The Poisson distribution Poisson(λ).
The Poisson distribution is a discrete probability distribution with
rate parameter λ (lambda). It models the number of events occurring in a fixed
interval of time or space.
This distribution has density function:
f(k) = λ^k * exp(-λ) / k! for k >= 0.
§Plot
The following plot shows the Poisson distribution with various values of λ.
Note how the expected number of events increases with λ.
§Example
use rand_distr::{Poisson, Distribution};
let poi = Poisson::new(2.0).unwrap();
let v: f64 = poi.sample(&mut rand::rng());
println!("{} is from a Poisson(2) distribution", v);§Integer vs FP return type
This implementation uses floating-point (FP) logic internally.
Due to the parameter limit λ < Self::MAX_LAMBDA, it
statistically impossible to sample a value larger u64::MAX. As such, it
is reasonable to cast generated samples to u64 using as:
distr.sample(&mut rng) as u64 (and memory safe since Rust 1.45).
Similarly, when λ < 4.2e9 it can be safely assumed that samples are less
than u32::MAX.
Implementations§
Source§impl<F> Poisson<F>
impl<F> Poisson<F>
Sourcepub const MAX_LAMBDA: f64 = 1.844E+19f64
pub const MAX_LAMBDA: f64 = 1.844E+19f64
The maximum supported value of lambda
This value was selected such that
MAX_LAMBDA + 1e6 * sqrt(MAX_LAMBDA) < 2^64 - 1,
thus ensuring that the probability of sampling a value larger than
u64::MAX is less than 1e-1000.
Applying this limit also solves #1312.
Trait Implementations§
Source§impl<F> Distribution<F> for Poisson<F>where
F: Float + FloatConst,
StandardUniform: Distribution<F>,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
impl<F> Distribution<F> for Poisson<F>where
F: Float + FloatConst,
StandardUniform: Distribution<F>,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
impl<F> Copy for Poisson<F>
impl<F> StructuralPartialEq for Poisson<F>
Auto Trait Implementations§
impl<F> Freeze for Poisson<F>where
F: Freeze,
impl<F> RefUnwindSafe for Poisson<F>where
F: RefUnwindSafe,
impl<F> Send for Poisson<F>where
F: Send,
impl<F> Sync for Poisson<F>where
F: Sync,
impl<F> Unpin for Poisson<F>where
F: Unpin,
impl<F> UnwindSafe for Poisson<F>where
F: UnwindSafe,
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D, T> DistributionExt<T> for Dwhere
D: Distribution<T>,
impl<D, T> DistributionExt<T> for Dwhere
D: Distribution<T>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.