Skip to content

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

Closed
wants to merge 4 commits into from
Closed

Add single component samplers. #450

wants to merge 4 commits into from

Conversation

twiecki
Copy link
Member

@twiecki twiecki commented Jan 7, 2014

This PR adds SingleComponentSlice and SingleComponentMetropolis (derived from base class SingleComponentSampler) and appropriate unittests.

It was confusing before that in PyMC 2 the normal usage of samplers mostly produced single component updates while instantiating Slice() or Metropolis() 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).

@twiecki
Copy link
Member Author

twiecki commented Jan 10, 2014

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)
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.])

Copy link
Member Author

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().

Copy link
Member

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.

@jsalvatier
Copy link
Member

This will be a good addition. Thanks for fixing the problem in master too!

@twiecki
Copy link
Member Author

twiecki commented Jul 21, 2014

This is the wrong approach I realized now. We should just add a kwarg blocked to the samplers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants