From af93b5dedb4da787bb9dbe692dbb53691ccb57a5 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 25 Nov 2025 11:01:53 -0700 Subject: [PATCH] Implement icdf() method for Asymmetric Laplace distribution and provide corresponding tests, as requested in issue #6612. --- pymc/distributions/continuous.py | 9 +++++++++ tests/distributions/test_continuous.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index 1d30227fed..f8f56e1400 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -1640,6 +1640,15 @@ def logp(value, b, kappa, mu): msg="b > 0, kappa > 0", ) + def icdf(value, b, kappa, mu): + res = pt.switch( + pt.le(value, kappa**2 / (1 + kappa**2)), + mu + (kappa / b) * pt.log(value * (1 + kappa**2) / kappa**2), + mu - (1 / (b * kappa)) * pt.log((1 - value) * (1 + kappa**2)), + ) + res = check_icdf_value(res, value) + return check_icdf_parameters(res, b > 0, kappa > 0, msg="b > 0, kappa > 0") + class LogNormal(PositiveContinuous): r""" diff --git a/tests/distributions/test_continuous.py b/tests/distributions/test_continuous.py index eb0c4cabe7..6f9bedb945 100644 --- a/tests/distributions/test_continuous.py +++ b/tests/distributions/test_continuous.py @@ -489,6 +489,12 @@ def test_laplace_asymmetric(self): laplace_asymmetric_logpdf, decimal=select_by_precision(float64=6, float32=2), ) + check_icdf( + pm.AsymmetricLaplace, + {"b": Rplus, "kappa": Rplus, "mu": R}, + # scipy uses an alternative scale parameterization, scale=1/b + lambda q, b, kappa, mu: st.laplace_asymmetric.ppf(q, kappa, mu, 1 / b), + ) def test_lognormal(self): check_logp(