-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add single component samplers. #450
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
This also fixes the travis issue currently on master. |
@@ -61,7 +61,7 @@ def rmap(self, apt): | |||
dpt = self.dpt.copy() | |||
|
|||
for var, slc, shp in self.ordering.vmap: | |||
dpt[var] = np.reshape(apt[slc], shp) | |||
dpt[var] = np.reshape(np.atleast_1d(apt)[slc], shp) |
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 means we won't distinguish between, 0-d and 1-d values, is that okay? That makes me a little nervous.
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.
Well 0d is a float which you can't index into which is what produced an exception here.
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 think they actually can: array(1.0)[()]
gives 1.0
and array(1.0).ravel()
gives array([1.])
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.
Hm, so for some reason a float got passed in here. Alternatively we could wrap it with np.asarray()
.
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.
Using asarray
here seems good. Though I would slightly prefer figuring out why a float was passed.
This will be a good addition. Thanks for fixing the problem in master too! |
This is the wrong approach I realized now. We should just add a kwarg |
This PR adds
SingleComponentSlice
andSingleComponentMetropolis
(derived from base classSingleComponentSampler
) and appropriate unittests.It was confusing before that in PyMC 2 the normal usage of samplers mostly produced single component updates while instantiating
Slice()
orMetropolis()
in PyMC 3 does block updating by default.To have an easy option to get to single component samplers I added these.
I had to skip the unittest for Metropolis as it was converging to the correct value, I think related to #358. (FWIW I did review the code but couldn't find any logic bug).