Skip to content

Stabilize Negative Binomial with large mu/alpha - #8394

Merged
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
ricardoV94:stable_negative_binom
Aug 10, 2026
Merged

Stabilize Negative Binomial with large mu/alpha#8394
ricardoV94 merged 1 commit into
pymc-devs:mainfrom
ricardoV94:stable_negative_binom

Conversation

@ricardoV94

@ricardoV94 ricardoV94 commented Aug 9, 2026

Copy link
Copy Markdown
Member

Related to #8389

@read-the-docs-community

read-the-docs-community Bot commented Aug 9, 2026

Copy link
Copy Markdown

Documentation build overview

📚 pymc | 🛠️ Build #33981715 | 📁 Comparing b916ff0 against latest (a4827f0)

  🔍 Preview build  

3 files changed
± glossary.html
± _modules/pymc/distributions/discrete.html
± _modules/pymc/dims/distributions/scalar.html

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (a4827f0) to head (b916ff0).

Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
pymc/dims/distributions/scalar.py 96.75% <100.00%> (ø)
pymc/distributions/discrete.py 99.43% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ricardoV94
ricardoV94 force-pushed the stable_negative_binom branch from 78dcb24 to 2243896 Compare August 9, 2026 08:26
@ricardoV94 ricardoV94 changed the title Stability regression for Negative Binomial Stabilize Negative Binomial with large mu/alpha Aug 9, 2026
@ricardoV94
ricardoV94 force-pushed the stable_negative_binom branch from 2243896 to b916ff0 Compare August 9, 2026 16:15
# (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))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is addressed by pymc-devs/pytensor#2328


@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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what's the story with the math argument?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why don't we want to use the helper anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was just convenience for the test, there's no numpy.sigmoid so can't be used anymore for bon symbolic inputs

@ricardoV94
ricardoV94 merged commit 98be75a into pymc-devs:main Aug 10, 2026
42 checks passed
@ricardoV94
ricardoV94 deleted the stable_negative_binom branch August 10, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants