scipy.special.bdtri#
- scipy.special.bdtri(k, n, y, out=None) = <ufunc 'bdtri'>#
Inverse function to
bdtrwith respect to p.Finds the event probability p such that the sum of the terms 0 through k of the binomial probability density is equal to the given cumulative probability y.
- Parameters:
- karray_like
Number of successes (float), rounded down to the nearest integer.
- narray_like
Number of events (float)
- yarray_like
Cumulative probability (probability of k or fewer successes in n events).
- outndarray, optional
Optional output array for the function values
- Returns:
- pscalar or ndarray
The event probability such that bdtr(lfloor k rfloor, n, p) = y.
See also
Notes
The computation is carried out using the inverse beta integral function and the relation,:
1 - p = betaincinv(n - k, k + 1, y).
Wrapper for the Cephes [1] routine
bdtri.Array API Standard Support
bdtrihas 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 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.bdtridoes not currently supportoutfor the PyTorch backend.See Support for the array API standard for more information.
References
[1]Cephes Mathematical Functions Library, https://netlib.org/cephes/
Examples
An “unfair” coin is to be created that has probability p of showing heads when flipped. What is the value of p that will ensure that the probability of getting heads at most once in 4 tosses is 0.5?
Let X be the number of heads. We want to find p such that the probability that X <= k is y, where k is 1, the total number of flips n is 4, and the cumulative probability y is 0.5. This is what
bdtri(k, n, y)computes:>>> from scipy.special import bdtri, bdtr
>>> p = bdtri(1, 4, 0.5) >>> p np.float64(0.3857275681323896)
Verify the result:
>>> bdtr(1, 4, p) # Should be 0.5. np.float64(0.5)