-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 missing discrete dists #4684
Refactor missing discrete dists #4684
Conversation
12bfdfd
to
df0222e
Compare
pymc3/distributions/discrete.py
Outdated
@classmethod | ||
def rng_fn(cls, rng, c, size=None): | ||
ones = np.ones_like(c) | ||
return rng.randint(ones, ones + 1, size=size) * c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There must be a less hacking way to get a filled array given c
and size
, that works as other random generators would. np.full(size, c)
doesn't seem to cut it, because it works with shape and not with size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't shape and size the same thing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No because c
could be a vector and size
could be None for instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, actually I think the only problem was size=None
. I added a check for that condition...
df0222e
to
cbd72dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Thanks for taking this on @ricardoV94. Separately, when I tried V4 it seems like other continuous distributions are also missing, like |
Yes they are missing. Only distributions that have a I won't have more time this week, so if someone wants to open a PR for the missing continuous distributions it would be great. The logic should be pretty similar to what is done in this PR with the custom RandomOps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but we really shouldn't rely on Distribution.logp
functions, since those aren't officially part of the Distribution
API—they're just a means of conveniently specifying dispatches.
6aae83e
to
e8ec87d
Compare
@brandonwillard I am not sure what you have in mind. This looks wrong, right? # at.log(psi) + Poisson.logp(value, theta)
at.log(psi) + _logp(poisson, value, {value: value}, theta) I also tried this, but it fails following a at.log(psi) + logpt(Poisson.dist(theta), value) |
e8ec87d
to
d13e871
Compare
No, that looks like the correct approach. |
Could you give some intuition why this is better than the original approach? |
As I stated in my original review comments, these More importantly, we do not want to rely on the Simply put, this approach unnecessarily adds If this sort of use case needs to be simplified, it can be done in better ways that are based only on the underlying dispatch. |
🥳 |
This PR refactors all missing univariate discrete distributions.
I decided to refactor the
Constant
distribution after some debate on Slack as to whether this should be deprecated or not. Its direct use might be pretty problematic without a custom step algorithm, but could still be useful indirectly, such as in mixture distributions. I made the dtype of the RV befloatX
to accept non-integer outputs (even though this distribution should be treated as a pmf, see Mixture should not allow mixing of discrete and continuous distributions #4511 for why this might matter)I created separate RandomOps for the ZeroInflated* distributions for now. Similarly to Replace custom RandomVariable for WeibullBetaRV #4683, this should only be done temporarily until we have Mixture Distributions working on V4 (it seems such approach was already attempted in the past WIP: Convert zero-inflated distributions to Mixture subclasses #2246, WIP Implement ZeroInflatedPoisson as a subclass of Mixture #1459)
Depending on what your PR does, here are a few things you might want to address in the description: