Skip to content

Fix gamma lccdf v3#3274

Closed
syclik wants to merge 4 commits intodevelopfrom
fix-gamma-lccdf-v3
Closed

Fix gamma lccdf v3#3274
syclik wants to merge 4 commits intodevelopfrom
fix-gamma-lccdf-v3

Conversation

@syclik
Copy link
Member

@syclik syclik commented Feb 5, 2026

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 fixes the reverted PR: #3272.

cc: @spinkney

Tests

New probability 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, Daniel Lee
    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

@syclik syclik requested a review from spinkney February 5, 2026 15:22
@syclik syclik closed this Feb 5, 2026
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.

Fix gamma_lccdf actually

2 participants