diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 12cb5f0ddd..de10c78d7b 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -2369,6 +2369,18 @@ def logp(self, value): alpha > 0, beta > 0) + def logcdf(self, value): + """ + Compute the log CDF for the Gamma distribution + """ + alpha = self.alpha + beta = self.beta + return bound( + tt.log(tt.gammainc(alpha, beta * value)), + value >= 0, + alpha > 0, + beta > 0) + def _repr_latex_(self, name=None, dist=None): if dist is None: dist = self diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index 2fef74d2d2..e10a34c6d5 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -692,6 +692,10 @@ def test_fun(value, mu, sigma): self.pymc3_matches_scipy( Gamma, Rplus, {'mu': Rplusbig, 'sigma': Rplusbig}, test_fun) + self.check_logcdf( + Gamma, Rplus, {'alpha': Rplusbig, 'beta': Rplusbig}, + lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0/beta)) + def test_inverse_gamma(self): self.pymc3_matches_scipy( InverseGamma, Rplus, {'alpha': Rplus, 'beta': Rplus},