Skip to content

Commit af93b5d

Browse files
committed
Implement icdf() method for Asymmetric Laplace distribution and provide corresponding tests, as requested in issue #6612.
1 parent 4ad7fa8 commit af93b5d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,15 @@ def logp(value, b, kappa, mu):
16401640
msg="b > 0, kappa > 0",
16411641
)
16421642

1643+
def icdf(value, b, kappa, mu):
1644+
res = pt.switch(
1645+
pt.le(value, kappa**2 / (1 + kappa**2)),
1646+
mu + (kappa / b) * pt.log(value * (1 + kappa**2) / kappa**2),
1647+
mu - (1 / (b * kappa)) * pt.log((1 - value) * (1 + kappa**2)),
1648+
)
1649+
res = check_icdf_value(res, value)
1650+
return check_icdf_parameters(res, b > 0, kappa > 0, msg="b > 0, kappa > 0")
1651+
16431652

16441653
class LogNormal(PositiveContinuous):
16451654
r"""

tests/distributions/test_continuous.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,12 @@ def test_laplace_asymmetric(self):
489489
laplace_asymmetric_logpdf,
490490
decimal=select_by_precision(float64=6, float32=2),
491491
)
492+
check_icdf(
493+
pm.AsymmetricLaplace,
494+
{"b": Rplus, "kappa": Rplus, "mu": R},
495+
# scipy uses an alternative scale parameterization, scale=1/b
496+
lambda q, b, kappa, mu: st.laplace_asymmetric.ppf(q, kappa, mu, 1 / b),
497+
)
492498

493499
def test_lognormal(self):
494500
check_logp(

0 commit comments

Comments
 (0)