pypomp.random.fast_gamma¶
- pypomp.random.fast_gamma(key: Array, alpha: Array, dtype: dtype | None = None, adjustment_size: int = 3, newton_steps: int = 3) Array[source]¶
Sample Gamma random variates using a GPU-optimized inverse CDF algorithm.
Generates Gamma(alpha, 1)-distributed samples using an approximate inverse CDF method based on Temme (1992) [1]. A multi-step adjustment trick extends accuracy to
alphavalues less than 2. Results are very close to exact but not guaranteed to be identical to a reference sampler.- Parameters:
key (jax.Array) – JAX PRNG key.
alpha (jax.Array) – Shape parameter(s) for the Gamma(alpha, 1) distribution. Must be positive.
dtype (np.dtype or None, optional) – Floating-point output dtype. Defaults to
float64ifjax_enable_x64=True, otherwisefloat32.adjustment_size (int, optional) – Number of uniform adjustments to apply for small-
alphaaccuracy. Defaults to3.newton_steps (int, optional) – Number of Newton-Raphson refinement steps. Defaults to
3.
- Returns:
Gamma samples with the same shape as
alpha.- Return type:
Notes
For speed and accuracy metrics, see the Quant Tests.
Examples
>>> import jax >>> import jax.numpy as jnp >>> from pypomp.random import fast_gamma >>> fast_gamma(jax.random.key(0), alpha=jnp.array(2.0)) Array(1.8..., dtype=float32)
References