changing the step method with "locals" function return

32 views
Skip to first unread message

Martin De Kauwe

unread,
Feb 11, 2014, 12:57:21 AM2/11/14
to py...@googlegroups.com
Hi,

I have set my pymc model as a function similar to the example in the manual, e.g. 

def make_model(x):
    a = pymc.Exponential('a', beta=x, value=0.5)

    @pymc.deterministic
    def b(a=a):
        return 100-a

    return locals()

import pymc
MC = pymc.MCMC(make_model(x))
MC.sample(1000)

But I am unclear how one would go about changing the step method as I don't have access to the attributes? For example, to use the AdaptiveMetropolis step method, how would I set this up so that it can access its attributes?

thanks.


Aravind Alwan

unread,
Feb 11, 2014, 3:25:05 PM2/11/14
to py...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "PyMC" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymc+uns...@googlegroups.com.
To post to this group, send email to py...@googlegroups.com.
Visit this group at http://groups.google.com/group/pymc.
For more options, visit https://groups.google.com/groups/opt_out.

Martin De Kauwe

unread,
Feb 12, 2014, 6:34:07 AM2/12/14
to py...@googlegroups.com
I did see that, but it really doesn't help me to be honest.

In that example it is explicitly setting the variables [x,y,z], but I'm unclear how to do this as the way I have set these variables up they are inside a function and returned with the locals() statement. My question was how does one interface with the return using locals? I guess perhaps your point is my example was a poor one as I am not setting up stochastics. 

Aravind Alwan

unread,
Feb 12, 2014, 7:40:40 AM2/12/14
to py...@googlegroups.com
The locals() command merely returns a dictionary of local variables,
so you could just do the following:

m = make_model(x)
MC = pymc.MCMC(m)
MC.use_step_method(pymc.AdaptiveMetropolis, [ m['x'], m['y'], m['z']
], scales={'x':1, 'y':2, 'z':.5}, delay=10000)

I think that should work.

Martin De Kauwe

unread,
Feb 12, 2014, 10:14:46 PM2/12/14
to py...@googlegroups.com
I see, I hadn't quite processed it was a dictionary, thanks.
Reply all
Reply to author
Forward
0 new messages