I have constructed a hierarchical model (in pymc) with 5 stochastic variables and a single deterministic variable and I want to be able to set a random seed so that the sampler is able to reproduce identical traces.
I've tried various things like setting rseed (for stochastics) and also numpy.random.seed at the beginning of my model but I am unable to reproduce the traces.
Here is what my code looks like:
import pymc
#level 3
a1 = pymc.Beta('a1', alpha=1, beta=1)
a2 = pymc.Gamma('a2', alpha=0.1, beta=0.1)
#level 2
b1 = pymc.Beta('b1', alpha = (a1 * a2) + 1, beta = ((1-a1) * a2) + 1, size = 8)
b2 = pymc.Gamma('b2', alpha=0.1, beta=0.1, size = 8)
#level 1
c = pymc.Beta('c', alpha = data['alpha'], beta = data['beta'])
# Likelihood scoring
d = pymc.Binomial('d', n = data['n'], p = c, value = data['obs'], observed=True)
# The model
model = pymc.Model([a1,a2,b1,b2,c,d])
mcmc = pymc.MCMC(model)
mcmc.sample(iter=50000, burn=10000, thin=20)
I am using Python 2.7 and pymc version 2.3.6