fn

ndtri

Tensor
ndtri(p: Tensor)
source

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

pTensor
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 p; 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=1plop_{hi} = 1 - p_{lo}, in which a rational polynomial in q=p0.5q = p - 0.5 is evaluated, and two symmetric tail regions in which a rational polynomial in r=2logmin(p,1p)r = \sqrt{-2 \log\min(p, 1-p)} is used:

Φ1(p){qNc(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×1091.15 \times 10^{-9} over its supported domain. 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.9600, 0.0000, 1.9600])