-
-
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
Replace zero inflated distributions with mixtures #5584
Replace zero inflated distributions with mixtures #5584
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5584 +/- ##
==========================================
- Coverage 87.64% 87.59% -0.05%
==========================================
Files 76 76
Lines 13775 13732 -43
==========================================
- Hits 12073 12029 -44
- Misses 1702 1703 +1
|
9771af3
to
6fc28bc
Compare
Nice refactor. |
3479b29
to
ba6b9a0
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.
Overall looks great! Left some questions so I can better understand myself 😅 (and maybe for others reading this PR!)
An overarching question that I have is what benefits do we get from positing a Mixture-type rv_op for zero-inflated distributions? My understanding was that Mixture distributions inherit from SymbolicDistribution
as a way to initialize a different rv_op depending on how many and what comp_dists
are provided. However, for zero-inflated distributions, there will always be "two" components: the zero Constant distribution and Poisson/binomial/negative binomial. Perhaps the answer is simple but I was just wondering...
weights = at.stack([1 - nonzero_p, nonzero_p], axis=-1) | ||
comp_dists = [ | ||
Constant.dist(0), | ||
nonzero_dist, |
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.
Does nonzero_dist
here have to be Discrete
?
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.
I think your question might be related to #4511
Still need to make sure we are not combining discrete and continuous distributions in mixtures. In the cases here they are both supposed to be discrete yes
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.
Did you have another thing in mind?
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 is exactly what I had in mind! I was wondering if it would help to have a check that nonzero_dist
is discrete, but, as you mentioned above, it may not be necessary since _zero_inflated_mixture
is not a user-facing function.
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.
Yes, and I want to add an explicit check in the Mixture class in a follow up PR
The biggest advantage is less code for us to maintain. As Thomas hinted above this is just a refactor. Reusing a building block also means any bug fixes there propagate everywhere quickly. For instance, the old RandomVariable Ops actually had a slight bug in that they did not broadcast psi with the other parameters when size was not specified. So Instead of having to fix this everywhere, it's now enough to do it (and test it) in one place as I did here: 78f1786 |
What about the integrated versions? I guess we get those automatically once it's added to |
What do you mean integrated? |
Upon thinking about it I don't think it makes sense here. |
ba6b9a0
to
650a217
Compare
c71a919
to
a6e6748
Compare
0fbcd1d
to
3917d88
Compare
For consistency with the base Poisson distribution
3917d88
to
68bb77a
Compare
Okay I see, thanks for the clarification! Makes a lot of sense |
Required the following extra changes: