Skip to content
Open
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
10 changes: 10 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,16 @@ def logcdf(value, alpha, beta):
msg="alpha > 0, beta > 0",
)

def icdf(value, alpha, beta):
res = 1 / Gamma.icdf(value=1 - value, alpha=alpha, scale=1 / beta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use the stable API, and then you don't need to hack with the scale thing either

Suggested change
res = 1 / Gamma.icdf(value=1 - value, alpha=alpha, scale=1 / beta)
res = 1 / icdf(Gamma.dist(alpha=alhpa, beta=beta), value=1 - value)

Copy link
Member

@ricardoV94 ricardoV94 Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For curiosity only, any intuition why the icdf looks like it does, specially the flipped value. It's interesting

res = check_icdf_value(res, value)
return check_icdf_parameters(
res,
alpha > 0,
beta > 0,
msg="alpha > 0, beta > 0",
)


class ChiSquared:
r"""
Expand Down
7 changes: 7 additions & 0 deletions tests/distributions/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,13 @@ def test_fun(value, mu, sigma):
decimal=select_by_precision(float64=4, float32=3),
)

def test_inverse_gamma_icdf(self):
check_icdf(
pm.InverseGamma,
{"alpha": Rplusbig, "beta": Rplusbig},
lambda q, alpha, beta: st.invgamma.ppf(q, alpha, scale=beta),
)

def test_pareto(self):
check_logp(
pm.Pareto,
Expand Down