Skip to content

Commit 10eab32

Browse files
james-2001ricardoV94
authored andcommitted
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 c377bf6 commit 10eab32

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
@@ -1489,6 +1489,19 @@ def logcdf(value, mu, b):
14891489
msg="b > 0",
14901490
)
14911491

1492+
def icdf(value, mu, b):
1493+
res = pt.switch(
1494+
pt.le(value, 0.5),
1495+
mu + b * np.log(2 * value),
1496+
mu - b * np.log(2 - 2 * value)
1497+
)
1498+
res = check_icdf_value(res, value)
1499+
return check_icdf_parameters(
1500+
res,
1501+
b > 0,
1502+
msg="b > 0"
1503+
)
1504+
14921505

14931506
class AsymmetricLaplaceRV(RandomVariable):
14941507
name = "asymmetriclaplace"

tests/distributions/test_continuous.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ def test_laplace(self):
466466
{"mu": R, "b": Rplus},
467467
lambda value, mu, b: st.laplace.logcdf(value, mu, b),
468468
)
469+
check_icdf(
470+
pm.Laplace,
471+
{"mu": R, "b": Rplus},
472+
lambda q, mu, b: st.laplace.ppf(q, mu, b)
473+
)
469474

470475
def test_laplace_asymmetric(self):
471476
check_logp(

0 commit comments

Comments
 (0)