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.
Extend
_logccdfusage to Truncated and transformed discrete distributions, improve stabilityDescription
This PR extends the
_logccdfdispatcher implementation to further improve numerical stability for log survival function computations.Following a thorough audit of the codebase for
log(1 - CDF)patterns, the following additional improvements have been made:Truncateddistributions: UpdatedTruncatedRVto use the stable_logccdffor its lower bound calculation, as suggested by @ricardoV94.measurable_transform_logcdfinpymc/logprob/transforms.pynow correctly uses_logccdf_helperfor discrete variables, replacing a numerically unstablept.log1mexp(_logcdf_helper(...))call.pt.log(pt.exp(a) - pt.exp(b))pattern withlogdiffexp(a, b)inmeasurable_transform_logcdfto preventnanresults at support boundaries (e.g.,logdiffexp(-inf, -inf)now correctly returns-inf).These changes ensure more robust log-probability calculations across a wider range of distributions and transformations, particularly at extreme tail values.
Related Issue
_logccdfdispatcher for numerically stable log survival function in censored distributions pymc-devs/pymc#7996 (This PR is an update to Add_logccdfdispatcher for numerically stable log survival function in censored distributions pymc-devs/pymc#7996)Checklist
test_transforms.pytests pass)Type of change
📚 Documentation preview 📚: https://pymc--2.org.readthedocs.build/en/2/