From 49ce764ccb047af2ee924dd6d0cab0919147b093 Mon Sep 17 00:00:00 2001
From: Gregory Ashton <gregory.ashton@ligo.org>
Date: Wed, 25 Mar 2020 17:44:57 +1100
Subject: [PATCH] Improve tau plot

---
 bilby/core/sampler/ptemcee.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/bilby/core/sampler/ptemcee.py b/bilby/core/sampler/ptemcee.py
index f314563e5..5aa4ca2c0 100644
--- a/bilby/core/sampler/ptemcee.py
+++ b/bilby/core/sampler/ptemcee.py
@@ -232,7 +232,7 @@ class Ptemcee(MCMCSampler):
                 tau_usable,
             )
 
-            if converged:
+            if converged and tau_usable:
                 logger.info("Finished sampling")
                 break
 
@@ -301,7 +301,8 @@ class Ptemcee(MCMCSampler):
             )
 
             # Generate the tau plot diagnostic
-            plot_tau(self.tau_list_n, self.tau_list, self.outdir, self.label)
+            plot_tau(self.tau_list_n, self.tau_list, self.outdir, self.label,
+                     self.autocorr_tol)
 
 
 def print_progress(
@@ -419,9 +420,13 @@ def plot_walkers(walkers, nburn, parameter_labels, outdir, label):
     plt.close(fig)
 
 
-def plot_tau(tau_list_n, tau_list, outdir, label):
+def plot_tau(tau_list_n, tau_list, outdir, label, autocorr_tol):
     fig, ax = plt.subplots()
     ax.plot(tau_list_n, tau_list, "-")
+    check_tau_idx = -int(tau_list[-1] * autocorr_tol)
+    check_taus = tau_list[check_tau_idx:]
+    check_taus_n = tau_list_n[check_tau_idx:]
+    ax.plot(check_taus_n, check_taus, "--")
     ax.set_xlabel("Iteration")
     ax.set_ylabel(r"$\langle \tau \rangle$")
     fig.savefig("{}/{}_tau.png".format(outdir, label))
-- 
GitLab