Repository navigation
Conversation
…screte-uniform/quantile` `a + floor(p*n)` is one past the quantile whenever `p*n` is an integer, and returns `b+1`, outside the support, for `p = 1`. Use `a - 1 + ceil(p*n)` instead, with `Q(0) = a` and a correction for `p*n` rounding up past an integer.
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Member
|
@Planeshifter Mind taking a look at 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/quantile(JS,factory, and C) returning one past the quantile wheneverp*(b-a+1)is an integer. That includesp = 1, where it returnsb+1, outside the support.The quantile is the smallest
xwithF(x) >= p. WithF(x) = (x-a+1)/nandn = b-a+1, that isx = a - 1 + ceil(p*n), nota + floor(p*n). The two agree unlessp*nis an integer, which is why the Julia fixtures didn't catch it:p = rand()never lands onk/n. The Julia runner's ownquantile( DiscreteUniform( a, b ), p )givesa - 1 + ceil(p*n), and the new implementation matches all 3,000 existing fixture values.Two details:
Q(0) = a, sinceceil(0) = 0would otherwise givea-1.p*ncan round up past an integer, e.g.0.3*10 = 3.0000000000000004. The code stepskback when(k-1)/n >= p, which is the same comparisoncdfmakes, soF(Q(p)) >= p > F(Q(p)-1)holds exactly.The README formula is updated to match. I couldn't get
make markdown-svg-equations-filesto run locally (remark config error), sodocs/img/equation_discrete_uniform_quantile_function.svgstill shows the old formula and will need regenerating.Related Issues
No.
Questions
No.
Other
factory, native) checkp = 0andp = 1, and everyp = k/nfornin1..10andain{-3, 0, 3}. Ondevelop, 167 assertions fail intest.quantile.js(all 165p = k/ncases and bothp = 1checks), and the same 167 fail intest.factory.js. All of them pass with this change.quantile.factory( 0, 4 )( 0.8 )now returns3, sinceF(3) = 4/5 = 0.8. It is updated in the README,repl.txt,index.d.ts, and thelib/index.jsJSDoc.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