-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Track model logp (in HMC and NUTS) #3134
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
Oh you are right - in Metropolis we only computed the delta_logp. Hmmm, it does complicate things... |
This seems to pass tests now. The test it fails is due to SMC and appears unrelated. Ready for review! What I've done for CompoundStep is to remove |
Need a new test to check if the logp is saved correctly at least. Also, add a line to release-note. I think this is a good first step. Maybe in another PR we can also add it to other samplers. I have an idea to do this also for Metropolis where we are computing the delta_logp instead of the logp. We can compute the model logp at sample 0, then from sample 1 onward we do |
RELEASE-NOTES.md
Outdated
- Track the model log-likelihood as a sampler stat for NUTS and HMC samplers | ||
(accessible as `trace.logp`). | ||
|
||
### Fixes |
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.
This is more maintenance.
@junpenglao I'm actually not sure where the tests for sampler stats are. I would've thought |
pymc3/tests/test_step.py |
Sorry for the lull, I was taking a break from my laptop! I've added a test to assert the existence of various sampler stats for NUTS, and also assert that their shapes are correct. Let's see if this passes tests. |
Passes tests! @junpenglao ready for review |
Maybe we should rename it to |
Hm, my concern is how intuitive a name I don't really know much about Arviz though. Is "compatibility" with Stan/Arviz a high priority for the PyMC devs? |
I agree with @eigenfoo, |
In that case, either |
Yeah, agree on using a descriptive name - I think |
@junpenglao I think I like I'll need some help with the test though - see my comment above. |
Awesome work @eigenfoo |
Maybe better |
It gets a little semantic, I suppose. Its the log-probability of the model at a particular point, so I don't think |
How about |
But I guess you have a point. They all probably work. (except that last one) |
This looks good to me (and something I will use right away) - thanks, @eigenfoo! Is there something specific you would still like review on? |
For the record, the problem that stalled me up was this: The way The "bad thing" about this PR is best explained by example: with pm.Model():
x = pm.Normal('x')
y = pm.Normal('y')
step1 = pm.NUTS([mu1])
step2 = pm.NUTS([mu2])
trace = pm.sample(step=[step1, step2]) Here, Eventually, @ColCarroll and I decided that it's better to keep this quirk and document it, rather than having an inconsistent API. This means that if you wanted the overall logp for with a I think we're going to go ahead and merge this once tests pass. |
Hm yeah that's unfortunate but I agree with your assessment. |
Thank @eigenfoo! |
Thanks for this! |
Close #2971.
WIP. Following up from #3121. I'm opening up this PR so I can get Travis builds/tests/feedback from maintainers 😄
@ColCarroll I've done a first pass at tracking the logp. The sampler stats stack actually goes deeper than you outlined before, since the model logp is actually kept in
integration.py
for HMC. What I've done is modify theState
so it keeps track of the model logp, and percolate that up as a sampler stat to HMC and NUTS.@junpenglao currently this PR falls a bit short of what you were expecting; I've only made the model logp a sampling stat for HMC and NUTS. If I'm not mistaken, no other sampler computes the logp (e.g. Metropolis doesn't), so there would be overhead to require these samplers to track the logp. However, if this is a feature the dev team wants, I'd be happy to do that too - probably in a separate PR, though.
I'm also unsure about the
compoundstep
changes...states
is a list, and cannot be indexed by a string. I must have misunderstood @junpenglao's comments here: I'll take another look sometime in the next few days. For now, tests will fail for that.