Skip to content

Adding logcdf method to inverse gamma distribution #3873

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

Closed
wants to merge 2 commits into from
Closed
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
23 changes: 23 additions & 0 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,29 @@ def logp(self, value):
+ logpow(value, -alpha - 1),
value > 0, alpha > 0, beta > 0)

def logcdf(self, value):
"""
Compute the log of the cumulative distribution function for Inverse Gamma distribution
at the specified value.

Parameters
----------
value: numeric
Value(s) for which log CDF is calculated. If the log CDF for multiple
values are desired the values must be provided in a numpy array or theano tensor.

Returns
-------
TensorVariable
"""
alpha = self.alpha
beta = self.beta
return bound(
tt.log(tt.gammaincc(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 @@ -689,6 +689,10 @@ def test_inverse_gamma(self):
InverseGamma, Rplus, {'alpha': Rplus, 'beta': Rplus},
lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta))

self.check_logcdf(
InverseGamma, Rplus, {'alpha': Rplusbig, 'beta': Rplusbig},
lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta))

@pytest.mark.xfail(condition=(theano.config.floatX == "float32"),
reason="Fails on float32 due to scaling issues")
def test_inverse_gamma_alt_params(self):
Expand Down