Repository navigation
Preserve small shape precision in gamma tail recovery - #182
Merged
Merged
Conversation
When x/scale is subnormal, the gamma CDF and CCDF recover the lower probability in logarithmic form. Forming 1 + shape for logGamma loses small shape bits even if logGamma itself is accurate. At shape 1e-8 and the smallest positive double argument, this rounding alone causes about 4.7e-12 relative error in the complementary probability. Extend the existing small-shape approximation to include the quadratic term when shape squared is at most the type's epsilon. The omitted cubic term is negligible relative to shape * log(x/scale) in this region. Keep the change within the subnormal-ratio recovery path. Add independent high-precision CDF and CCDF references for the affected case. AI-Assisted-By: Codex (GPT-6 Astra Medium)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Improve gamma CDF/CCDF accuracy when x/scale is subnormal and the shape is small. The existing logarithmic recovery forms
1 + shapebefore callinglogGamma, losing shape bits even iflogGammaitself is accurate. At shape1e-8and the smallest positive double argument, this addition alone causes approximately4.7e-12relative error in the complementary probability.Extend the existing small-shape approximation with the quadratic term of
logGamma(1 + shape)whenshape² <= epsilon. The omitted cubic term is negligible relative toshape * log(x/scale)in this region. The change stays within the existing subnormal-ratio recovery path; ordinary CDF/CCDF evaluation is unchanged.Add independent high-precision CDF and CCDF regression references. This addresses argument rounding in mir-stat separately from the Phobos
logGammaevaluation issue reported in dlang/phobos#11128.Validation:
AI-Assisted-By: Codex (GPT-6 Astra Medium)