Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::GammaDistribution< RealType > Class Template Reference

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.
 

Detailed Description

template<class RealType = ::celeritas::real_type>
class celeritas::GammaDistribution< RealType >

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:

  1. Set \( d = \alpha - 1/3 \) and \( c = 1 / \sqrt{9d} \)
  2. Generate random variates \( Z \sim N(0,1) \) and \( U \sim U(0,1) \)
  3. Set \( v = (1 + cZ)^3 \)
  4. If \( \log U < Z^2 / 2 + d(1 - v + \log v) \) return \( dv \). Otherwise, go to step 2. A squeeze function can be used to avoid the two logarithms in most cases by accepting early if \( U < 1 - 0.0331 Z^4 \).

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) \).


The documentation for this class was generated from the following file: