-
-
Save jonathansick/4172588 to your computer and use it in GitHub Desktop.
for jsick
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
#!/usr/bin/env python | |
import numpy as np | |
import emcee | |
class ProbWrapper(object): | |
def __init__(self, f): | |
super(ProbWrapper, self).__init__() | |
self._f = f | |
def __call__(self, x, *args): | |
return self._f(x, *args)[0] | |
def lnprob(x, ivar): | |
return -0.5 * np.array([np.sum(ivar * x ** 2), ]) | |
ndim, nwalkers = 10, 100 | |
ivar = 1. / np.random.rand(ndim) | |
p0 = [np.random.rand(ndim) for i in range(nwalkers)] | |
lnprobwr = ProbWrapper(lnprob) | |
sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprobwr, args=[ivar]) | |
sampler.run_mcmc(p0, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lnprobs need to return zero-dim scalars.