Skip to content

Instantly share code, notes, and snippets.

@jonathansick
Forked from dfm/jsick.py
Created November 29, 2012 23:16
Show Gist options
  • Save jonathansick/4172588 to your computer and use it in GitHub Desktop.
Save jonathansick/4172588 to your computer and use it in GitHub Desktop.
for jsick
#!/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)
@jonathansick
Copy link
Author

lnprobs need to return zero-dim scalars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment