pypomp.random.fast_gamma

pypomp.random.fast_gamma(key: Array, alpha: Array, adjustment_size: int = 3, dtype: dtype | None = None) Array[source]

Generate a Gamma random variable using an approximate inverse CDF method in order to run fast on GPUs.

The implementation follows the methodology from Temme (1992). To extend the method to small alpha values, we apply a multi-step trick. The method does not produce exact Gamma random variables, but it is very close to exact.

Parameters:
  • key – a PRNG key used as the random key.

  • alpha – shape parameters for the Gamma(alpha, 1) distribution.

  • adjustment_size – number of uniform adjustments to apply (default: 3). The function generates Gamma(alpha + adjustment_size) and reduces it to Gamma(alpha) using adjustment_size uniform adjustments. The larger the value, the more accurate the approximation at low alpha values (e.g., alpha < 2).

  • dtype – optional, a float dtype for the returned values (default float64 if jax_enable_x64 is true, otherwise float32).

Returns:

A jax.Array with the same shape as alpha.

References

  • Temme, N. M. “Asymptotic Inversion of Incomplete Gamma Functions.” Mathematics of Computation 58, no. 198 (1992): 755–64. https://doi.org/10.2307/2153214.