diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index 91d2193504..a4371a940e 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -1480,6 +1480,13 @@ def logcdf(value, mu, b): msg="b > 0", ) + def icdf(value, mu, b): + res = pt.switch( + pt.le(value, 0.5), mu + b * np.log(2 * value), mu - b * np.log(2 - 2 * value) + ) + res = check_icdf_value(res, value) + return check_icdf_parameters(res, b > 0, msg="b > 0") + class AsymmetricLaplaceRV(RandomVariable): name = "asymmetriclaplace" @@ -1930,6 +1937,16 @@ def logcdf(value, alpha, m): msg="alpha > 0, m > 0", ) + def icdf(value, alpha, m): + res = m * pt.pow(1 - value, -1 / alpha) + res = check_icdf_value(res, value) + return check_icdf_parameters( + res, + alpha > 0, + m > 0, + msg="alpha > 0, m > 0", + ) + @_default_transform.register(Pareto) def pareto_default_transform(op, rv): diff --git a/tests/distributions/test_continuous.py b/tests/distributions/test_continuous.py index 1f673eb285..77ba827bfb 100644 --- a/tests/distributions/test_continuous.py +++ b/tests/distributions/test_continuous.py @@ -457,6 +457,7 @@ def test_laplace(self): {"mu": R, "b": Rplus}, lambda value, mu, b: st.laplace.logcdf(value, mu, b), ) + check_icdf(pm.Laplace, {"mu": R, "b": Rplus}, lambda q, mu, b: st.laplace.ppf(q, mu, b)) def test_laplace_asymmetric(self): check_logp( @@ -633,6 +634,11 @@ def test_pareto(self): {"alpha": Rplusbig, "m": Rplusbig}, lambda value, alpha, m: st.pareto.logcdf(value, alpha, scale=m), ) + check_icdf( + pm.Pareto, + {"alpha": Rplusbig, "m": Rplusbig}, + lambda q, alpha, m: st.pareto.ppf(q, alpha, scale=m), + ) @pytest.mark.skipif( condition=(pytensor.config.floatX == "float32"),