pypomp.random.fast_multinomial¶
- pypomp.random.fast_multinomial(key: Array, n: Array, p: Array, order: int = 2, exact_max: int = 5, dtype: dtype | None = None) Array[source]¶
Sample multinomial random variates using a GPU-optimized inverse CDF algorithm.
Generates multinomial counts by sequentially sampling binomial components via
fast_binomial(). Follows the methodology from Giles and Beentjes (2024) [1]. Results are very close to exact but not guaranteed to be identical to a reference sampler.- Parameters:
key (jax.Array) – JAX PRNG key.
n (jax.Array) – Number of trials. Shape
(...,).p (jax.Array) – Category probabilities. Shape
(..., k)wherekis the number of categories. Probabilities along the last axis are normalised automatically.order (int, optional) – Order of the beta-function approximation (0, 1, or 2). Defaults to
2(most accurate).exact_max (int, optional) – Maximum iterations for the bottom-up exact inverse CDF stage. Defaults to
5.dtype (np.dtype or None, optional) – Output dtype (float or integer). Defaults to
float64ifjax_enable_x64=True, otherwisefloat32. Integer dtypes return-1for invalid inputs.
- Returns:
Multinomial count array with the same shape as
pand the specifieddtype.- Return type:
Notes
For speed and accuracy metrics, see the Quant Tests.
References