Repository navigation
Keep lgamma_p finite where P underflows, and add ulps plots to the Python layer - #1565
Merged
Merged
Conversation
…thon layer lgamma_p works in logs (a log-space Lanczos prefix) for large a and wherever P underflows; entropy for the arcsine and Bernoulli distributions; boost.math.ulps draws 1D and 2D ulps plots against mpmath. Closes #1564 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Hi Nick (@NAThompson) I don't usually flag too many warnings with Math, but I picked up some Could you eliminate the |
Collaborator
Author
|
@ckormanyos : Fixing in the entropy PR to preserve CI. |
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.
lgamma_p works in logs (a log-space Lanczos prefix) for large a and wherever P underflows; entropy for the arcsine and Bernoulli distributions; boost.math.ulps draws 1D and 2D ulps plots against mpmath.
Closes #1564
lgamma_p
lgamma_pused to takelog(gamma_p(a, x)). Once P underflowed, that gavelog(0) = -inf, which was reported as an overflow, and log P lost accuracy as P went subnormal. Now, for x < a, it uses method 2 in logs, log P = log(prefix) + log(series / a), in two cases:The log of the prefix x^a e^-x / Γ(a) is
a·log1pmx(d) + x(½ − g)/agh + ½·log(agh/e) − log(lanczos_sum_expG_scaled(a)), the logarithm ofregularised_gamma_prefix's large-a form. It has none of the cancellation ina·log(x) − x − lgamma(a), which had reached 540 eps at a = 10⁷. Elsewherelog(gamma_p)stays, since it is the more accurate of the two for smaller a.Double, 300 × 300 grid, against mpmath (x < a) and Arb (x ≥ a):
log1p(-gamma_q(a, x)). There Q's relative error reaches 10⁶ eps (e.g. a = 3.8·10⁶, x = 1.016a), which is agamma_qaccuracy issue unchanged from develop.Also
entropy(arcsine_distribution)= log(π(x_max − x_min)/4).entropy(bernoulli_distribution)= −p log p − (1 − p) log1p(−p).boost.math.ulps.plot/heatmap(nanobind layer) classify each point as ulps, spurious overflow (cyan), NaN or domain error (green), or out of range and handled (gray). The plots above were made with it.🤖 Generated with Claude Code