Skip to content

fix: resolve quantile accuracy for small p in stats/base/dists/pareto-type1/quantile - #17019

Open
wanjinhao1 wants to merge 3 commits into
stdlib-js:developfrom
wanjinhao1:agent/fix-17008-pareto-quantile-log1p
Open

wanjinhao1 wants to merge 3 commits into
stdlib-js:developfrom
wanjinhao1:agent/fix-17008-pareto-quantile-log1p

Conversation

@wanjinhao1

Copy link
Copy Markdown
Contributor

Resolves #17008.

Description

What is the purpose of this pull request?

This pull request:

  • Fixes a floating-point cancellation bug in stats/base/dists/pareto-type1/quantile for small p: evaluating 1.0 - p rounds to 1.0 when p < 2^-53 (and loses relative accuracy for small p in general), so the quantile function returned beta instead of the true quantile. When p < 1e-4, the quantile is now evaluated in log-space as beta * exp( -log1p( -p ) / alpha ), matching the issue's suggested fix; the existing beta / pow( 1.0 - p, 1.0/alpha ) path is kept otherwise, leaving all currently accurate results (including the Julia fixtures) unchanged. The same change is applied to lib/main.js, lib/factory.js, and src/main.c, and regression tests using the issue's mpmath reference values are added for both the main and factory implementations.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Reference Packages

Did the content of this pull request follow one or more existing packages? Answering is optional.

This pull request followed these packages:

  • stats/base/dists/pareto-type1/quantile (existing package)

What carried over from the reference(s)?

What differed, or what did you have to work out yourself?

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Verification: node test/test.js, node test/test.quantile.js, node test/test.factory.js (3027+ tests) pass. The C implementation was syntax-checked with gcc -fsyntax-only (native build/test left to CI). The five reproduction cases from #17008 now match the mpmath reference values to within 2e-16 relative error, and p === 1 still returns +Infinity.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this pull request, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. How did you use AI assistance?


@stdlib-js/reviewers

…eto-type1/quantile`

Evaluates `beta / pow(1.0 - p, 1.0/alpha)` in log-space via `log1p` when `p < 1e-4`, avoiding floating-point cancellation in `1.0 - p` that rounds to `1.0` when `p < 2^-53` and returns `beta` instead of the true quantile.

Resolves stdlib-js#17008.
@wanjinhao1
wanjinhao1 requested a review from a team November 30, 2026 20:14
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Nov 30, 2026
Signed-off-by: wanjinhao1 <394959433@qq.com>
@stdlib-bot

stdlib-bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/pareto-type1/quantile $\\color{green}331/331$
$\\color{green}+0.00\\%$
$\\color{green}29/29$
$\\color{green}+0.00\\%$
$\\color{green}4/4$
$\\color{green}+0.00\\%$
$\\color{green}331/331$
$\\color{green}+0.00\\%$

The above coverage report was generated for the changes in this PR.

@stdlib-bot stdlib-bot added the Potential Duplicate There might be another pull request resolving the same issue. label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Potential Duplicate There might be another pull request resolving the same issue. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: stats/base/dists/pareto-type1/quantile loses accuracy for small p

2 participants