Skip to content

Conversation

@spinkney
Copy link
Collaborator

Summary

This pr closes #3257. The gamma_lccdf experiences numerical instability for alpha approximately greater than 30. It’s due to gamma_q or grad_reg_inc_gamma. This pr rewrites the code to use gamma_p and grad_reg_lower_inc_gamma, which avoids potential instability in a tgamma(alpha) and digamma(alpha) call. It seems to sample a bit faster than just wrapping gamma_lcdf with log1m_exp.

This supercedes and improves upon pr #3264.

Tests

I've implemented new tests in the problematic regime.

Release notes

The gamma_lccdf is made more robust for alpha values. The issue was overflow in the derivatives when alpha was greater than 30.

Checklist

  • Copyright holder: Publicis Groupe
    The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
    - Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
    - Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

  • the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

Base automatically changed from fix-grad_reg_lower_inc_gamma to develop December 23, 2025 19:43
Copy link
Member

@syclik syclik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things to change. I'll try to update the branch accordingly; it's nothing about the math itself.

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.

5 participants