diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2dd70fbaf4..91227e409d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -46,6 +46,7 @@ This new version of `Theano-PyMC` comes with an experimental JAX backend which, - Test model logp before starting any MCMC chains (see [#4116](https://github.com/pymc-devs/pymc3/issues/4116)) - Fix bug in `model.check_test_point` that caused the `test_point` argument to be ignored. (see [PR #4211](https://github.com/pymc-devs/pymc3/pull/4211#issuecomment-727142721)) - Refactored MvNormal.random method with better handling of sample, batch and event shapes. [#4207](https://github.com/pymc-devs/pymc3/pull/4207) +- The `InverseGamma` distribution now implements a `logcdf`. [#3944](https://github.com/pymc-devs/pymc3/pull/3944) ### Documentation - Added a new notebook demonstrating how to incorporate sampling from a conjugate Dirichlet-multinomial posterior density in conjunction with other step methods (see [#4199](https://github.com/pymc-devs/pymc3/pull/4199)). diff --git a/pymc3/distributions/continuous.py b/pymc3/distributions/continuous.py index 234d5d7aed..533aeff5b4 100644 --- a/pymc3/distributions/continuous.py +++ b/pymc3/distributions/continuous.py @@ -2634,6 +2634,30 @@ def logp(self, value): def _distr_parameters_for_repr(self): return ["alpha", "beta"] + 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, + ) + class ChiSquared(Gamma): r""" diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index 6a2593ac97..04d9b0e3c0 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -913,6 +913,10 @@ def test_fun(value, mu, sigma): lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0 / beta), ) + @pytest.mark.xfail( + condition=(theano.config.floatX == "float32"), + reason="Fails on float32 due to numerical issues", + ) def test_inverse_gamma(self): self.pymc3_matches_scipy( InverseGamma, @@ -920,6 +924,12 @@ def test_inverse_gamma(self): {"alpha": Rplus, "beta": Rplus}, lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta), ) + self.check_logcdf( + InverseGamma, + Rplus, + {"alpha": Rplus, "beta": Rplus}, + lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta), + ) @pytest.mark.xfail( condition=(theano.config.floatX == "float32"),