Skip to content

Commit 9abe6fb

Browse files
committed
Add ICDF function to pareto distribution
Adds ICDF (quantile) function for the Pareto distribution. Source https://en.wikipedia.org/wiki/Pareto_distribution Issue #6612
1 parent 09215c2 commit 9abe6fb

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

pymc/distributions/continuous.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1482,16 +1482,10 @@ def logcdf(value, mu, b):
14821482

14831483
def icdf(value, mu, b):
14841484
res = pt.switch(
1485-
pt.le(value, 0.5),
1486-
mu + b * np.log(2 * value),
1487-
mu - b * np.log(2 - 2 * value)
1485+
pt.le(value, 0.5), mu + b * np.log(2 * value), mu - b * np.log(2 - 2 * value)
14881486
)
14891487
res = check_icdf_value(res, value)
1490-
return check_icdf_parameters(
1491-
res,
1492-
b > 0,
1493-
msg="b > 0"
1494-
)
1488+
return check_icdf_parameters(res, b > 0, msg="b > 0")
14951489

14961490

14971491
class AsymmetricLaplaceRV(RandomVariable):
@@ -1943,6 +1937,16 @@ def logcdf(value, alpha, m):
19431937
msg="alpha > 0, m > 0",
19441938
)
19451939

1940+
def icdf(value, alpha, m):
1941+
res = m * pt.pow(1 - value, -1 / alpha)
1942+
res = check_icdf_value(res, value)
1943+
return check_icdf_parameters(
1944+
res,
1945+
alpha > 0,
1946+
m > 0,
1947+
msg="alpha > 0, m > 0",
1948+
)
1949+
19461950

19471951
@_default_transform.register(Pareto)
19481952
def pareto_default_transform(op, rv):

tests/distributions/test_continuous.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,7 @@ def test_laplace(self):
457457
{"mu": R, "b": Rplus},
458458
lambda value, mu, b: st.laplace.logcdf(value, mu, b),
459459
)
460-
check_icdf(
461-
pm.Laplace,
462-
{"mu": R, "b": Rplus},
463-
lambda q, mu, b: st.laplace.ppf(q, mu, b)
464-
)
460+
check_icdf(pm.Laplace, {"mu": R, "b": Rplus}, lambda q, mu, b: st.laplace.ppf(q, mu, b))
465461

466462
def test_laplace_asymmetric(self):
467463
check_logp(
@@ -638,6 +634,11 @@ def test_pareto(self):
638634
{"alpha": Rplusbig, "m": Rplusbig},
639635
lambda value, alpha, m: st.pareto.logcdf(value, alpha, scale=m),
640636
)
637+
check_icdf(
638+
pm.Pareto,
639+
{"alpha": Rplusbig, "m": Rplusbig},
640+
lambda q, alpha, m: st.pareto.ppf(q, alpha, scale=m),
641+
)
641642

642643
@pytest.mark.skipif(
643644
condition=(pytensor.config.floatX == "float32"),

0 commit comments

Comments
 (0)