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

Abierto
#16,564 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@ItsAbir005 ya está trabajando en esto.

Desde el 10/11/2026.

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

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
backend, testing

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
JavaScript
Estrellas
6k
Forks
1.3k
Merge medio
1 d 21 h
PR fusionados (30 d)
224

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stdlib-js/stdlib

Todos los issues de stdlib-js/stdlib

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.