Skip to content

Commit 988ab9d

Browse files
dfmSpaak
andauthored
Adding logcdf method to inverse gamma distribution (#3944)
* adding logcdf method to inverse gamma distribution * formatting fixes * more formatting fixes * mark xfail for float32 * updating release notes to master * adding PR to release notes Co-authored-by: Eelke Spaak <[email protected]>
1 parent 7ff2f49 commit 988ab9d

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Diff for: RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ This new version of `Theano-PyMC` comes with an experimental JAX backend which,
4646
- Test model logp before starting any MCMC chains (see [#4116](https://github.com/pymc-devs/pymc3/issues/4116))
4747
- 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))
4848
- Refactored MvNormal.random method with better handling of sample, batch and event shapes. [#4207](https://github.com/pymc-devs/pymc3/pull/4207)
49+
- The `InverseGamma` distribution now implements a `logcdf`. [#3944](https://github.com/pymc-devs/pymc3/pull/3944)
4950

5051
### Documentation
5152
- 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 for: pymc3/distributions/continuous.py

+24
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,30 @@ def logp(self, value):
26342634
def _distr_parameters_for_repr(self):
26352635
return ["alpha", "beta"]
26362636

2637+
def logcdf(self, value):
2638+
"""
2639+
Compute the log of the cumulative distribution function for Inverse Gamma distribution
2640+
at the specified value.
2641+
2642+
Parameters
2643+
----------
2644+
value: numeric
2645+
Value(s) for which log CDF is calculated. If the log CDF for multiple
2646+
values are desired the values must be provided in a numpy array or theano tensor.
2647+
2648+
Returns
2649+
-------
2650+
TensorVariable
2651+
"""
2652+
alpha = self.alpha
2653+
beta = self.beta
2654+
return bound(
2655+
tt.log(tt.gammaincc(alpha, beta / value)),
2656+
value >= 0,
2657+
alpha > 0,
2658+
beta > 0,
2659+
)
2660+
26372661

26382662
class ChiSquared(Gamma):
26392663
r"""

Diff for: pymc3/tests/test_distributions.py

+10
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,23 @@ def test_fun(value, mu, sigma):
913913
lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0 / beta),
914914
)
915915

916+
@pytest.mark.xfail(
917+
condition=(theano.config.floatX == "float32"),
918+
reason="Fails on float32 due to numerical issues",
919+
)
916920
def test_inverse_gamma(self):
917921
self.pymc3_matches_scipy(
918922
InverseGamma,
919923
Rplus,
920924
{"alpha": Rplus, "beta": Rplus},
921925
lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta),
922926
)
927+
self.check_logcdf(
928+
InverseGamma,
929+
Rplus,
930+
{"alpha": Rplus, "beta": Rplus},
931+
lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta),
932+
)
923933

924934
@pytest.mark.xfail(
925935
condition=(theano.config.floatX == "float32"),

0 commit comments

Comments
 (0)