-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Generalize multinomial moment to arbitrary dimensions #5476
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
Generalize multinomial moment to arbitrary dimensions #5476
Conversation
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.
Hi @markvrma thanks for opening a PR!
Besides the comment below, we also need to add test conditions to make sure the moment is indeed correct for higher dimensions. This PR is a good template: https://github.com/pymc-devs/pymc/pull/5225/files
pymc/distributions/multivariate.py
Outdated
if (p.ndim == 1) and (n.ndim > 0): | ||
n = at.shape_padright(n) | ||
p = at.shape_padleft(p) |
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 we shouldn't need any these shape_padright/left anymore
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 tried removing:
if p.ndim > 1:
n = at.shape_padright(n)
if (p.ndim == 1) and (n.ndim > 0):
n = at.shape_padright(n)
p = at.shape_padleft(p)
but existing tests fail in test_distributions_moments.py
FAILED test_distributions_moments.py::test_multinomial_moment[p4-n4-None-expected4]
FAILED test_distributions_moments.py::test_multinomial_moment[p5-n5-None-expected5]
FAILED test_distributions_moments.py::test_multinomial_moment[p6-n6-2-expected6]
Codecov Report
@@ Coverage Diff @@
## main #5476 +/- ##
==========================================
- Coverage 87.60% 81.45% -6.16%
==========================================
Files 76 81 +5
Lines 13745 14205 +460
==========================================
- Hits 12041 11570 -471
- Misses 1704 2635 +931
|
Added new test for higher dimensions. I couldn't remove: if p.ndim > 1:
n = at.shape_padright(n)
if (p.ndim == 1) and (n.ndim > 0):
n = at.shape_padright(n)
p = at.shape_padleft(p) as existing tests fail in |
We might need something else, instead of just removing these lines. Or perhaps those lines also give the right result for higher dimensions that are now supported, but I would be surprised if that was the case, since they seem to have specialized logic for <= 2D parameters. I would brute-force with local tests where we try different combinations of pymc/pymc/tests/test_distributions.py Lines 2228 to 2251 in c892317
and here: pymc/pymc/tests/test_distributions.py Lines 335 to 347 in c892317
pymc/pymc/tests/test_distributions.py Lines 2297 to 2319 in c892317
|
Also did you figure out what exactly is failing? Looking at the DirichletMultinomial mode it seems like it should be exactly the same, except that here we already have the |
9271395
to
adeb799
Compare
adeb799
to
1785167
Compare
@markvrma It seems than it was enough to add one dimension to the right of Thanks for the help! |
Resolves #5393