Repository navigation
fix: resolve log-density underflow in stats/base/dists/gamma/logpdf - #17022
Open
wanjinhao1 wants to merge 3 commits into
Open
wanjinhao1 wants to merge 3 commits into
wanjinhao1 wants to merge 3 commits into
Conversation
…nderflows Signed-off-by: wanjinhao1 <394959433@qq.com>
Contributor
|
Hello! Thank you for your contribution to stdlib. We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
This acknowledgment confirms that you've read the guidelines, which include:
We can't review or accept contributions without this acknowledgment. Thank you for your understanding and cooperation. We look forward to reviewing your contribution! |
stats/base/dists/gamma/logpdf
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
Signed-off-by: wanjinhao1 <394959433@qq.com>
Signed-off-by: wanjinhao1 <394959433@qq.com>
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.
Resolves #17004.
Description
This pull request:
stats/base/dists/gamma/logpdfreturning-Infinitywhen the PDF underflows to0(or loses digits when subnormal), by evaluating the log-density directly in log space whengamma_p_derivative( alpha, x*beta ) < FLOAT64_SMALLEST_NORMAL:(alpha-1)*ln(x*beta) - x*beta - gammaln(alpha) + ln(beta). All currently accurate results are unchanged (the fallback only triggers for subnormal densities).lib/main.js,lib/factory.js, and the nativesrc/main.c(with@stdlib/constants/float64/smallest-normaladded to the add-onmanifest.jsondependencies).erlang/logpdfandchisquare/logpdfcallgamma/logpdf, so they inherit the fix; a regression test is added forerlangas well.Related Issues
This pull request has the following related issues:
stats/base/dists/gamma/logpdfreturns-Infinitywhen the PDF underflows #17004Reference Packages
This pull request followed these packages:
math/base/special/cinv(for thesmallest-normalconstant include/manifest convention)manifest.jsondependency naming for@stdlib/constants/float64/smallest-normal.Validation
node test/test.js,node test/test.logpdf.js(3036 passed),node test/test.factory.js(3040 passed) ingamma/logpdf;test.native.jsskips locally (no built add-on) butgcc -fsyntax-onlyonsrc/main.cpasses and the C change mirrors the JS logic.erlang/logpdftests: 3021 passed;chisquare/logpdftests: 5115 passed.math.lgamma-based reference: e.g.logpdf( 1000, 10, 1 ) = -950.632…,logpdf( 755, 10, 1 ) = -708.161…(subnormal density case) — finite and accurate instead of-Infinity.AI Assistance
Portions of this pull request were authored with the assistance of an AI coding agent (GLM, trained by Z.ai); the approach follows the fix suggested in issue #17004, and all code and tests were reviewed and verified locally by the contributor.
[contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md