Skip to content

Commit 13d0ed6

Browse files
authored
Merge pull request #3356 from domenzain/logcdf-gamma
Implement log CDF for Gamma distribution
2 parents cdb218e + 327045a commit 13d0ed6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pymc3/distributions/continuous.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,6 +2369,18 @@ def logp(self, value):
23692369
alpha > 0,
23702370
beta > 0)
23712371

2372+
def logcdf(self, value):
2373+
"""
2374+
Compute the log CDF for the Gamma distribution
2375+
"""
2376+
alpha = self.alpha
2377+
beta = self.beta
2378+
return bound(
2379+
tt.log(tt.gammainc(alpha, beta * value)),
2380+
value >= 0,
2381+
alpha > 0,
2382+
beta > 0)
2383+
23722384
def _repr_latex_(self, name=None, dist=None):
23732385
if dist is None:
23742386
dist = self

pymc3/tests/test_distributions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ def test_fun(value, mu, sigma):
692692
self.pymc3_matches_scipy(
693693
Gamma, Rplus, {'mu': Rplusbig, 'sigma': Rplusbig}, test_fun)
694694

695+
self.check_logcdf(
696+
Gamma, Rplus, {'alpha': Rplusbig, 'beta': Rplusbig},
697+
lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0/beta))
698+
695699
def test_inverse_gamma(self):
696700
self.pymc3_matches_scipy(
697701
InverseGamma, Rplus, {'alpha': Rplus, 'beta': Rplus},

0 commit comments

Comments
 (0)