Skip to content

Commit 9b72c2e

Browse files
james-2001ricardoV94
authored andcommitted
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 10eab32 commit 9b72c2e

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
@@ -1491,16 +1491,10 @@ def logcdf(value, mu, b):
14911491

14921492
def icdf(value, mu, b):
14931493
res = pt.switch(
1494-
pt.le(value, 0.5),
1495-
mu + b * np.log(2 * value),
1496-
mu - b * np.log(2 - 2 * value)
1494+
pt.le(value, 0.5), mu + b * np.log(2 * value), mu - b * np.log(2 - 2 * value)
14971495
)
14981496
res = check_icdf_value(res, value)
1499-
return check_icdf_parameters(
1500-
res,
1501-
b > 0,
1502-
msg="b > 0"
1503-
)
1497+
return check_icdf_parameters(res, b > 0, msg="b > 0")
15041498

15051499

15061500
class AsymmetricLaplaceRV(RandomVariable):
@@ -1952,6 +1946,16 @@ def logcdf(value, alpha, m):
19521946
msg="alpha > 0, m > 0",
19531947
)
19541948

1949+
def icdf(value, alpha, m):
1950+
res = m * pt.pow(1 - value, -1 / alpha)
1951+
res = check_icdf_value(res, value)
1952+
return check_icdf_parameters(
1953+
res,
1954+
alpha > 0,
1955+
m > 0,
1956+
msg="alpha > 0, m > 0",
1957+
)
1958+
19551959

19561960
@_default_transform.register(Pareto)
19571961
def pareto_default_transform(op, rv):

tests/distributions/test_continuous.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,7 @@ def test_laplace(self):
466466
{"mu": R, "b": Rplus},
467467
lambda value, mu, b: st.laplace.logcdf(value, mu, b),
468468
)
469-
check_icdf(
470-
pm.Laplace,
471-
{"mu": R, "b": Rplus},
472-
lambda q, mu, b: st.laplace.ppf(q, mu, b)
473-
)
469+
check_icdf(pm.Laplace, {"mu": R, "b": Rplus}, lambda q, mu, b: st.laplace.ppf(q, mu, b))
474470

475471
def test_laplace_asymmetric(self):
476472
check_logp(
@@ -647,6 +643,11 @@ def test_pareto(self):
647643
{"alpha": Rplusbig, "m": Rplusbig},
648644
lambda value, alpha, m: st.pareto.logcdf(value, alpha, scale=m),
649645
)
646+
check_icdf(
647+
pm.Pareto,
648+
{"alpha": Rplusbig, "m": Rplusbig},
649+
lambda q, alpha, m: st.pareto.ppf(q, alpha, scale=m),
650+
)
650651

651652
@pytest.mark.skipif(
652653
condition=(pytensor.config.floatX == "float32"),

0 commit comments

Comments
 (0)