Skip to content

Conversation

@maresb
Copy link
Owner

@maresb maresb commented Dec 16, 2025

Extend _logccdf usage to Truncated and transformed discrete distributions, improve stability

Description

This PR extends the _logccdf dispatcher 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:

  • Truncated distributions: Updated TruncatedRV to use the stable _logccdf for its lower bound calculation, as suggested by @ricardoV94.
  • Transformed discrete distributions: The measurable_transform_logcdf in pymc/logprob/transforms.py now correctly uses _logccdf_helper for discrete variables, replacing a numerically unstable pt.log1mexp(_logcdf_helper(...)) call.
  • General stability in transforms: Replaced a pt.log(pt.exp(a) - pt.exp(b)) pattern with logdiffexp(a, b) in measurable_transform_logcdf to prevent nan results 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

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

Open in Cursor Open in Web


📚 Documentation preview 📚: https://pymc--2.org.readthedocs.build/en/2/

@cursor
Copy link

cursor bot commented Dec 16, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants