You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the asymptotic Mills ratio in the far lower tail (DLMF 7.12.1)
The scaled_diff < -29 branch took the Abramowitz & Stegun negative-tail
approximation and added a cubic residual fit whose leading term is
0.0015065154280332 * x2. That term grows quadratically in scaled_diff.
DLMF 7.12.1 gives, for y = -scaled_diff > 0,
erfc(y) ~ (exp(-y^2) / (sqrt(pi) y)) * sum_m (-1)^m (1/2)_m / y^(2m)
and since dncdf_log = (2/sqrt(pi)) exp(-y^2) / erfc(y), this is
dncdf_log ~ 2y / (1 - 1/(2y^2) + 3/(4y^4) - 15/(8y^6) + ...)
so dncdf_log grows LINEARLY, as -2*scaled_diff. A quadratic residual fit
cannot track a linear asymptote; it must eventually dominate. Measured
relative error of the old branch against a 60-digit mpmath reference:
scaled_diff -29 -40 -75 -100 -1000
old 9.5e-06 1.9e-04 1.0e-02 2.3e-02 6.8e-01
new 1.3e-11 1.0e-12 6.5e-15 7.0e-16 7.8e-18
At scaled_diff = -1000 the old branch is 68% wrong. In y terms (mu=0,
sigma=1) the gradient passes 1e-4 relative error at y = -54.46 and 1e-2 at
y = -106.06. This is a plain first-order var gradient, so it corrupts HMC
transitions, not just Hessians -- and PR #3363's reflection newly exposes it
on the lccdf side at large positive y.
Replacing the branch with the truncated asymptotic is also exponential-free:
no erf, no exp, nothing that can overflow. DLMF states the remainder is
bounded by the first neglected term for real argument, which at
scaled_diff = -29 is 6.5625/29^8 = 1.3e-11, matching the measured error.
The seam at scaled_diff = -29 moves from 3.3e-06 to 6.2e-06 relative, still
well inside the existing inter-branch jumps (~2.7e-5 at scaled_diff = 2.9).
Also corrects the sqrt(2) scaling in the new rev sweep assertions: dncdf_log
is d/d(scaled_diff), while the reported partial is dncdf_log/(sigma*sqrt(2)).
The discrete mpmath-referenced cases were unaffected. Verified the corrected
sweep is still red without this fix and green with it.
All P1, P2 and P3 tests now pass across prim, rev, fwd and mix.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
0 commit comments