Skip to content

Commit e54729f

Browse files
committed
Remove gammainc(c) safeguards in logcdf methods of Gamma and InverseGamma
Closes #4467
1 parent 1db0c19 commit e54729f

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

pymc3/distributions/continuous.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -2370,13 +2370,8 @@ def logcdf(value, alpha, inv_beta):
23702370
"""
23712371
beta = at.inv(inv_beta)
23722372

2373-
# Avoid C-assertion when the gammainc function is called with invalid values (#4340)
2374-
safe_alpha = at.switch(at.lt(alpha, 0), 0, alpha)
2375-
safe_beta = at.switch(at.lt(beta, 0), 0, beta)
2376-
safe_value = at.switch(at.lt(value, 0), 0, value)
2377-
23782373
return bound(
2379-
at.log(at.gammainc(safe_alpha, safe_beta * safe_value)),
2374+
at.log(at.gammainc(alpha, beta * value)),
23802375
0 <= value,
23812376
0 < alpha,
23822377
0 < beta,
@@ -2518,13 +2513,9 @@ def logcdf(value, alpha, beta):
25182513
-------
25192514
TensorVariable
25202515
"""
2521-
# Avoid C-assertion when the gammaincc function is called with invalid values (#4340)
2522-
safe_alpha = at.switch(at.lt(alpha, 0), 0, alpha)
2523-
safe_beta = at.switch(at.lt(beta, 0), 0, beta)
2524-
safe_value = at.switch(at.lt(value, 0), 0, value)
25252516

25262517
return bound(
2527-
at.log(at.gammaincc(safe_alpha, safe_beta / safe_value)),
2518+
at.log(at.gammaincc(alpha, beta / value)),
25282519
0 <= value,
25292520
0 < alpha,
25302521
0 < beta,

pymc3/tests/test_distributions.py

-10
Original file line numberDiff line numberDiff line change
@@ -1442,15 +1442,11 @@ def test_fun(value, mu, sigma):
14421442
reason="Fails on float32 due to numerical issues",
14431443
)
14441444
def test_gamma_logcdf(self):
1445-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1446-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
1447-
# in gamma.c file. Can be set back to False (default) once that issue is solved
14481445
self.check_logcdf(
14491446
Gamma,
14501447
Rplus,
14511448
{"alpha": Rplusbig, "beta": Rplusbig},
14521449
lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0 / beta),
1453-
skip_paramdomain_outside_edge_test=True,
14541450
)
14551451

14561452
def test_inverse_gamma_logp(self):
@@ -1460,23 +1456,17 @@ def test_inverse_gamma_logp(self):
14601456
{"alpha": Rplus, "beta": Rplus},
14611457
lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta),
14621458
)
1463-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1464-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
14651459

14661460
@pytest.mark.skipif(
14671461
condition=(aesara.config.floatX == "float32"),
14681462
reason="Fails on float32 due to numerical issues",
14691463
)
14701464
def test_inverse_gamma_logcdf(self):
1471-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1472-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
1473-
# in gamma.c file. Can be set back to False (default) once that issue is solved
14741465
self.check_logcdf(
14751466
InverseGamma,
14761467
Rplus,
14771468
{"alpha": Rplus, "beta": Rplus},
14781469
lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta),
1479-
skip_paramdomain_outside_edge_test=True,
14801470
)
14811471

14821472
@pytest.mark.skipif(

0 commit comments

Comments
 (0)