How can emcee be run deterministically?
See original GitHub issueI want to be able to run emcee multiple times and get exactly the same answer. How can this be accomplished? It does not seem to be sufficient to use random.seed(0), or numpy.random.seed(0), or to capture numpy.random.mtrand.RandomState(0) and assign it to the sampler, or in fact all three.
This is relevant, among others, for making sure that our example notebook doesn’t change when rerun, so that it can be checked in to version control without endless merge conflicts.
A quick test in raw emcee; this passes, mystifyingly, sometimes but not always:
def test_raw_emcee():
r = []
for i in range(2):
random.seed(0)
numpy.random.seed(0)
s = numpy.random.mtrand.RandomState(0)
def log_prob(x, ivar):
return -0.5 * np.sum(ivar * x ** 2)
ndim, nwalkers = 5, 100
ivar = 1. / np.random.rand(ndim)
# r.append(ivar[0])
p0 = np.random.randn(nwalkers, ndim)
#r.append(p0[0, 0])
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_prob, args=[ivar])
sampler.random_state = s
sampler.run_mcmc(p0, 100)
samples = sampler.chain.reshape((-1, ndim))
r.append(samples[0, 0])
assert r[0] == r[1]
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
emcee + PyMC3 | Dan Foreman-Mackey
And now we can run the sampler: import emcee with model: # First we work out the shapes of all of the deterministic...
Read more >Deterministic versus Probabilistic Schedule - Herding Cats
Deterministic schedules - are networks of tasks connected to each other with dependencies that describe the work to be performed, ...
Read more >Parallel Programming Must Be Deterministic by Default
In contrast, we argue for a parallel programming model that is deterministic by default: deterministic behavior is guaranteed unless the ...
Read more >Internally Deterministic Parallel Algorithms Can Be Fast
In this paper, we advocate a particular form of internal de- terminism as providing such a sweet spot for a class of nested-...
Read more >Observed Deterministic - Questions - PyMC Discourse
Hi there :) As the title says, I'm looking for a way to build a model where the observed variable is a combination...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you, that works great! In the event I think we’re going to depend on a recent version of emcee in order to have long double walkers.
@aarchiba would you mind letting me know if #324 indeed addresses your needs?