diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index d597299997..e5efeb775a 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -1714,7 +1714,6 @@ def logcdf(value, mu, sigma): -np.inf, normal_lcdf(mu, sigma, pt.log(value)), ) - return check_parameters( res, sigma > 0, @@ -2039,6 +2038,15 @@ def logcdf(value, alpha, beta): msg="beta > 0", ) + def icdf(value, alpha, beta): + res = alpha + beta * pt.tan(np.pi * (value - 0.5)) + res = check_icdf_value(res, value) + return check_parameters( + res, + beta > 0, + msg="beta > 0", + ) + class HalfCauchy(PositiveContinuous): r""" @@ -3357,6 +3365,15 @@ def logcdf(value, mu, s): msg="s > 0", ) + def icdf(value, mu, s): + res = mu + s * pt.log(value / (1 - value)) + res = check_icdf_value(res, value) + return check_parameters( + res, + s > 0, + msg="s > 0", + ) + class LogitNormalRV(RandomVariable): name = "logit_normal" diff --git a/tests/distributions/test_continuous.py b/tests/distributions/test_continuous.py index b84a77e049..a4512b8a61 100644 --- a/tests/distributions/test_continuous.py +++ b/tests/distributions/test_continuous.py @@ -548,6 +548,11 @@ def test_cauchy(self): {"alpha": R, "beta": Rplusbig}, lambda value, alpha, beta: st.cauchy.logcdf(value, alpha, beta), ) + check_icdf( + pm.Cauchy, + {"alpha": R, "beta": Rplusbig}, + lambda q, alpha, beta: st.cauchy.ppf(q, alpha, beta), + ) def test_half_cauchy(self): check_logp( @@ -768,6 +773,12 @@ def test_logistic(self): lambda value, mu, s: st.logistic.logcdf(value, mu, s), decimal=select_by_precision(float64=6, float32=1), ) + check_icdf( + pm.Logistic, + {"mu": R, "s": Rplus}, + lambda q, mu, s: st.logistic.ppf(q, mu, s), + decimal=select_by_precision(float64=6, float32=1), + ) def test_logitnormal(self): check_logp(