Created
September 20, 2016 02:23
-
-
Save astro313/d46043c12ba348e5b07152d91073c103 to your computer and use it in GitHub Desktop.
use emcee to generate ~N ind. samples
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 emcee | |
import numpy as np | |
# TODO: | |
# write something using sampler.sample() instead of predefined niter to ensure we have enough uncorrelated sample after run.. | |
nindependent = 0 | |
nind = 500 | |
niter = 1000 | |
attempts = 10 | |
counter = 0 | |
if counter <= attempt: | |
while nindependent < nind: | |
print("Number of independent samples from last iteration: {:}".format(nindependent)) | |
try: | |
pos0, lnprob0, rstate0 = sampler.run_mcmc(pzero, burnin) | |
except ValueError: | |
pos0, lnprob0, rstate0, _ = sampler.run_mcmc(pos0, niter, rstate=rstate0, lnprob0=lnprob0) | |
try: | |
nindependent = sampler.iterations/numpy.mean(sampler.acor) | |
except RuntimeError: | |
print("acor didn't converge") | |
nindependent = 0 | |
counter +=1 | |
else: | |
print("Need more iterations to reach {:d} independent samples.".format(nindependent)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment