-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Infer logprob of absolute operations and fix logprob of powers with negative values #6414
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
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6414 +/- ##
==========================================
+ Coverage 86.05% 94.73% +8.68%
==========================================
Files 148 148
Lines 27646 27698 +52
==========================================
+ Hits 23792 26241 +2449
+ Misses 3854 1457 -2397
|
Thanks for opening a PR!
Hmm, it should behave the same for negative values... Not sure what's the best way to encode that. What happens with a In that case the jacobian could perhaps be:
But the logp will be broken in both cases without jacobian. Perhaps we need to implement a specific logprob for the absolute and power transforms Regardless of the solution, we should add test for those cases, hadn't thought of them |
Applogies I have gotten this the wrong way round... in the example: import pymc as pm
x = pm.math.abs(pm.Normal.dist())
y = pm.HalfNormal.dist()
z = pm.Normal.dist() ** 0.5
print(pm.logp(x, -2.5).eval(), pm.logp(y, -2.5).eval(), pm.logp(z, -2.5).eval()) x = nan, y = -inf, z = nan. So the transforms return nan values. |
Yup, |
Hi @LukeLB I wanted to leave a review but ended up having to try many things locally that in the end it was easier to push my suggestions as a separate commit. I realized the issue you found was not specific to power transforms, but any transform that is constrained. For instance the I also tweaked some of your tests and tried to simplify the PowerTransform logic. Let me know what you think, and if you agree with the changes I will clean a bit the commits before merging. Thanks a lot for the work so far! |
7bc23dd
to
4c4a9e5
Compare
@ricardoV94 yes this looks like a more robust solution, just checking for the |
I'll just clean a bit the commits. I don't think anything else is needed, just wanted your input :) |
Awesome! Thank you for helping me through this PR! |
We rely on the jacobian returning `nan` for invalid values Co-authored-by: Luke LB <[email protected]>
Co-authored-by: Luke LB <[email protected]>
4c4a9e5
to
0ce4eec
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.
Cleaned up the commits, didn't change any content
Thanks @LukeLB! This one required a bit of digging because it wasn't really working from the previous PRs, nice finding! |
What is this PR about?
Following from #6400 and implements #6402. This PR allows the use of an absolute transform for cases like
I have included the above example as a test.
Some notes:
Because in this case,
x
returns-inf
whiley
returnsnan
Checklist
New features