Skip to content

Commit 918f1af

Browse files
committed
adding logcdf method to inverse gamma distribution
1 parent 1d92c23 commit 918f1af

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pymc3/distributions/continuous.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,39 @@ 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+
def _repr_latex_(self, name=None, dist=None):
2661+
if dist is None:
2662+
dist = self
2663+
beta = dist.beta
2664+
alpha = dist.alpha
2665+
name = r'\text{%s}' % name
2666+
return r'${} \sim \text{{InverseGamma}}(\mathit{{alpha}}={},~\mathit{{beta}}={})$'.format(name,
2667+
get_variable_name(alpha),
2668+
get_variable_name(beta))
2669+
26372670

26382671
class ChiSquared(Gamma):
26392672
r"""

pymc3/tests/test_distributions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,12 @@ def test_inverse_gamma(self):
920920
{"alpha": Rplus, "beta": Rplus},
921921
lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta),
922922
)
923+
self.check_logcdf(
924+
InverseGamma,
925+
Rplus,
926+
{'alpha': Rplusbig, 'beta': Rplusbig},
927+
lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta),
928+
)
923929

924930
@pytest.mark.xfail(
925931
condition=(theano.config.floatX == "float32"),

0 commit comments

Comments
 (0)