Skip to content

Implement log CDF for Gamma distribution #3356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down