Repository navigation
Conversation
…f/cdf` Both branches handed `betainc` the argument close to one, so it was rounded before the incomplete beta saw it. For small `x`, `d2/(d2+d1*x)` rounds to `1` and the upper tail returns `0`, and cdf values below about `1e-8` lost most of their digits. Swap the branches so each uses the argument below one half, as Boost does, and add a fixture for `x` down to `1e-20`.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
This branch has not been deployed
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.
Description
This pull request:
stats/base/dists/f/cdflosing precision, down to returning0, for smallx.The two branches hand
betaincthe argument that is close to one:For small
x,d2/(d2+d1*x)is1 - d1*x/d2rounded, so every digit ofd1*x/d2below machine epsilon is lost beforebetaincruns, and the upper tail comes back as0. This PR swaps the branches so each passes the argument below one half, which is exact to rounding. That is the same split as Boost'scdf( fisher_f_distribution ):ibetac( df2/2, df1/2, df2/(df2+v1x) )whenv1x > df2, andibeta( df1/2, df2/2, v1x/(df2+v1x) )otherwise. The change is tolib/main.jsandlib/factory.js.Checked against mpmath's regularized incomplete beta (40 digits) on 3,000 random
(x, d1, d2)withxin[1e-17, 1e9]andd1,d2in[0.1, 800], excluding results below1e-290:developRelated Issues
This pull request has the following related issues:
stats/base/dists/f/cdf#14692 (the open C implementation ports the current branches, so it would carry the same issue).Questions
No.
Other
small_x.json(Julia,x = 10^U(-20, 0),d1,d2in[0.5, 20.5]), added torunner.jl. The other fixture files are unchanged. Ondevelop, 942 assertions intest.cdf.jsfail, 200 of them becausedevelopreturns exactly0.runner.jlassignsd2twice in theboth_largeblock and never setsd1, soboth_large.jsonreusesd1from the previous block.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. The bug was found by comparing every
stats/base/distsfunction against SciPy on random parameters.@stdlib-js/reviewers