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

refactor kumaraswamy #4706

Merged
merged 6 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,24 @@ def logp(value, a, b):

return bound(logp, value >= 0, value <= 1, a > 0, b > 0)

def logcdf(value, a, b):
r"""
Compute the log of cumulative distribution function for the Kumaraswamy distribution
at the specified value.

Parameters
----------
value: numeric or np.ndarray or aesara.tensor
Value(s) for which log CDF is calculated. If the log CDF for
multiple values are desired the values must be provided in a numpy
array or Aesara tensor.

Returns
-------
TensorVariable
"""
return bound(at.log1p(-((1 - value ** a) ** b)), value >= 0, value <= 1)
Copy link
Member

@ricardoV94 ricardoV94 May 17, 2021

Choose a reason for hiding this comment

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

Value above one should give a logcdf of 0, so we need a switch: at.switch(value < 1, normal expression, 0), and to remove value <= 1 as a bound condition. We should still keep the a > 0 and b > 0 conditions as in the logp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does tt equal to at? Because I assume tt is Theano tensor and it is not available.

Copy link
Member

@ricardoV94 ricardoV94 May 17, 2021

Choose a reason for hiding this comment

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

Yes of course. It was a mistake, I am still used to writing with theano's abbreviation :p

Fixed the comment



class Exponential(PositiveContinuous):
r"""
Expand Down
4 changes: 4 additions & 0 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,11 @@ def scipy_log_pdf(value, a, b):
np.log(a) + np.log(b) + (a - 1) * np.log(value) + (b - 1) * np.log(1 - value ** a)
)

def scipy_log_cdf(value, a, b):
return np.log1p(-((1 - value ** a) ** b))

self.check_logp(Kumaraswamy, Unit, {"a": Rplus, "b": Rplus}, scipy_log_pdf)
self.check_logcdf(Kumaraswamy, Unit, {"a": Rplus, "b": Rplus}, scipy_log_cdf)

def test_exponential(self):
self.check_logp(
Expand Down