pymc.MCMC algorithm

244 views
Skip to first unread message

Imri Sofer

unread,
Mar 25, 2011, 9:37:10 AM3/25/11
to PyMC
I just want to make sure that I understand what pymc.MCMC does, since
it is not written explicitly in the documentation.
As I understand it is basically a Gibbs sampler, so it loops over the
nodes of the model and sample each stochastic node using its step
method.
Did I get it right?

Imri

Chris Fonnesbeck

unread,
Mar 25, 2011, 9:42:25 AM3/25/11
to PyMC
Hi Imri,

Everything is documented pretty well in the user's guide and in our
JSS paper, actually:

http://www.jstatsoft.org/v35/i04/paper

The MCMC class is just a subclass of Sampler, and it coordinates the
sampling algorithm across all the variables in the model. The type of
MCMC algorithm differs according to the characteristics of the
particular stochastic, but the Metropolis step method is the most
general.

cf

Imri Sofer

unread,
Mar 25, 2011, 11:57:19 AM3/25/11
to PyMC
Hi Chris,
thanks for the reference. The documentation is very helpful and I use
it a lot. I think you guys did a great job, but I'm still confused.

is there a way for me to know which algorithm the sampler uses for a
specific model?
I am asking this question because I would like to use pymc in my
research and It is important to me to be able to write that I used the
X algorithm.

cheers,
Imri

Chris Fonnesbeck

unread,
Mar 25, 2011, 12:54:56 PM3/25/11
to PyMC
On Mar 25, 10:57 am, Imri Sofer <imriso...@gmail.com> wrote:
> is there a way for me to know which algorithm the sampler uses for a
> specific model?

The step methods used in a particular model are found in:

<my_model>.step_methods

So, in the disaster_model example this looks like:

In [6]: M.step_methods
Out[6]:
set([<pymc.StepMethods.Metropolis at 0x107777c90>,
<pymc.StepMethods.Metropolis at 0x107777c10>,
<pymc.StepMethods.DiscreteMetropolis at 0x107777d90>])


You can override the selected step method for a particular stochastic
using use_step_method:

M.use_step_method(Metropolis, M.switchpoint)

Hope that helps,
cf

Imri Sofer

unread,
Mar 25, 2011, 2:02:47 PM3/25/11
to PyMC
Chris, thank you for your answer, but I believe I did not explain
myself well. my question is more general then that.
I'm trying to understand how do the step methods combined together, in
other words what does MCMC.sample does in a single iteration.

for instance if in a single iteration the sampler loop over the nodes
and sample each node from its conditional distribution, then I would
say that I'm running a Gibbs sampler.

would it be correct to say that I use Gibbs sampling for the disaster
model?

Chris Fonnesbeck

unread,
Mar 25, 2011, 2:06:40 PM3/25/11
to PyMC
PyMC does not force you to use the same sampling algorithm over the
whole model. Its entirely possible to use Gibbs sampling over some of
the parameters, and Metropolis-Hastings for another, and gradient-
based methods for another. The most general, and probably most widely-
used, method in PyMC is the random-walk Metropolis sampler.

cf

Imri Sofer

unread,
Mar 25, 2011, 3:16:37 PM3/25/11
to PyMC
now I understand.
thank you

mbiet...@gmail.com

unread,
Dec 7, 2014, 5:52:55 AM12/7/14
to py...@googlegroups.com, imri...@gmail.com
What happens in cases where you have multiple step methods for some variablel?  How does pymc
decide which step method is to be used for the next step?
Reply all
Reply to author
Forward
0 new messages