Hi!
I’ve been having trouble getting consistent results with the rng seeded and it only seems to happen when the model has a Gamma random variable defined after a Dirichlet random variable. This also only happens in Python 2.7 though – seeding seems to give me consistent results on Python 3.5. I’ve distilled it to this basic model:
import pymc3 as pm
import numpy as np
seed = 383561
with pm.Model() as model:
p = pm.Dirichlet('w', np.ones(2))
tau = pm.Gamma('tau', 1., 1.)
trace = pm.sample(1, tune=10, chains=1, random_seed=seed)
print(trace['tau'])
I end up getting either [1.06999556] or [2.30071916].
Strangely enough, this only occurs when I define the Dirichlet before the Gamma. If the Gamma is defined before the Dirichlet, then the numbers are deterministic (as far as I can tell!) and consistent with the results when run on Python 3.5 (consistently get [1.06999556])
Also, running pm.sample(1, tune=10, chains=1, random_seed=seed)
itself repeatedly yields a consistent result. It’s only when repeatedly rebuilding the whole model that different results come out.
Setting the random seed (e.g. with np.random.seed(seed)
) before the model doesn’t seem to affect anything.
I’m still really new to PyMC3 and Python in general, but I haven’t been able to find an answer to this just yet. Thanks for reading and considering this issue!