Repository navigation
Keep the geometric CDF and quantile precise for a rare success - #96
Merged
Merged
Conversation
GeometricDistributionProvider worked with 1 - p directly, which rounds to exactly one below p of about 1e-16: the CDF was zero everywhere and the quantile's correction loop walked to int.MaxValue, about 22 s per call. Store log1p(-p) and build the CDF, survival function, mass and quantile on it through the shared ExpM1/Log1P, and bound the quantile's correction walk to two steps either way before falling back to bisecting the support. Fixes #51 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
|
This was referenced Oct 7, 2026
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.



Fixes #51
What changed
GeometricDistributionProviderworked with1 − pdirectly. For p ≲ 1.1e-16 that rounds to exactly 1, soCdfwas 0 everywhere.Quantilethen walked its correction loop all the way toint.MaxValue, which took about 22 s per call and also stalledMedianandSample. For larger small p,Cdfstill carried a relative error of about ε/p.The provider now:
log1p(−p)throughSpecialFunctions.Log1P.Shared/SpecialFunctions.csis now linked into the Geometric project, and the line inCLAUDE.mdthat lists which providers link it is updated.Cdf = −expm1((k+1)·log1p(−p))andSurvivalFunction = exp((k+1)·log1p(−p)).Pmfis built on the same logarithm.Quantilefromlog1p(−q) / log1p(−p). The correction walks are bounded to two steps in each direction. If the result still isn't settled, it falls back to bisecting the support, which costs 31 CDF evaluations, so a bad estimate can no longer become a walk of about 2e9 steps.Tests
Geometric_Keeps_Its_Precision_For_A_Rare_Successchecks values computed to 60 digits:Geometric(1e-17).Cdf(1e8)Geometric(1e-17).Quantile(1e-9)int.MaxValue(~22 s)Geometric(1e-12).Cdf(1e9)Geometric(1e-300).Cdf(1000)Essentials.Testson net10.0: 949 passed, 0 failed. The Geometric project builds on every target framework.This branch is independent of #95 (Binomial survival function). Both start from
main.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
Generated by Claude Code