-
-
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
Add PolyaGamma distribution class #4531
Conversation
Thanks for taking this on @zoj613 |
Hi @twiecki, I am new to the pymc3 distribution API. I have a few questions, and I hope you will be able to provide some guidance.
|
That's passed through to
We don't need to implement a
It looks like you've implemented the old As you can see, the new API only requires values/implementations for the class-level
Simply put, there's no use for a |
Okay, I tried upgrading the distribution to the v4 design. It seems like I had to create a RandomVariable class for the distribution since the |
Sorry, I left that out, but it's the most important and distinct thing about this particular case (i.e. adding an entirely new random variable)! You should be able to just copy the implementation of (N.B.: You can even put in a PR to remove that
Just like the current implementation of
Other implementations use |
By the way, when you copy the You're breaking ground when it comes to implementing new |
After taking a closer look at the distribution I realised implementing the pdf and cdf of the distribution is easier than I initially thought. So I added these and their logs in a recent PR zoj613/polyagamma#58. I will update this one soon. It looks like you made changes to distribution API @brandonwillard. I see the dispatch functions for |
30ccfb6
to
c6d2ff8
Compare
That's great news! Having the log-likelihoods available will allow the PG distribution to be used with gradient-based samplers—like the default NUTS used by PyMC.
I somewhat simplified the process of creating Here's a summary of how new |
Thanks,that was very helpful. I think I have done all that is required to implement the classes. I just need to write tests for it. How does one implement the logic for conversion between tensors and numpy arrays? The distribution's sampler and logp/logcdf can only accept scalars/numpy arrays/lists/tuples and other objects that can be converted to a numpy array. Or is this left up to the caller to pass the correct data types? When do I have to call |
The log-likelihoods returned by the |
Okay, I see. I pushed new changes and added a basic test case for the distribution. Please feel free to give feedback about what the implementation is missing that still needs to be accounted for. I wasn't sure how to proceed with the testing since the test module seems like its due for an update. |
e6d7ae8
to
af23c2f
Compare
Not sure what happened here. Was the merge intentional @brandonwillard? It looks like it introduced other commits into this branch EDIT: I fixed the commits the spilled over to this branch |
6e5f4a9
to
ac6f6aa
Compare
I suppose it could be snuck in here https://github.com/pymc-devs/pymc3/blob/7e464e59bcb0adb28df94f379b3e8d4af12bd4d1/.github/workflows/pytest.yml#L133-L137 However i'm not sure how appropriate that is given that it is a third-party library that isn't a dependency. |
We have custom code that is used to integrate the library (the op), so that should probably be tested. |
EDIT: I added it |
The logp/logcdf tests in Can you replicate locally if you add |
It fails with the error: |
Can you convert it when you call it inside perform? |
Just updated the code. The tests now pass locally for float32. |
All tests cases pass on Ubuntu. Seems like the test failure is unrelated to this PR: I've pushed another commit to ensure the tests on Windows are not skipped. |
Running the tests again. Thanks for checking it out. |
The test failure is again unrelated. All other relevant tests pass. I do notice that the tests are still being skipped on windows even though I explicitly install the package for the OS. It appears the conda environment is not able to pick it up somehow because there are no signs of installation failure. |
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.
Thanks, looks ready to me
LGTM, needs a line in the release notes though. CI failure seems unrelated, opened #4853. |
@zoj613 just needs a rebase to fix the conflict issues. |
Done. Should I squash the commits? Some don't look useful for the commit history past the review. |
Good idea.
…On Tue, Jul 13, 2021 at 2:59 PM zoj613 ***@***.***> wrote:
@zoj613 <https://github.com/zoj613> just needs a rebase to fix the
conflict issues.
Done. Should I squash the commits? Some don't look useful for the commit
history.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4531 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFETGB2WBDVO2WK7QWTX3LTXQ2CDANCNFSM4ZAXZPRA>
.
|
Requested changes are implemented.
Unrelated test failure: Details________________________ TestSMC.test_parallel_sampling ________________________ self = <pymc3.tests.test_smc.TestSMC object at 0x7faf16e577d0>
E assert 2.209818124771118 < 2.16743540763855 |
Merged, thanks for your patience @zoj613 Hope to see more PRs from you in the future, including the pymc-examples if you come up with a good case study :) |
Sure, i'm working on an example. Thanks for the reviews. |
This PR add a PolyaGamma distribution class. See #4520.
Polya-gamma random variables are commonly used as auxiliary variables during data augmentation in Bayesian sampling algorithms, which have wide-spread usage in Statistics. The random number generation uses the
polyagamma
package which implements the sampling methods described in the paper: Sampling Polya-Gamma random variates: alternate andapproximate techniques.Depending on what your PR does, here are a few things you might want to address in the description: