Slide 59
Slide 59 text
MCMC sampling with emcee
# x, y, yerr are numpy arrays of the same shape
import emcee
import numpy as np
def model(theta, x):
a, b, c = theta
return a / (1 + np.exp(-b * (x - c)))
def log_prob(theta):
log_prior = 0.0
r = (y - model(theta, x)) / yerr
return -0.5 * np.sum(r*r) + log_prior
ndim, nwalkers = 3, 32
p0 = np.array([1.0, 10.0, 1.5])
p0 = p0 + 0.01*np.random.randn(nwalkers, ndim)
sampler = emcee.EnsembleSampler(nwalkers, ndim, log_prob)
sampler.run_mcmc(p0, 1000)