Celeritas
0.5.0-56+6b053cd
|
Sample from a gamma distribution. More...
#include <GammaDistribution.hh>
Public Types | |
Type aliases | |
using | real_type = RealType |
using | result_type = real_type |
Public Member Functions | |
CELER_FUNCTION | GammaDistribution (real_type alpha=1, real_type beta=1) |
Construct from the shape and scale parameters. | |
template<class Generator > | |
CELER_FUNCTION result_type | operator() (Generator &rng) |
template<class Generator > | |
CELER_FUNCTION auto | operator() (Generator &rng) -> result_type |
Sample a random number according to the distribution. | |
Sample from a gamma distribution.
The gamma distribution can be parameterized with a shape parameter \( \alpha \) and a scale parameter \( \beta \) and has the PDF:
\[ f(x; \alpha, \beta) = \frac{x^{\alpha - 1} e^{-x / \beta}}{\beta^\alpha \Gamma(\alpha)} \quad \mathrm{for}\ x > 0, \quad \alpha, \beta > 0 \]
The algorithm described in Marsaglia and Tsang [MT00] is used here to generate gamma-distributed random variables. The steps are:
Though this method is valid for \( \alpha \ge 1 \), it can easily be extended for \( \alpha < 1 \): if \( X \sim \Gamma(\alpha + 1) \) and \( U \sim U(0,1) \), then \( X U^{1/\alpha} \sim \Gamma(\alpha) \).