Conversation
…y/median` `1 - 2^(-1/b)` cancels for large `b`: at `b = 1e15` the median was 4% off. Use `-expm1( -ln(2)/b )`. The fixtures are now generated from the textbook formula in extended precision.
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/kumaraswamy/medianaspow( -expm1( -ln(2)/b ), 1/a )instead ofpow( 1 - pow( 2, -1/b ), 1/a )(JS and C).2^(-1/b)is close to1for largeb, so1 - 2^(-1/b)cancels:Fixtures and tests:
runner.jlnow evaluates the textbook formula(1 - 2^(-1/b))^(1/a)in 2048-bitBigFloatinstead ofDistributions.median, which uses the same double-precision expression.Distributionsis dropped fromREQUIRE, anddata.jsonis regenerated with the same input ranges.New
large_b.json:blog-spaced over[1, 1e15], withain[0.5, 5.5].Max error in JS and native:
developdatalarge_bThe tolerances are set to those values; the old one was 9 ULP against Distributions' double-precision values. What's left on
datacomes fromaas small as~1e-3. Rounding1/a(about 1000) is then multiplied by|ln(1 - 2^(-1/b))|. That's conditioning, anddevelopis worse there too. Ondevelop, 838 of the 2,017 assertions intest.jsfail. With this change they all pass.Related Issues
None. Companion to #15769 (
kumaraswamy/quantile).Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was written primarily by Claude Code. I found the bug by scanning
stats/base/distsfor1 - pow(...).@stdlib-js/reviewers