Skip to content
fn

ndtri

→Tensor
ndtri(input: Tensor)

Inverse standard normal CDF (probit / quantile function).

Computes Φ−1(p)\Phi^{-1}(p), the quantile function of the standard normal distribution. This is the workhorse for sampling Gaussian variates from uniforms via inverse-CDF, for probit regression, and for converting tail probabilities back to standard scores.

Parameters

inputTensor
Input tensor of probabilities in (0,1)(0, 1); any floating-point dtype.

Returns

Tensor

Φ−1(p)\Phi^{-1}(p) element-wise, same shape and dtype as input; values are unbounded reals.

Notes

The implementation uses the Beasley-Springer-Moro rational approximation. The unit interval is split into a central region [plo,phi][p_{lo}, p_{hi}] with plo=0.02425p_{lo} = 0.02425, phi=1−plop_{hi} = 1 - p_{lo}, in which a rational polynomial in q=p−0.5q = p - 0.5 is evaluated, and two symmetric tail regions in which a rational polynomial in r=−2log⁡min⁡(p,1−p)r = \sqrt{-2 \log\min(p, 1-p)} is used:

Φ−1(p)≈{q⋅Nc(q2)Dc(q2),p∈[plo,phi]±Nt(r)Dt(r),otherwise.\Phi^{-1}(p) \approx \begin{cases} q \cdot \frac{N_c(q^2)}{D_c(q^2)}, & p \in [p_{lo}, p_{hi}] \\[4pt] \pm \frac{N_t(r)}{D_t(r)}, & \text{otherwise}. \end{cases}

The approximation is accurate to roughly 1.15×10−91.15 \times 10^{-9} over its supported domain, which is as much as float32 holds. A float64 input gets one Newton step on top of it, taken where each stretch keeps its relative precision (on Φ(x)−p\Phi(x) - p in the centre, on log⁡Φ(x)−log⁡p\log\Phi(x) - \log p in the tails), and is then accurate to the last few digits across 10−30010^{-300} to 1−10−161 - 10^{-16}. Boundary behaviour: Φ−1(0.5)=0\Phi^{-1}(0.5) = 0, and the function blows up to ∓∞\mp \infty at the endpoints.

Examples

>>> import lucid
>>> from lucid.special import ndtri
>>> ndtri(lucid.tensor([0.025, 0.5, 0.975]))
tensor([-1.96, 0., 1.96])