Repository navigation
fix: return MGF for the number of failures in stats/base/dists/geometric/mgf - #16424
Open
harsh-thakkar7 wants to merge 1 commit into
Open
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
harsh-thakkar7
force-pushed
the
fix/geometric-mgf-failures-convention
branch
2 times, most recently
from
November 1, 2026 05:45
2222797 to
fae8a48
Compare
harsh-thakkar7
force-pushed
the
fix/geometric-mgf-failures-convention
branch
from
November 1, 2026 05:52
fae8a48 to
9375595
Compare
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.
Resolves #15780.
Description
This pull request:
fixes
stats/base/dists/geometric/mgfto returnp / (1 - (1-p)e^t), the MGF for the number of failures before the first success, which is the parameterization used by the rest of thegeometricpackages (pmf,mean,variance, etc.);previously it returned
pe^t / (1 - (1-p)e^t), the MGF for the number of trials, so every value was off by a factor ofe^t;applies the same fix to the C implementation in
src/main.c, and updates the affected doctests inlib/index.js,lib/native.js,lib/factory.js, the README equation, and the README/C example values;regenerates the
expectedvalues intest/fixtures/julia/{small_p,large_p}.json, which had been computed with the old formula (thexandpinputs are unchanged);updates the
p = 1test expectation intest.mgf.js/test.native.js:Xis degenerate at0whenp = 1, so the MGF is1, note^t.Related Issues
This pull request has the following related issues:
stats/base/dists/geometric/mgfreturns the MGF for the number of trials instead of the number of failures #15780stats/base/dists/geometric/mgf#15781 (an earlier PR for this issue that has been inactive for about a month; happy to withdraw this one if that PR is being revived)Questions
No.
Other
Verification with
p = 0.3:mgf(0.1, 0.3)now returns1.3252033149682356, matching the numerically integratedsum_k e^{0.1k} pmf(k, 0.3)from the issue (1.3252);(mgf(1e-6, 0.3) - mgf(-1e-6, 0.3)) / 2e-6is2.3333, matchingmean(0.3)(2.3333); before the fix it was3.3333;mgf(0.5, 1.0)now returns1(X is always 0 when p = 1); before the fix it returned1.6487;mgf(0.8, 0.5)still returnsNaN).Checklist
AI Assistance
Yes
No
Code generation
Documentation (including examples)
Research and understanding
Disclosure
This PR was prepared with Qoder AI assistance under the contributor's direction. All changed code and examples were executed locally to verify the values above.
@stdlib-js/reviewers