Repository navigation
fix: return the smallest value with cdf( x ) >= p in stats/base/dists/discrete-uniform/quantile - #16994
Open
anshurajbisoyi98-ctrl wants to merge 1 commit into
Conversation
…sts/discrete-uniform/quantile` Signed-off-by: anshurajbisoyi98-ctrl <anshurajbisoyi98@gmail.com>
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/discrete-uniform/quantileso that it returns the smallestxwithcdf( x ) >= p.The current formula
a + floor( p*n )returns one past the right value wheneverp*nis an integer, which includes every step of the CDF andp = 1(where it returnsb+1, outside the support). I switched it toa - 1 + ceil( p*n ), withp = 0returninga, which is what Julia'sDistributions.jl(used for the test fixtures) does. SciPy'srandint.ppfagrees except atp = 0. The same change is inmain.js,factory.jsandsrc/main.c, andmanifest.jsonswapsfloorforceil.The fixtures use random
pand don't hit these cases, so I added tests totest.quantile.js,test.factory.jsandtest.native.js. Thefactory( 0, 4 )( 0.8 )example in the README and docs said4, butcdf( 3, 0, 4 )is already0.8, so I changed it to3.Related Issues
No.
Questions
No.
Other
No.
Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
I used Claude Code to run consistency checks across the discrete distributions in
stats/base/dists(comparingquantileagainstcdf), which turned this up, and to make the change and tests. I checked the formula against Julia and SciPy, built the add-on locally, and ran the JS and native tests.@stdlib-js/reviewers