Implementing step methods that use multiple chains

82 views
Skip to first unread message

John Salvatier

unread,
Oct 25, 2009, 4:11:22 AM10/25/09
to py...@googlegroups.com
Hello,

Is there a recommended way to implement step methods that use multiple interdependent chains? Is this possible with PyMC? I ask because I am interested in creating an implementation of "DREAM" (link) for PyMC

Best Regards,
John Salvatier

Anand Patil

unread,
Oct 26, 2009, 5:41:20 AM10/26/09
to py...@googlegroups.com
Hi John,

This is uncharted territory, but I'd suggest two new classes: one that holds multiple MCMC samplers, and one that holds multiple step methods. The individual step methods would be used by the individual MCMC samplers. At intervals, the multi-MCMC object could coordinate tuning in the multi-step methods. 

David has given some thought to running multiple chains in different processes, but he's travelling for the next couple of weeks or so. I don't know what the current best practice is for interprocess communication.

Fire away if you have questions as you move forward.

Anand

John Salvatier

unread,
Nov 2, 2009, 1:21:03 AM11/2/09
to py...@googlegroups.com
Hi Anand,

I have been building a prototype for this idea, and I have a question:

 If I have multiple MCMC samplers and multiple step methods more or less as you suggested, and one of the step methods updates its self.stochastics will this interfere at all with the other step methods in the other MCMC objects?

Thanks for your help.

Best Regards,
John

Anand Patil

unread,
Nov 2, 2009, 5:17:43 AM11/2/09
to py...@googlegroups.com
On Mon, Nov 2, 2009 at 6:21 AM, John Salvatier <jsal...@u.washington.edu> wrote:
 If I have multiple MCMC samplers and multiple step methods more or less as you suggested, and one of the step methods updates its self.stochastics will this interfere at all with the other step methods in the other MCMC objects?

Yes, it will, if they're sharing the stochastics. You'd need to have multiple versions of each stochastic in memory.

Cheers
Anand

John Salvatier

unread,
Nov 2, 2009, 6:15:30 PM11/2/09
to py...@googlegroups.com
Is there an easy way to copy a collection of stochastics for something like this?

Anand Patil

unread,
Nov 3, 2009, 4:38:58 AM11/3/09
to py...@googlegroups.com
On Mon, Nov 2, 2009 at 11:15 PM, John Salvatier <jsal...@u.washington.edu> wrote:
Is there an easy way to copy a collection of stochastics for something like this?


Rather than copying them after they're created, I'd suggest creating multiple copies:

def make_model():
    A = Normal('A',0,1)
    B = Normal('B',A,1)
    return locals()

M1 = MCMC(make_model())
M2 = MCMC(make_model())

Anand

John Salvatier

unread,
Dec 17, 2009, 11:21:14 PM12/17/09
to py...@googlegroups.com
Hello all,

I have built a prototype sampler that relies on multiple interdependent chains and Differential Evolution based on "DREAM" (link) (DREAM eliminates the need for tuning and handles multiple modes well) for PyMC. I took Anand Patil's design advice to have an object that contains several MCMC objects which contain a step method, but this makes it work outside of the PyMC framework, since you can't just pass a step method to the normal MCMC object and as Anand Patil suggested, the user must implement a model generating function. If anyone wants to look at it I can send it along.

I do have a question: have the PyMC developers considered making multiple chains a more fundamental part of PyMC? I am under the impression that multiple chains are also useful for assessing convergence and ensuring that the whole space is explored.

Best Regards,
John Salvatier


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "PyMC" group.
To post to this group, send email to py...@googlegroups.com
To unsubscribe from this group, send email to pymc+uns...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/pymc?hl=en
-~----------~----~----~----~------~----~------~--~---


Flavio Coelho

unread,
Dec 18, 2009, 4:27:45 AM12/18/09
to py...@googlegroups.com
Hi John,

I am interesting in seeing what you have done. 

By the way, your link for "DREAM" leads to a "page not found error"

Best,

Flávio 

--

You received this message because you are subscribed to the Google Groups "PyMC" group.
To post to this group, send email to py...@googlegroups.com.
To unsubscribe from this group, send email to pymc+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pymc?hl=en.



--
Flávio Codeço Coelho

Anand Patil

unread,
Dec 18, 2009, 10:01:39 AM12/18/09
to py...@googlegroups.com
Thanks for the update, John! I'd be very interested in having a look
at your code.

On Fri, Dec 18, 2009 at 4:21 AM, John Salvatier
<jsal...@u.washington.edu> wrote:
> I do have a question: have the PyMC developers considered making multiple
> chains a more fundamental part of PyMC? I am under the impression that
> multiple chains are also useful for assessing convergence and ensuring that
> the whole space is explored.

Could you be more specific about what you have in mind?

Anand

> --


>
> You received this message because you are subscribed to the Google Groups
> "PyMC" group.

> To post to this group, send email to py...@googlegroups.com.


> To unsubscribe from this group, send email to

> pymc+uns...@googlegroups.com.


> For more options, visit this group at

> http://groups.google.com/group/pymc?hl=en.
>

Jose Gomez-Dans

unread,
Dec 18, 2009, 12:15:36 PM12/18/09
to py...@googlegroups.com
John,

On Fri, Dec 18, 2009 at 4:21 AM, John Salvatier <jsal...@u.washington.edu> wrote:
I have built a prototype sampler that relies on multiple interdependent chains and Differential Evolution based on "DREAM" (link) (DREAM eliminates the need for tuning and handles multiple modes well) for PyMC. I took Anand Patil's design advice to have an object that contains several MCMC objects which contain a step method, but this makes it work outside of the PyMC framework, since you can't just pass a step method to the normal MCMC object and as Anand Patil suggested, the user must implement a model generating function. If anyone wants to look at it I can send it along.

I have an implementation of the DEMC_ZS sampler from ter Braak et al, although not within pymc, it's python code. Happy to pass it around if anyone wants to have a look at it. The chains can be run using multiprocessing, so effectively it's parallel (may not be the cleanest implementation,, but appears to work). Naturally, I'd love to have a peek at your implementation of DREAM. I am not fully conversant in terms of pymc, but I hope I can chip something in.

Cheers,
Jose

--
RSU ■ Dept. of Geography ■ University College ■ Gower St, London WC1E 6BT UK
EMM ■ Dept. of Geography ■ King's College ■  Strand, London WC2R 2LS UK

John Salvatier

unread,
Dec 19, 2009, 12:39:17 AM12/19/09
to py...@googlegroups.com
Hello all,

Since there was a reasonable amount of interest in the step method, I have created a package pymcdream (http://pypi.python.org/pypi/pymcdream). The source distribution should also contain the original paper along (since Flavio had trouble with the link, though it still works for me) with the matlab implementation of DREAM I got from Dr. Vrugt in case those are of interest. I hope that my comments are clear enough to explain how the sampler works. There are also two very simple examples in the source distribution (I never know where the best place to put examples for packages is), one example of inference for a normal distribution and a non-linear regression example.

Please do not hesitate to e-mail me if you have any comments, questions, errors, suggestions. Tell me what you think.

Anand:
I mean having each stochastic be capable of keeping track of multiple positions at once, so perhaps instead of assigning proposals to stochastic.value you would assign to stochastic.value[i] and likewise get the logp from logp_plus_loglike[i] and reject by .revert(i). Does that make sense?

Best Regards,
John Salvatier

--

You received this message because you are subscribed to the Google Groups "PyMC" group.
To post to this group, send email to py...@googlegroups.com.
To unsubscribe from this group, send email to pymc+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pymc?hl=en.

Flavio Coelho

unread,
Dec 19, 2009, 7:41:28 AM12/19/09
to pymc
Thanks Jonh,

I just tried again the link, and it is working...
From my initial look at your code, and my still supperficial undertanding of the whole PyMC API, I think your sampler can be easily parallelized using multiprocessing with some variables, such as currentVectors and CurrentLogPs being shared (maybe) at the DreamStepper object level:

http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes

What do you think?

Flávio
--
Flávio Codeço Coelho

Anand Agarwal

unread,
Dec 20, 2009, 4:26:36 AM12/20/09
to py...@googlegroups.com
Hi All

I have a set of 100 random values.

From that i calculate mean & standard deviation.

Now to calculate Confidence Interval I use the below formula

CI = Point Estimate (+/- )  (reliabilty factor * Standard Error)

From this i get range of value for % confidence.

Till now everything is fine.

How do i calculate Confidence Distribution from this?

How do i use pymc apis to calculate confidence distribution?

-Regards
Anand 

Anand Patil

unread,
Dec 20, 2009, 7:36:48 AM12/20/09
to py...@googlegroups.com
Hi John,

On Sat, Dec 19, 2009 at 5:39 AM, John Salvatier <jsalv...@gmail.com> wrote:

> Anand:
> I mean having each stochastic be capable of keeping track of multiple
> positions at once, so perhaps instead of assigning proposals to
> stochastic.value you would assign to stochastic.value[i] and likewise get
> the logp from logp_plus_loglike[i] and reject by .revert(i). Does that make
> sense?

Absolutely. However, the 'each variable has one state' design decision
is pretty entrenched. If the people interested in multiple chains/
multiple processors find that it's a deal-breaker I suppose we could
look at removing it, but my feeling at the moment is it's not going to
be a noticeable problem for concurrency over and above the GIL and
Python's inherent mutability.

A less-disruptive alternative would be to work toward making the
variable objects lighter, simpler and easier to 'copy'. We're headed
down that path in 2.1 by deprecating

M.x.trace()

in favor of

M.trace('x')

and it wouldn't be too hard to delay computation of things like the
Markov blankets & even the children to 'fitting time' and make them
attributes of models rather than variables.

I'm looking forward to having a look at your code, but most likely
won't get to it until the new year.

Cheers,
Anand

Reply all
Reply to author
Forward
0 new messages