Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement invgamma icdf + test #7619

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
12 changes: 11 additions & 1 deletion pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pytensor.tensor import gammaln, get_underlying_scalar_constant_value
from pytensor.tensor.exceptions import NotScalarConstantError
from pytensor.tensor.extra_ops import broadcast_shape
from pytensor.tensor.math import betaincinv, gammaincinv, tanh
from pytensor.tensor.math import betaincinv, gammainccinv, gammaincinv, tanh
from pytensor.tensor.random.basic import (
BetaRV,
_gamma,
Expand Down Expand Up @@ -2541,6 +2541,16 @@ def logcdf(value, alpha, beta):
msg="alpha > 0, beta > 0",
)

def icdf(value, alpha, beta):
res = beta / gammainccinv(alpha, value)
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 @@ -675,6 +675,13 @@ def test_inverse_gamma_logp(self):
lambda value, alpha, beta: st.invgamma.logpdf(value, alpha, scale=beta),
)

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),
)

@pytest.mark.skipif(
condition=(pytensor.config.floatX == "float32"),
reason="Fails on float32 due to numerical issues",
Expand Down
Loading