Loss of accuracy for small p in stats/base/dists/weibull/quantile

Aberta
#16,564 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@ItsAbir005 já está trabalhando nisso.

Desde 10/11/2026.

  • #16565 de @ItsAbir005 — aberto
  • #16577 de @protestershankar — aberto

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
javascript
Domínio
backend, testing

Direção de pesquisa

The issue identifies lib/main.js, lib/factory.js, and src/main.c as affected, and proposes following the @stdlib/stats/base/dists/rayleigh/quantile approach. First inspect those implementations and the existing Weibull quantile tests, then check whether the linked pull request #16565 already covers the fix. Done means small lower-tail probabilities match the stated reference values and the relevant tests pass.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Description

@stdlib/stats/base/dists/weibull/quantile loses precision for small p (lower tail) because it evaluates -ln( 1.0 - p ), which suffers catastrophic floating-point cancellation when p is small. The relative error grows roughly like eps / p: about 1e-7 at p = 1e-10, 5.4% at p = 1e-16, and 50% or more once p <= 1e-17.

Reference values were computed with mpmath at 80 digits:

p k lambda stdlib (current) reference rel. error
1e-17 1000.0 10000.0 4743.421575702269 9616.122783836647 0.51
1e-16 1000.0 10000.0 9639.298077406433 9638.290236239705 1.05e-4
5e-16 2000.0 50000.0 49129.48305287857 49126.91460808886 5.23e-5
1e-16 2.0 10.0 1.0536712127723508e-7 1.0e-7 0.054
1e-10 1.0 1.0 1.000000082790371e-10 1.00000000005e-10 8.3e-8

Cause:
The implementation computes lambda * pow( -ln( 1.0 - p ), 1.0/k ) in lib/main.js, lib/factory.js, and src/main.c. For small p, 1.0 - p rounds away the lower-order bits of p.

Proposed fix:
Replace -ln( 1.0 - p ) with -log1p( -p ) using @stdlib/math/base/special/log1p (and stdlib_base_log1p in C), identical to the approach used in @stdlib/stats/base/dists/rayleigh/quantile. Evaluating -log1p( -p ) preserves full double-precision accuracy, dropping the relative error to ~1e-17 across all tested inputs.

I have a branch ready with the fix and unit tests for small p, and can open a PR if acceptable.

Related Issues

No related issues found.

Questions

No.

Demo

No response

Reproduction

Run the following script in Node.js:

var quantile = require( '@stdlib/stats/base/dists/weibull/quantile' );

console.log( 'p = 1e-16, k = 2.0, lambda = 10.0:' );
console.log( 'quantile:', quantile( 1.0e-16, 2.0, 10.0 ) );

console.log( '\np = 1e-17, k = 1000.0, lambda = 10000.0:' );
console.log( 'quantile:', quantile( 1.0e-17, 1000.0, 10000.0 ) );
Expected Results
p = 1e-16, k = 2.0, lambda = 10.0:
quantile: 1e-7

p = 1e-17, k = 1000.0, lambda = 10000.0:
quantile: 9616.122783836647
Actual Results
p = 1e-16, k = 2.0, lambda = 10.0:
quantile: 1.0536712127723508e-7

p = 1e-17, k = 1000.0, lambda = 10000.0:
quantile: 4743.421575702269
Version

develop (commit 2d5e843c6d840d5cb5ad0a5f27b9a9947d972371)

Environments

Node.js

Browser Version

No response

Node.js / npm Version

Node.js v24.19.0 / npm 11.17.0

Platform

Windows 11 (x64)

Checklist
  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
Linguagem predominante
JavaScript
Estrelas
6k
Forks
1.3k
Merge médio
1d 21h
PRs com merge (30d)
224

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de stdlib-js/stdlib

Todas as issues de stdlib-js/stdlib

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.