pub struct Gamma<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 ↩