Skip to content

Instantly share code, notes, and snippets.

@dfm
Created October 31, 2012 03:49
Show Gist options
  • Save dfm/3984683 to your computer and use it in GitHub Desktop.
Save dfm/3984683 to your computer and use it in GitHub Desktop.
Saving random state between steps in emcee
import cPickle as pickle
for pos, lnprob, rstate in sampler.sample(pos0, iterations=500, storechain=False):
# First save the positions as you usually would. Following: http://dfm.io/RrU8w8
# Save the current state.
with open("state.pkl", "w") as f:
pickle.dump([pos, lnprob, rstate], f, -1)
#
# --------------------------------------------------------
#
# Reload the most recently saved state...
with open("state.pkl") as f:
pos, lnprob, rstate = pickle.load(f)
# Restart the chain from there...
sampler.run_mcmc(pos, 1000, lnprob0=lnprob, rstate0=rstate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment