Repository navigation
fix(stats/base/dists/f/cdf): swap betainc branches to avoid cancellation for small x - #16660
wanjinhao1 wants to merge 2 commits into
Conversation
…ion for small x For d1*x <= d2, evaluate the regularized incomplete beta at the small argument (d1*x)/(d2+d1*x) instead of its nearly-one complement, which lost most significant digits for small x and returned exactly 0 once d1*x/d2 fell below ~1e-16. Aligns the branch selection with Boost's fisher_f CDF. Fixes stdlib-js#16655
|
Hello! Thank you for your contribution to stdlib. We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
This acknowledgment confirms that you've read the guidelines, which include:
We can't review or accept contributions without this acknowledgment. Thank you for your understanding and cooperation. We look forward to reviewing your contribution! |
Coverage Report
The above coverage report was generated for the changes in this PR. |
|
@wanjinhao1 Mind providing a link to the line in Boost source code which aligns with this change? Cheers! |
|
@anandkaranubc Once the Boost source link is provided, would you mind taking a look at this? I am wondering if we also need to adjust test tolerances. |
|
Sure! The change aligns with Boost's return v1x > df2
? BOOST_MATH_NAMESPACE::ibetac(df2 / 2, df1 / 2, df2 / (df2 + v1x), Policy())
: BOOST_MATH_NAMESPACE::ibeta(df1 / 2, df2 / 2, v1x / (df2 + v1x), Policy());i.e., Boost uses the direct (non-complemented) incomplete beta when |
|
The contributing-guidelines acknowledgment checkbox is checked in the PR description, but the |
Resolves #16655.
Description
This pull request:
betaincbranches in the F distribution CDF (lib/main.js,lib/factory.js,src/main.c) so that whend1*x <= d2the regularized incomplete beta is evaluated at the small argument(d1*x)/(d2+d1*x)instead of its nearly-one complementd2/(d2+d1*x), which lost most significant digits for smallxand returned exactly0onced1*x/d2fell below ~1e-16. This aligns the branch selection with Boost'sfisher_fCDF.Related Issues
This pull request has the following related issues:
stats/base/dists/f/cdfloses accuracy for small x and returns 0 for very small x #16655Reference Packages
This pull request followed these packages:
fisher_fCDF branch selectionVerification
cdf(1e-20, 2, 3)→1e-20;cdf(1e-12, 2, 3)→9.999999999991665e-13;cdf(1e-12, 10, 30)→4.785185185158598e-59(matches the mpmath/SciPy reference values in [BUG]:stats/base/dists/f/cdfloses accuracy for small x and returns 0 for very small x #16655).large_d1,large_d2,both_large) pass with worst relative error < 4e-15 for bothmainandfactoryexports (local check; the packagedtaperunner was unavailable in this environment).gcc -fsyntax-onlypasses onsrc/main.c.AI assistance disclosure: this change was prepared with AI assistance under the direction of the account owner (wanjinhao1), who reviewed and verified the results.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was implemented with AI assistance under the direction of the account owner (wanjinhao1), who reviewed the diff and verified the numerical results against the issue's reference values and the package fixtures.