Skip to content

Commit 09215c2

Browse files
committed
Add ICDF function to laplace distribution
Adds ICDF (quantile) function for the laplace distribution. Source https://en.wikipedia.org/wiki/Laplace_distribution Issue #6612
1 parent 371472d commit 09215c2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,19 @@ def logcdf(value, mu, b):
14801480
msg="b > 0",
14811481
)
14821482

1483+
def icdf(value, mu, b):
1484+
res = pt.switch(
1485+
pt.le(value, 0.5),
1486+
mu + b * np.log(2 * value),
1487+
mu - b * np.log(2 - 2 * value)
1488+
)
1489+
res = check_icdf_value(res, value)
1490+
return check_icdf_parameters(
1491+
res,
1492+
b > 0,
1493+
msg="b > 0"
1494+
)
1495+
14831496

14841497
class AsymmetricLaplaceRV(RandomVariable):
14851498
name = "asymmetriclaplace"

tests/distributions/test_continuous.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ def test_laplace(self):
457457
{"mu": R, "b": Rplus},
458458
lambda value, mu, b: st.laplace.logcdf(value, mu, b),
459459
)
460+
check_icdf(
461+
pm.Laplace,
462+
{"mu": R, "b": Rplus},
463+
lambda q, mu, b: st.laplace.ppf(q, mu, b)
464+
)
460465

461466
def test_laplace_asymmetric(self):
462467
check_logp(

0 commit comments

Comments
 (0)