Stabilize Negative Binomial with large mu/alpha - #8394
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8394 +/- ##
==========================================
+ Coverage 91.83% 91.85% +0.01%
==========================================
Files 128 128
Lines 21259 21259
==========================================
+ Hits 19523 19527 +4
+ Misses 1736 1732 -4
🚀 New features to boost your workflow:
|
ricardoV94
force-pushed
the
stable_negative_binom
branch
from
August 9, 2026 08:26
78dcb24 to
2243896
Compare
ricardoV94
force-pushed
the
stable_negative_binom
branch
from
August 9, 2026 16:15
2243896 to
b916ff0
Compare
ricardoV94
commented
Aug 9, 2026
| # (1 - p) / p in log space: a p = sigmoid(w) that saturates at 1.0 carries no | ||
| # information, while the rewritten log terms still see w. Spelled log(1 - p) | ||
| # because the sigmoid stabilization rewrites do not recognize log1p(-p) | ||
| mu = n * pt.exp(pt.log(1 - p) - pt.log(p)) |
|
|
||
| @classmethod | ||
| def get_n_p(cls, mu=None, alpha=None, p=None, n=None): | ||
| def get_n_p(cls, mu=None, alpha=None, p=None, n=None, math=pt): |
Member
There was a problem hiding this comment.
what's the story with the math argument?
Member
Author
There was a problem hiding this comment.
tensor and xtensor are using the helper
| def test_zeroinflatednegativebinomial_logp(self): | ||
| def logp_fn(value, psi, mu, alpha): | ||
| n, p = NegativeBinomial.get_n_p(mu=mu, alpha=alpha) | ||
| n, p = alpha, alpha / (mu + alpha) |
Member
There was a problem hiding this comment.
Why don't we want to use the helper anymore?
Member
Author
There was a problem hiding this comment.
It was just convenience for the test, there's no numpy.sigmoid so can't be used anymore for bon symbolic inputs
jessegrabowski
approved these changes
Aug 10, 2026
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.
Related to #8389