pypomp.random.fast_binomial¶
- pypomp.random.fast_binomial(key: Array, n: Array, p: Array, order: int = 2, exact_max: int = 5, dtype: dtype | None = None) Array[source]¶
Sample binomial random variates using a GPU-optimized inverse CDF algorithm.
Generates binomial counts with parameters
(n, p)using an approximate inverse incomplete beta function method. The implementation follows Giles and Beentjes (2024) [1], with an optional exact inverse CDF correction for small or extreme quantiles. 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 Bernoulli trials.
p (jax.Array) – Success probability in
[0, 1].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:
Binomial samples with the broadcast shape of
nandpand the specifieddtype.- 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_binomial >>> fast_binomial(jax.random.key(0), n=jnp.array(10), p=jnp.array(0.3)) Array(3., dtype=float32)
References