fix: Stabilize beta CDF and extreme quantiles - #447
Open
day01 wants to merge 62 commits into
Open
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #447 +/- ##
==========================================
+ Coverage 95.07% 95.13% +0.06%
==========================================
Files 62 90 +28
Lines 14191 17128 +2937
==========================================
+ Hits 13492 16295 +2803
- Misses 699 833 +134 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
day01
marked this pull request as ready for review
August 13, 2026 09:08
Contributor
Author
|
@YeungOnion i take a boost impl and few articles impl. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause
The forward path formed ill-conditioned gamma and power differences in
f64; cancellation eventually drove a valid CDF outside[0, 1]. The inverse path clamped its initial estimate away from zero and iterated on an underflowing value-domain CDF, causing the fixed~1e-17floor, non-monotonic results, non-termination, and an unchecked error panic.The replacement uses DLMF 8.17, DLMF 8.18.9–12, TOMS Algorithm 708, and Temme, Special Functions (1996), section 11.3.3.2. Boost-derived kernels are attributed and distributed under BSL-1.0 in
THIRD_PARTY_NOTICES.md.TDD and independent numerical references
The issue reproducers fail on upstream and pass with this change. Inputs are passed to every reference as their exact binary64 values. The columns below are signed ULP error against 500-digit MPFR/Boost.Multiprecision references; the endpoint uses the exact
I_x(2,b)identity at 1100 digits.0is correctly rounded.Cases: center
I_0.5(1e8, 1e8); asymmetricI_x(1e8, 2e8)atx=0.33330611678068106; inverse cases(a,b,p)=(200,2,1e-60),(200,2,1e-165),(0.1,500,1e-30), and the endpoint(2,1e308,0.5).p=1e-60p=1e-165[0,1]+2,922,987,503+4,288,298,043,698,456,8680-10000+15+15,949,984+120+30+15+15,949,984+120+300+89100-234000SciPy's beta kernels are Boost-backed, so SciPy and Boost are not independent references. mpmath is independent; MPFR/Boost.Multiprecision is used only as the high-precision arithmetic oracle, not as the Boost.Math implementation under test. A separate 1763-case endpoint audit around rounding thresholds found no error above 1 ULP; a theoretically unresolved adjacent-float overlap selects the monotone ties-to-even result without panicking.
Performance
[0,1]bendpointp=1e-60target-cpu=native-O3 -march=native00Timings are scalar-call latency; a faster time does not imply a correct result—the accuracy table applies. mpmath is an accuracy oracle rather than a production-speed competitor. Batched SciPy/R throughput is measured separately and is not presented as scalar latency.
Related issues
Fixes #434 —
Beta::cdfloses accuracy above shapes of ~1e4 and returns values outside [0, 1] by 1e8.Fixes #435 —
inv_beta_regpanics, does not return, and is non-monotone for smallx.