Skip to content

Commit

Permalink
Added ICDF for the Kumaraswamy distribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
gokuld committed Apr 1, 2023
1 parent 8d5b236 commit 4598cd4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,16 @@ def logcdf(value, a, b):
msg="a > 0, b > 0",
)

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


class Exponential(PositiveContinuous):
r"""
Expand Down
16 changes: 16 additions & 0 deletions tests/distributions/test_continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,22 @@ def scipy_log_cdf(value, a, b):
{"a": Rplus, "b": Rplus},
scipy_log_cdf,
)
check_icdf(
pm.Kumaraswamy,
{"a": Rplus, "b": Rplus},
lambda q, a, b: (1 - (1 - q) ** (1 / b)) ** (1 / a),
)

# Custom logp / logcdf / icdf check for invalid parameters
for a, b in ((-2, 0.5), (0.5, -2), (-2, -2)):
invalid_dist = pm.Kumaraswamy.dist(a=a, b=b)
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_exponential(self):
check_logp(
Expand Down

0 comments on commit 4598cd4

Please sign in to comment.