turing
turing

Reputation: 607

plotting figure from saved traces in pymc

I need to run MCMC different times with different parameters to check the convergence. So I decided to save the traces so that when I need to know (for comaprison purposes) what was the result of

pymc.MCMC (iter = 10000, burn = 1000, thin = 10)

I don't need to rerun it. (It takes a lot of time (I have to do the same for many different values of parameters)).

I found out a solution

m = MCMC([tau, rv], db='pickle', dbname='10000iter1000burn.pickle')
m.sample(iter = 10000, burn = 5000, thin = 10)
m.db.close()

So the trace is saved now in a database named 10000iter1000burn.pickle

Now, to load teh trace, I do the following

db = pymc.database.pickle.load('10000iter5000burn.pickle')

and when I perform print db.trace('tau')[:] I get the same output, but when I want tp plot the figure or get other information, it fails

plot(db)  #error

plot() takes at least 2 arguments (1 given) but when I do plot(m) (initial case when I have run the sampler again), it works fine.

Similarly db.tau.summary() gives error 'Trace' object has no attribute 'summary' It works fine when I do m.tau.summary()

Same is true for db.logp

I am a novice in this field. Kindly correct me if there is any mistake somewhere in the syntax. If there is some other way that I can replot the figure and get log-probability of the model without running mcmc again, I will be happy to know.

Upvotes: 4

Views: 1488

Answers (1)

Chris Fonnesbeck
Chris Fonnesbeck

Reputation: 4203

You can't just pass a database backend to the plot function. You can either pass (1) the original node/stochastic (2) a trace object (3) a dictionary of pymc nodes/stochastics or (4) raw output.

Upvotes: 4

Related Questions