-
Notifications
You must be signed in to change notification settings - Fork 423
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 rrule
for logpdf
of NegativeBinomial
#1568
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.
Can you add tests with ChainRulesTestUtils.test_rrule? It should cover in-support, out-support values, and the special case.
Codecov Report
@@ Coverage Diff @@
## master #1568 +/- ##
=======================================
Coverage 85.52% 85.52%
=======================================
Files 128 128
Lines 7861 7882 +21
=======================================
+ Hits 6723 6741 +18
- Misses 1138 1141 +3
Continue to review full report at Codecov.
|
Co-authored-by: David Widmann <[email protected]>
Co-authored-by: David Widmann <[email protected]>
There are some errors in testing the rrule (as opposed to test failures). I'm not completely sure I'm using the test correctly, but the fact that the test is hitting negative parameters could be an issue of the finite differencing scheme, right? |
Possibly. Probably you can fix these by using e.g. |
https://github.com/JuliaDiff/FiniteDifferences.jl#dealing-with-singularities |
Tests for EDIT: scratch that, apparently there are some parameters that still fail. |
I managed to make all tests pass except the ones for |
I made the following changes:
As it now turns out, the ForwardDiff derivative wrt. |
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'm not really happy with the changes of the tests. Generally, I think we should try to avoid making any unrelated changes also of the tests since that possibly unintentionally relaxes some existing tests and hence makes it easier for bugs to sneak in in the future.
My suggestion is to keep it really simple and just add some test_rrule
s that cover all branches. Due to the numerical issues of finite differencing we can't just not add it inside the loop for ForwardDiff. IMO that's fine, just test some other parameters in a separate loop (if you want to test multiple parameters).
The ForwardDiff issue might be fixed by JuliaDiff/ForwardDiff.jl#481 (assuming it's about a measure-zero branch). DiffRules won't help here since then the result will be non-deterministic: If users load ForwardDiff before Distributions, the rules won't be picked up by ForwardDiff.
Ok, I think I might have misunderstood your previous comment then:
I took this to mean that while we're at it, we should use finite differencing also to test ForwardDiff against, given that previously it was tested against the analytical derivative, to have uniformity between ForwardDiff and the rrule. The new ForwardDiff tests are more comprehensive because they now also cover edge cases and the derivative wrt. Please let me know how you would like me to proceed. Some of the following options may not be independent of each other:
|
Co-authored-by: David Widmann <[email protected]>
I rearranged the tests. ForwardDiff is now tested against analytical derivatives and in the old parameters ranges as before, but additionally there are tests
As some of them fail for some parameters or for all parameters, they are marked with |
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 noticed that even the current iteration of the tests doesn't actually test all branches and contains changes unrelated to this PR. I thought maybe it's easier and faster if I implement directly what I had in mind, so I opened #1579 since I was not sure if you are OK with me pushing to this PR. I could also push my commit to this PR if you prefer. In any case I'd like to merge one of the PRs since I think the rrule
is very useful 🙂
No worries, you can close this PR and merge the other one. |
This is superseded by #1579 |
* Add `rrule` for `logpdf` of `NegativeBinomial` * Remove unnecessary module prefix Co-authored-by: David Widmann <[email protected]> * Use explicit division Co-authored-by: David Widmann <[email protected]> * Refator and correct pullback * Add tests for rrule * Use `forward_fdm` for testing `rrule` * Fix tests * Update test/negativebinomial.jl * Fix tests (without `p = 1 - eps()`) * Use FD for all tests, use random parameters * Avoid type instability Co-authored-by: David Widmann <[email protected]> * Split and rearrange ForwardDiff and rrule tests * Bump version * Fix typo * Clean tests (revert unrelated changes) and fix them Co-authored-by: Simone Carlo Surace <[email protected]> Co-authored-by: Simone Carlo Surace <[email protected]>
This needs to be tested, and not entirely sure about the edge case.