Skip to content

Commit

Permalink
Added ICDF for the continuous exponential distribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
gokuld committed Apr 1, 2023
1 parent 8d5b236 commit 662edf0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,15 @@ def logcdf(value, mu):
msg="lam >= 0",
)

def icdf(value, mu):
res = -mu * pt.log(1 - value)
res = check_icdf_value(res, value)
return check_icdf_parameters(
res,
mu >= 0,
msg="mu >= 0",
)


class Laplace(Continuous):
r"""
Expand Down
14 changes: 14 additions & 0 deletions tests/distributions/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,20 @@ def test_exponential(self):
{"lam": Rplus},
lambda value, lam: st.expon.logcdf(value, 0, 1 / lam),
)
check_icdf(
pm.Exponential,
{"lam": Rplus},
lambda q, lam: st.expon.ppf(q, loc=0, scale=1 / lam),
)
# Custom logp / logcdf / icdf check for invalid parameters
invalid_dist = pm.Exponential.dist(lam=-1)
with pytensor.config.change_flags(mode=Mode("py")):
with pytest.raises(ParameterValueError):
logp(invalid_dist, np.array(0.5)).eval()
with pytest.raises(ParameterValueError):
logcdf(invalid_dist, np.array(0.5)).eval()
with pytest.raises(ParameterValueError):
icdf(invalid_dist, np.array(0.5)).eval()

def test_laplace(self):
check_logp(
Expand Down

0 comments on commit 662edf0

Please sign in to comment.