pub struct RandGamma<F>{ /* private fields */ }Expand description
The Gamma distribution Gamma(k, θ).
The Gamma distribution is a continuous probability distribution
with shape parameter k > 0 (number of events) and
scale parameter θ > 0 (mean waiting time between events).
It describes the time until k events occur in a Poisson
process with rate 1/θ. It is the generalization of the
Exponential distribution.
§Density function
f(x) = x^(k - 1) * exp(-x / θ) / (Γ(k) * θ^k) for x > 0,
where Γ is the gamma function.
§Plot
The following plot illustrates the Gamma distribution with
various values of k and θ.
Curves with θ = 1 are more saturated, while corresponding
curves with θ = 2 have a lighter color.
§Example
use rand_distr::{Distribution, Gamma};
let gamma = Gamma::new(2.0, 5.0).unwrap();
let v = gamma.sample(&mut rand::rng());
println!("{} is from a Gamma(2, 5) distribution", v);§Notes
The algorithm used is that described by Marsaglia & Tsang 20001,
falling back to directly sampling from an Exponential for shape == 1, and using the boosting technique described in that paper for
shape < 1.
George Marsaglia and Wai Wan Tsang. 2000. “A Simple Method for Generating Gamma Variables” ACM Trans. Math. Softw. 26, 3 (September 2000), 363-372. DOI:10.1145/358407.358414 ↩
Implementations§
Trait Implementations§
Source§impl<F> Clone for Gamma<F>where
F: Clone + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
impl<F> Clone for Gamma<F>where
F: Clone + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
Source§impl<F> Debug for Gamma<F>where
F: Debug + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
impl<F> Debug for Gamma<F>where
F: Debug + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
Source§impl<F> Distribution<F> for Gamma<F>
impl<F> Distribution<F> for Gamma<F>
Source§impl<F> PartialEq for Gamma<F>where
F: PartialEq + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
impl<F> PartialEq for Gamma<F>where
F: PartialEq + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
impl<F> Copy for Gamma<F>where
F: Copy + Float,
StandardNormal: Distribution<F>,
Exp1: Distribution<F>,
Open01: Distribution<F>,
impl<F> StructuralPartialEq for Gamma<F>
Auto Trait Implementations§
impl<F> Freeze for Gamma<F>where
F: Freeze,
impl<F> RefUnwindSafe for Gamma<F>where
F: RefUnwindSafe,
impl<F> Send for Gamma<F>where
F: Send,
impl<F> Sync for Gamma<F>where
F: Sync,
impl<F> Unpin for Gamma<F>where
F: Unpin,
impl<F> UnwindSafe for Gamma<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.