Skip to content

fix: improve accuracy of stats/base/dists/pareto-type1/quantile for small p - #17009

Open
ItsAbir005 wants to merge 2 commits into
stdlib-js:developfrom
ItsAbir005:fix/pareto-type1-quantile-accuracy
Open

ItsAbir005 wants to merge 2 commits into
stdlib-js:developfrom
ItsAbir005:fix/pareto-type1-quantile-accuracy

Conversation

@ItsAbir005

Copy link
Copy Markdown
Contributor

Resolves #17008.

Description

What is the purpose of this pull request?

This pull request:

  • Replaces beta / pow( 1.0 - p, 1.0 / alpha ) with beta * exp( -log1p( -p ) / alpha ) in lib/main.js and src/main.c (and beta * exp( -log1p( -p ) * alphaInv ) in lib/factory.js) to prevent catastrophic cancellation in 1.0 - p for small p.
  • Explicitly returns +Infinity (PINF / STDLIB_CONSTANT_FLOAT64_PINF) when p === 1.0.
  • Updates manifest.json dependencies across build, benchmark, and examples tasks (@stdlib/math/base/special/exp, @stdlib/math/base/special/log1p, @stdlib/constants/float64/pinf).
  • Adds 100-digit mpmath-generated small-p fixtures (test/fixtures/python/runner.py and test/fixtures/python/small_p.json) and unit tests for p = 0.0, p = 1.0, and small p in test/test.quantile.js, test/test.factory.js, and test/test.native.js, while updating existing Julia fixture ULP tolerances (4 ULPs for bothLarge/largeAlpha and 20 ULPs for largeBeta).

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/rayleigh/quantile
  • stats/base/dists/pareto-type1/mean
  • stats/base/dists/planck/quantile

What carried over from the reference(s)?

  • Using log1p( -p ) to avoid cancellation for small probabilities, STDLIB_CONSTANT_FLOAT64_PINF and manifest.json dependency conventions, and the Python fixture script layout (test/fixtures/python/runner.py).

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

  • Rewriting the Pareto (Type I) quantile formula via beta * exp( -log1p( -p ) / alpha ) (and -log1p( -p ) * alphaInv in factory.js), and adjusting ULP tolerances on the existing Julia-generated fixtures to account for up to 2–17 ULP differences from Julia's pow( 1 - p, ... ) evaluation.

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.

No.

Checklist

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

AI Assistance

When authoring the changes proposed in this PR, 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. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

AI assistance (Gemini) was used to scan for numerical cancellation bugs, implement the exp/log1p fix across JS and C, generate the mpmath small-p test fixtures, and update the test suites. All changes and tests were reviewed and verified in Codespaces.


@stdlib-js/reviewers

@ItsAbir005
ItsAbir005 requested a review from a team November 30, 2026 17:09
@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
@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}329/329$
$\\color{green}+100.00\\%$
$\\color{green}29/29$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}329/329$
$\\color{green}+100.00\\%$

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

@ItsAbir005

Copy link
Copy Markdown
Contributor Author

@kgryte @batpigandme pls review this when get time

@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