diff --git a/bilby/core/sampler/ptemcee.py b/bilby/core/sampler/ptemcee.py index f314563e5037b16563454e6c2918d4153cfe2955..5aa4ca2c012fa51ff234ca6c570a7e130d17b46e 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))