scipy.special.bdtrin#
- scipy.special.bdtrin(k, y, p, out=None) = <wrapped_ufunc 'bdtrin'>#
Inverse function to
bdtrwith respect to n.Finds the number of events n such that the sum of the terms 0 through k of the Binomial probability density for events with probability p is equal to the given cumulative probability y.
- Parameters:
- karray_like
Number of successes (float).
- yarray_like
Cumulative probability (probability of k or fewer successes in n events).
- parray_like
Success probability (float).
- outndarray, optional
Optional output array for the function values
- Returns:
- nscalar or ndarray
The number of events n such that bdtr(k, n, p) = y.
See also
Notes
This function uses the find_minimum_number_of_trials method of the binomial_distribution class of the Boost.Math C++ library [1].
Array API Standard Support
bdtrinhas support for Python Array API Standard compatible backends in addition to NumPy. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
⛔
PyTorch
✅
⛔
JAX
✅
⛔
Dask
✅
n/a
For the NumPy backend, this function supports all NumPy ufunc keyword arguments. Other backends may support
out, but typically none of the other ufunc kwargs.outis typically supported for CuPy and PyTorch, but not currently in cases where SciPy relies on a generic Array API implementation or, for PyTorch on CPU, falls back to the NumPy backend.outis never supported for JAX because JAX arrays are immutable.bdtrindoes not currently supportoutfor the PyTorch backend.See Support for the array API standard for more information.
References
[1]The Boost Developers. “Boost C++ Libraries”. https://www.boost.org/.
Examples
What is the largest number of times we can flip a fair coin and still have at least a 90% chance of getting 10 or fewer heads?
bdtrinanswers this question:>>> import scipy.special as sc >>> k = 10 # maximum number of heads >>> p = 0.5 # probability of flipping heads >>> y = 0.9 # cumulative probability >>> result = sc.bdtrin(k, y, p) >>> result np.float64(15.90442928275109)
To verify, compute the cumulative probability of getting 10 or fewer successes in 15 trials with probability 0.5 using the binomial distribution from
scipy.stats. Since the cumulative probability decreases as the number of trials increases, we round down to the nearest integer:>>> from scipy.stats import Binomial >>> Binomial(n=15, p=p).cdf(k) np.float64(0.940765380859375)