Skip to content

Commit 662edf0

Browse files
committed
Added ICDF for the continuous exponential distribution.
1 parent 8d5b236 commit 662edf0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,15 @@ def logcdf(value, mu):
13631363
msg="lam >= 0",
13641364
)
13651365

1366+
def icdf(value, mu):
1367+
res = -mu * pt.log(1 - value)
1368+
res = check_icdf_value(res, value)
1369+
return check_icdf_parameters(
1370+
res,
1371+
mu >= 0,
1372+
msg="mu >= 0",
1373+
)
1374+
13661375

13671376
class Laplace(Continuous):
13681377
r"""

tests/distributions/test_continuous.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,20 @@ def test_exponential(self):
438438
{"lam": Rplus},
439439
lambda value, lam: st.expon.logcdf(value, 0, 1 / lam),
440440
)
441+
check_icdf(
442+
pm.Exponential,
443+
{"lam": Rplus},
444+
lambda q, lam: st.expon.ppf(q, loc=0, scale=1 / lam),
445+
)
446+
# Custom logp / logcdf / icdf check for invalid parameters
447+
invalid_dist = pm.Exponential.dist(lam=-1)
448+
with pytensor.config.change_flags(mode=Mode("py")):
449+
with pytest.raises(ParameterValueError):
450+
logp(invalid_dist, np.array(0.5)).eval()
451+
with pytest.raises(ParameterValueError):
452+
logcdf(invalid_dist, np.array(0.5)).eval()
453+
with pytest.raises(ParameterValueError):
454+
icdf(invalid_dist, np.array(0.5)).eval()
441455

442456
def test_laplace(self):
443457
check_logp(

0 commit comments

Comments
 (0)