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]¶
Generate binomial random variables using a JAX implementation of the inverse incomplete beta function approximation in order to run fast on GPUs.
The implementation follows the methodology from Giles and Beentjes (2024). To more accurately handle cases where np is very small or the random draw is expected to be close to 0 or n, we apply the exact inverse CDF method in a manner similar to Giles (2016). Our implementation of the method does not produce exact binomial random variables, but it is very close to exact.
- Parameters:
key – PRNG key used as the random key.
n – Number of trials for the binomial distribution.
p – Success probability for the binomial distribution.
order – Order of approximation (0, 1, or 2). Default is 2 for best accuracy.
exact_max – Maximum number of loop iterations to perform for the bottom up exact inverse CDF method.
dtype – optional, a float dtype for the returned values (default float64 if jax_enable_x64 is true, otherwise float32). If integer, returns -1 for invalid inputs instead of nan.
- Returns:
Binomial random variables with the same shape as n and p.
References
Giles, Michael B., and Casper Beentjes. “Approximation of an Inverse of the Incomplete Beta Function.” In Mathematical Software – ICMS 2024, vol. 14749. Lecture Notes in Computer Science. Springer Nature Switzerland, 2024. https://doi.org/10.1007/978-3-031-64529-7_22.
Giles, Michael B. “Algorithm 955: Approximation of the Inverse Poisson Cumulative Distribution Function.” ACM Transactions on Mathematical Software 42, no. 1 (2016): 1–22. https://doi.org/10.1145/2699466.