Created
October 31, 2012 03:49
-
-
Save dfm/3984683 to your computer and use it in GitHub Desktop.
Saving random state between steps in emcee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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