fn

log_ndtr

Tensor
log_ndtr(x: Tensor)
source

Numerically stable logarithm of the standard normal CDF.

Computes logΦ(x)\log \Phi(x) without losing precision in the deep left tail, where the direct composition log(ndtr(x)) underflows. Essential for log-likelihood evaluation of probit / Tobit / censored models that need to handle x0x \ll 0 cleanly.

Parameters

xTensor
Input tensor; any floating-point dtype.

Returns

Tensor

logΦ(x)\log \Phi(x) element-wise, same shape and dtype as x; values lie in (,0](-\infty, 0].

Notes

The implementation switches strategies on a branch boundary at x = -1:

logΦ(x)={logΦ(x),x1log ⁣(12erfc(x/2)),x<1.\log \Phi(x) = \begin{cases} \log \Phi(x), & x \ge -1 \\[2pt] \log\!\left(\tfrac{1}{2}\, \mathrm{erfc}(-x/\sqrt{2})\right), & x < -1. \end{cases}

For x1x \ge -1 we have Φ(x)0.16\Phi(x) \gtrsim 0.16 so the direct log(ndtr(x)) is safe. Below x=1x = -1 the identity Φ(x)=12erfc(x/2)\Phi(x) = \tfrac{1}{2}\,\mathrm{erfc}(-x/\sqrt{2}) is used, sidestepping the catastrophic cancellation in 1+erf(x/2)1 + \mathrm{erf}(x/\sqrt{2}).

Examples

>>> import lucid
>>> from lucid.special import log_ndtr
>>> log_ndtr(lucid.tensor([-10.0, -1.0, 0.0, 1.0]))
Tensor([-52.6651, -1.8410, -0.6931, -0.1727])