Repository navigation
fix(distributions): improve lower tail numerical stability in Moyal logcdf (#8437) - #8438
sonusharma6-dsa wants to merge 4 commits into
Conversation
a093327 to
c9d642b
Compare
|
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
|
The added lower-tail regression test appears to need a different reference. At a9e414d, line 963, In SciPy 1.18.0, For from scipy.special import log_ndtr
# For this test's mu=0, sigma=1 and xs=[-10, -20, -50]:
expected = np.log(2.0) + log_ndtr(-np.exp(-xs / 2.0))
assert np.isfinite(expected).all()
assert np.isfinite(res).all()
np.testing.assert_allclose(res, expected, rtol=1e-5)I checked the pinned source paths and a standard-library Prepared with Codex for a source-based numerical-methods clarification. Affiliation: Bharath Healthcare / Pinnacle Blooms Network. |
|
Thanks for catching this. I missed that I'll switch to the |
Description
In
pymc.distributions.continuous.Moyal.logcdf,reswas previously computed aspt.log(pt.erfc(pt.exp(-scaled / 2) * (2**-0.5))). For large negativevalue(scaled = (value - mu) / sigma << 0),pt.exp(-scaled / 2)grows large, causingpt.erfc(...)to underflow to0.0andpt.log(0.0)to return-inf.This PR switches to
pt.erfcx(u)foru > 1.0using the identitylog(erfc(u)) = log(erfcx(u)) - u**2, preventing premature numerical underflow to-infin the lower tail while maintaining double-precision accuracy across all inputs.Added unit test
test_moyal_logcdf_lower_tailintests/distributions/test_continuous.py.Related Issue
Checklist
Type of change