Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions tests/distributions/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"),
Expand Down