Repository navigation
fix: handle negative t in stats/base/dists/weibull/mgf - #16212
Open
0PrashantYadav0 wants to merge 1 commit into
Open
0PrashantYadav0 wants to merge 1 commit into
0PrashantYadav0 wants to merge 1 commit into
Conversation
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown_pkg_readmes
status: passed
- task: lint_markdown_docs
status: na
- task: lint_markdown
status: na
- task: lint_package_json
status: na
- task: lint_repl_help
status: passed
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: na
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: missing_dependencies
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: passed
- task: lint_typescript_tests
status: passed
- task: lint_license_headers
status: passed
---
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/mgf(main.js,factory.js, andsrc/main.c). The loop ranwhile ( summand / sum > EPS ). Whent < 0, the terms alternate in sign, so the ratio is negative whenever a summand and the running sum have opposite signs, and the loop stopped after one or two terms. The criterion now usesabs( summand / sum ). Fort >= 0every term is positive, so results there do not change.mgf( -1.0, 4.0, 4.0 )example from~0.019to~0.045, and theweibull.mgf( -0.5 )example inweibull/ctorfrom~0.075to~0.109.ttotest.mgf.js,test.factory.js, andtest.native.js.Examples:
mgf( -0.5, 1.0, 1.0 )0.50.66666666666666661/(1-tλ) = 2/3(Weibull withk = 1is exponential)mgf( -0.3, 2.0, 4.0 )0.27370.39615540526349570.39615540526349546mgf( -1.0, 4.0, 4.0 )0.01890.044759611342952090.04475961134294959The reference values come from summing the same series in 1024-bit
BigFloatarithmetic in Julia, and they agree with numerical integration ofE[exp(tX)].Related Issues
No.
Questions
This fixes the stopping test, but the power series still has limits for
t < 0that this PR does not address:k < 1the series diverges for anyt != 0, so the function returns±Infinity, although the MGF is finite for everyt <= 0.k = 1,gamma( 1+n )overflows beforecunderflows once|tλ|approaches 1 (e.g.,mgf( -0.9, 1.0, 1.0 )), and attλ <= -1the series does not converge at all.|tλ|, the alternating terms cancel badly. The error is ~4 ULP at|tλ| = 1.2, ~7700 ULP at|tλ| = 5, and the result is meaningless atmgf( -20.0, 3.0, 1.0 ).For
t < 0, evaluating the integral∫₀^∞ exp( tλ u^(1/k) ) exp( -u ) dunumerically would avoid all three. stdlib has no quadrature routine inmath/base, so I kept this PR to the stopping test. Would you like a follow-up for this, or a note in the README in the meantime?Other
The new tests use
|tλ| <= 2, where the series agrees with the reference to within 4 ULP. They fail ondevelopand pass with this change, for both the JavaScript and native implementations.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
I found this bug manually while reviewing other PRs. The code changes were generated with Claude Code, and I reviewed them and verified the results.
@stdlib-js/reviewers