Repository navigation
Conversation
…eibull/pdf` and `logpdf` For shape `k < 1` the Weibull density grows without bound as `x -> 0+`, but the JavaScript `pdf` returned `0` and `logpdf` returned `-Infinity` at `x = 0`. The C implementation of `pdf` already returned `+Infinity`, so the JavaScript and native results disagreed.
5 of 7 tasks
Contributor
Coverage Report
The above coverage report was generated for the changes in 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/weibull/pdfandstats/base/dists/weibull/logpdfreturning0and-Infinityatx = 0when the shapek < 1. The density(k/lambda) (x/lambda)^(k-1) exp(-(x/lambda)^k)grows without bound asx -> 0+in that case.The C implementation of
pdfhas no special case forx = 0and evaluates the formula, wherepow( 0.0, k-1.0 )is+Infinity. The JavaScript implementation special-casesx = 0ask === 1 ? k/lambda : 0, which is only right fork >= 1. So the two backends currently disagree. R (dweibull( 0, 0.5, 2 )), SciPy (weibull_min.pdf( 0, 0.5, scale=2 )) and Julia (pdf( Weibull( 0.5, 2 ), 0 )) all returnInf. Within stdlib,gamma,beta,chisquareandfalready return+Infinityfor the same boundary case.Changes:
pdf/lib/main.js,pdf/lib/factory.js: returnPINFatx = 0fork < 1.logpdf/lib/main.js,logpdf/lib/factory.js,logpdf/src/main.c: returnPINFatx = 0fork < 1, where it used to beNINF. The Clogpdfhad the same special case as the JavaScript.knot equal to one returns0" cases (which usek = 2) are renamed to "greater than one", and there is a newk < 1case in each of the six test files.The
k = 1(1/lambda) andk > 1(0) results are unchanged.Related Issues
This pull request has the following related issues:
ln(sqrt(2/pi))instead ofNaNforx = 0andk = 1instats/base/dists/chi/logpdf#15604 (the same class of boundary bug inchi/logpdf).Questions
No.
Other
Not changed here: in
pdf/src/main.c, thex == +/-Infinitybranch returns( k == 0.0 ) ? k/lambda : 0.0. Thek == 0.0arm can't be reached, sincek <= 0has already returnedNaN, so the branch always returns0, which is the correct result.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