-
-
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
Implement logp derivation for division, subtraction and negation #6371
Implement logp derivation for division, subtraction and negation #6371
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6371 +/- ##
==========================================
- Coverage 94.79% 93.01% -1.78%
==========================================
Files 148 148
Lines 27488 27549 +61
==========================================
- Hits 26058 25626 -432
- Misses 1430 1923 +493
|
40d889e
to
8fd177f
Compare
8fd177f
to
6959886
Compare
Sorry for the very naive question, but I think I am still missing some pieces of the puzzle. I tried to understand what new models this will allow to write, but it looks like with pm.Model():
x = pm.Normal("x")
y = pm.Normal("y", 1/x, 1) was already possible before. Why is the |
No, you're not completely off tracks. The difference is that between a parameter transformation (what your snippet does) a variable transformation (what my snippet does). The difference between the two is easier if you just think about the logp you are requestiong: some_value = 1.0
x = pm.Normal.dist()
y = pm.Normal.dist(1/x)
pm.logp(y, some_value) # Fine before
z = 1 / x
pm.logp(z, some_value) # Failed before, now it works! This is more relevant for observed variables, so that you can condition on them directly. After this and #6361 you can do this: def inverse_normal(mu, sigma, size):
return 1 / pm.Normal.dist(mu, sigma, size=size)
with pm.Model() as m:
x = pm.Normal("x")
y = pm.CustomDist("y", mu, 1, random=inverse_normal, observed=data) PyMC will now be able to derive the logp of The way this functionality trickles down to users is that they don't need us to implement InverseNormal, InverseGamma, Inverse.... They can simply use |
6959886
to
48eb532
Compare
Adds rewrite that converts divisions with measurable variables to product with reciprocals, making the reciprocal measurable transform more widely applicable.
48eb532
to
a819fcf
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.
Elementary school math. I feel confident about this 👍
This implements measurable rewrites for the following type of graphs:
As well as:
It works by canonicalizing such operations to the form already understood by
find_measurable_transforms
(only a new condition forReciprocal
s was added)These canonicalizations are only applied when MeasurableVariables are involved to minimize disruption of the underlying graph
Bugfixes / New features