Skip to content

Commit

Permalink
fixing #198
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Oct 15, 2016
1 parent 3a208ce commit fa32b13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions emcee/mh.py
Expand Up @@ -115,10 +115,7 @@ def sample(self, p0, lnprob=None, randomstate=None, thin=1,
diff = newlnprob - lnprob

# M-H acceptance ratio
if diff < 0:
diff = np.exp(diff) - self._random.rand()

if diff > 0:
if diff >= 0.0 or diff >= np.log(self._random.rand()):
p = q
lnprob = newlnprob
self.naccepted += 1
Expand Down
7 changes: 7 additions & 0 deletions emcee/tests.py
Expand Up @@ -166,6 +166,13 @@ def test_mh(self):
args=[self.icov])
self.check_sampler(N=self.N * self.nwalkers, p0=self.p0[0])

def test_mh_unif(self):
f = lambda x: 0.0 if np.all((0.0 <= x) & (x <= 1.0)) else -np.inf
self.sampler = MHSampler(self.cov, self.ndim, f)
self.sampler.run_mcmc(np.random.rand(self.ndim), 100)
chain = self.sampler.chain
assert np.any(np.abs(np.diff(chain, axis=0)) > 0.0)

def test_ensemble(self):
self.sampler = EnsembleSampler(self.nwalkers, self.ndim,
lnprob_gaussian, args=[self.icov])
Expand Down

0 comments on commit fa32b13

Please sign in to comment.