Skip to content
Snippets Groups Projects
Commit 05f72fb1 authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Fix bug in nsamples estimate

parent a23562aa
No related branches found
No related tags found
1 merge request!842Add a mean-log-likelihood method to improve the ACT estimation
Pipeline #161420 passed
......@@ -667,6 +667,9 @@ def check_iteration(
"""
ci = convergence_inputs
# Note: nsteps is the number of steps in the samples while iterations is
# the current iteration number. So iteration > nsteps by the number of
# od discards
nwalkers, nsteps, ndim = samples.shape
tau_array = calculate_tau_array(samples, search_parameter_keys, ci)
......@@ -699,14 +702,15 @@ def check_iteration(
nburn = int(ci.burn_in_nact * tau_int)
thin = int(np.max([1, ci.thin_by_nact * tau_int]))
samples_per_check = nwalkers / thin
nsamples_effective = int(nwalkers * (iteration - nburn) / thin)
nsamples_effective = int(nwalkers * (nsteps - nburn) / thin)
print(nwalkers, iteration, nsteps, nburn, thin, nsamples_effective)
# Calculate convergence boolean
converged = Q < ci.Q_tol and ci.nsamples < nsamples_effective
logger.debug("Convergence: Q<Q_tol={}, nsamples<nsamples_effective={}"
.format(Q < ci.Q_tol, ci.nsamples < nsamples_effective))
GRAD_WINDOW_LENGTH = 11
GRAD_WINDOW_LENGTH = nwalkers + 1
nsteps_to_check = ci.autocorr_tau * np.max([2 * GRAD_WINDOW_LENGTH, tau_int])
lower_tau_index = np.max([0, len(tau_list) - nsteps_to_check])
check_taus = np.array(tau_list[lower_tau_index :])
......@@ -990,11 +994,15 @@ def plot_tau(
def plot_mean_log_likelihood(mean_log_likelihood, outdir, label):
ntemps, nsteps = mean_log_likelihood.shape
max_logl = np.max(mean_log_likelihood)
ymax = max_logl + 0.01 * np.abs(max_logl)
ymin = max_logl - 0.1 * np.abs(max_logl)
fig, ax = plt.subplots()
idxs = np.arange(nsteps)
ax.plot(idxs, mean_log_likelihood.T)
ax.set(xlabel="Iteration", ylabel=r"$\langle\log\mathcal{L}\rangle$")
ax.set(xlabel="Iteration", ylabel=r"$\langle\log\mathcal{L}\rangle$",
ylim=(ymin, ymax))
fig.tight_layout()
fig.savefig("{}/{}_checkpoint_meanloglike.png".format(outdir, label))
plt.close(fig)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment