From 9c15e3e99867f0e00a91090977fa13d82136df68 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 21 Aug 2019 13:47:01 +1000
Subject: [PATCH] Resolve !398 ensures the emcee chains are down selcted
 correctly

---
 bilby/core/sampler/emcee.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/bilby/core/sampler/emcee.py b/bilby/core/sampler/emcee.py
index 38878c387..a03dda0b0 100644
--- a/bilby/core/sampler/emcee.py
+++ b/bilby/core/sampler/emcee.py
@@ -354,23 +354,23 @@ class Emcee(MCMCSampler):
         self.checkpoint()
 
         self.result.sampler_output = np.nan
-        blobs_flat = np.array(self.sampler.blobs).reshape((-1, 2))
-        log_likelihoods, log_priors = blobs_flat.T
-        chain = self.sampler.chain.reshape((-1, self.ndim))
-        log_ls = log_likelihoods
-        log_ps = log_priors
-        self.calculate_autocorrelation(chain)
+
+        self.calculate_autocorrelation(
+            self.sampler.chain.reshape((-1, self.ndim)))
         self.print_nburn_logging_info()
         self.calc_likelihood_count()
         self.result.nburn = self.nburn
-        n_samples = self.nwalkers * self.nburn
         if self.result.nburn > self.nsteps:
             raise SamplerError(
                 "The run has finished, but the chain is not burned in: "
                 "`nburn < nsteps`. Try increasing the number of steps.")
-        self.result.samples = chain[n_samples:, :]
-        self.result.log_likelihood_evaluations = log_ls[n_samples:]
-        self.result.log_prior_evaluations = log_ps[n_samples:]
+        self.result.samples = self.sampler.chain[:, self.nburn:, :].reshape(
+            (-1, self.ndim))
+        blobs = np.array(self.sampler.blobs)
+        blobs_trimmed = blobs[self.nburn:, :, :].reshape((-1, 2))
+        log_likelihoods, log_priors = blobs_trimmed.T
+        self.result.log_likelihood_evaluations = log_likelihoods
+        self.result.log_prior_evaluations = log_priors
         self.result.walkers = self.sampler.chain
         self.result.log_evidence = np.nan
         self.result.log_evidence_err = np.nan
-- 
GitLab