Example #1
0
def plot_summaries(trace, m, plotdir):
    ar_data = az.from_pymc3(trace=trace)
    # view summary
    df = az.summary(ar_data, var_names=m.all_vars)
    print(df)

    # write summary to disk
    f = open(plotdir / "summary.txt", "w")
    df.to_string(f)
    f.close()

    with az.rc_context(rc={"plot.max_subplots": 80}):
        stem = str(plotdir / "autocorr{:}.png")
        efficient_autocorr(ar_data, var_names=m.all_vars, figstem=stem)

        # make a traceplot
        stem = str(plotdir / "trace{:}.png")
        efficient_trace(ar_data, var_names=m.all_vars, figstem=stem)
    'CB': r'C$_\beta$',
    'C': 'C',
    'N': 'N',
}
state_to_name = {
    'like_o' : 'Open',
    'like_fo' : 'Fully Open',
    'like_c' : 'Closed',
}
for nucleus in nuclei_to_name.keys():
    for method in method_to_name.keys():
        for state in state_to_name.keys():
            print(nucleus,method,state)
            model_path = models_dir + f"{model_name}_{method}_{nucleus}.nc"
            my_model = az.from_netcdf(model_path)
            resids = my_model.posterior.resid
            n = resids.shape[0]
            fig, ax = plt.subplots(n // 6 + 1, 6, figsize=(13,15))
            for i in range(6 - n % 6):
                fig.delaxes(ax[-1,-i-1])
            ax = fig.axes
            with az.rc_context(rc={'plot.max_subplots': None}):
                az.plot_ppc(my_model, flatten=['step'], var_names = [state], random_seed=RANDOM_SEED, ax=ax)
            for r, a in zip(resids.to_index(), ax):
                a.set_title(f'{r}', size=12)
                a.set_xlabel('')
                a.legend_.set_visible(False)
            fig.suptitle(f'Posterior Predictive Check {method_to_name[method]} {nuclei_to_name[nucleus]} {state_to_name[state]} (ppm)', y =1.0, size =20)
            fig.tight_layout()
            plt.savefig(f'{reports_dir}for_print/ppc_{state_to_name[state]}_{nucleus}_{method}.png')
Example #3
0
    os.makedirs(plotdir)

trace = pm.load_trace(directory="chains", model=m.model)

if diagnostics:
    ar_data = az.from_pymc3(trace=trace)

    # view summary
    df = az.summary(ar_data, var_names=m.all_vars)

    # write summary to disk
    f = open(plotdir / "summary.txt", "w")
    df.to_string(f)
    f.close()

    with az.rc_context(rc={"plot.max_subplots": 80}):
        stem = str(plotdir / "autocorr{:}.png")
        efficient_autocorr(ar_data, var_names=m.all_vars, figstem=stem)

        # make a traceplot
        stem = str(plotdir / "trace{:}.png")
        efficient_trace(ar_data, var_names=m.all_vars, figstem=stem)

    # make a nice corner plot of the variables we care about
    samples = pm.trace_to_dataframe(
        trace,
        varnames=["Mtot", "a", "P", "e", "incl", "omega", "Omega", "phi"],
    )
    samples["P"] /= yr
    samples["incl"] /= deg
    samples["omega"] /= deg