Skip to content

Commit 7149781

Browse files
committed
Remove gammainc(c) safeguards in logcdf methods of Gamma and InverseGamma
Closes pymc-devs#4467
1 parent 86fd042 commit 7149781

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

pymc3/distributions/continuous.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,13 +2392,8 @@ def logcdf(value, alpha, inv_beta):
23922392
"""
23932393
beta = at.inv(inv_beta)
23942394

2395-
# Avoid C-assertion when the gammainc function is called with invalid values (#4340)
2396-
safe_alpha = at.switch(at.lt(alpha, 0), 0, alpha)
2397-
safe_beta = at.switch(at.lt(beta, 0), 0, beta)
2398-
safe_value = at.switch(at.lt(value, 0), 0, value)
2399-
24002395
return bound(
2401-
at.log(at.gammainc(safe_alpha, safe_beta * safe_value)),
2396+
at.log(at.gammainc(alpha, beta * value)),
24022397
0 <= value,
24032398
0 < alpha,
24042399
0 < beta,
@@ -2540,13 +2535,9 @@ def logcdf(value, alpha, beta):
25402535
-------
25412536
TensorVariable
25422537
"""
2543-
# Avoid C-assertion when the gammaincc function is called with invalid values (#4340)
2544-
safe_alpha = at.switch(at.lt(alpha, 0), 0, alpha)
2545-
safe_beta = at.switch(at.lt(beta, 0), 0, beta)
2546-
safe_value = at.switch(at.lt(value, 0), 0, value)
25472538

25482539
return bound(
2549-
at.log(at.gammaincc(safe_alpha, safe_beta / safe_value)),
2540+
at.log(at.gammaincc(alpha, beta / value)),
25502541
0 <= value,
25512542
0 < alpha,
25522543
0 < beta,

pymc3/tests/test_distributions.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,15 +1437,11 @@ def test_fun(value, mu, sigma):
14371437
reason="Fails on float32 due to numerical issues",
14381438
)
14391439
def test_gamma_logcdf(self):
1440-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1441-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
1442-
# in gamma.c file. Can be set back to False (default) once that issue is solved
14431440
self.check_logcdf(
14441441
Gamma,
14451442
Rplus,
14461443
{"alpha": Rplusbig, "beta": Rplusbig},
14471444
lambda value, alpha, beta: sp.gamma.logcdf(value, alpha, scale=1.0 / beta),
1448-
skip_paramdomain_outside_edge_test=True,
14491445
)
14501446

14511447
def test_inverse_gamma_logp(self):
@@ -1455,23 +1451,17 @@ def test_inverse_gamma_logp(self):
14551451
{"alpha": Rplus, "beta": Rplus},
14561452
lambda value, alpha, beta: sp.invgamma.logpdf(value, alpha, scale=beta),
14571453
)
1458-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1459-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
14601454

14611455
@pytest.mark.xfail(
14621456
condition=(aesara.config.floatX == "float32"),
14631457
reason="Fails on float32 due to numerical issues",
14641458
)
14651459
def test_inverse_gamma_logcdf(self):
1466-
# pymc-devs/aesara#224: skip_paramdomain_outside_edge_test has to be set
1467-
# True to avoid triggering a C-level assertion in the Aesara GammaQ function
1468-
# in gamma.c file. Can be set back to False (default) once that issue is solved
14691460
self.check_logcdf(
14701461
InverseGamma,
14711462
Rplus,
14721463
{"alpha": Rplus, "beta": Rplus},
14731464
lambda value, alpha, beta: sp.invgamma.logcdf(value, alpha, scale=beta),
1474-
skip_paramdomain_outside_edge_test=True,
14751465
)
14761466

14771467
@pytest.mark.xfail(

0 commit comments

Comments
 (0)