def debug_plots(std): print(std) res = load_stan_from_folder(std, merge=True, cut=False) chain, posterior, t, p, f, l, w, ow = res print(w.mean(), np.std(w), np.mean(np.log(w)), np.std(np.log(w))) # import matplotlib.pyplot as plt # plt.hist(np.log(w), 100) # plt.show() # exit() logw = np.log(w) m = np.mean(logw) s = np.std(logw) print(m, s) logw -= (m + 3 * s) good = logw < 0 logw *= good w = np.exp(logw) sorti = np.argsort(w) for key in chain.keys(): chain[key] = chain[key][sorti] w = w[sorti] ow = ow[sorti] posterior = posterior[sorti] c = ChainConsumer() truth = [0.3, 0.14, 3.1, -19.365, 0, 0, 0.1, 1.0, 0.1, 0, 0, 0, 0, 0, 0] c.add_chain(chain, name="uncorrected", posterior=posterior) c.add_chain(chain, weights=w, name="corrected", posterior=posterior) c.plot(filename="output.png", parameters=9, truth=truth, figsize=1.3) # c = ChainConsumer() # c.add_chain(chain, weights=w, name="corrected") c.plot_walks(chains="corrected", filename="walks.png", truth=truth)
def debug_plots(std): print(std) res = load_stan_from_folder(std, merge=True, cut=False) chain, posterior, t, p, f, l, w, ow = res # print(w.mean()) # import matplotlib.pyplot as plt # plt.hist(np.log(w), 100) # plt.show() # exit() logw = np.log(w) m = np.mean(logw) s = np.std(logw) print(m, s) logw -= (m + 3 * s) good = logw < 0 logw *= good w = np.exp(logw) c = ChainConsumer() c.add_chain(chain, weights=w, name="corrected") c.configure(summary=True) c.plot(figsize=2.0, filename="output.png", parameters=9) c = ChainConsumer() c.add_chain(chain, name="uncorrected") c.add_chain(chain, weights=w, name="corrected") # c.add_chain(chain, name="calib") c.plot(filename="output_comparison.png", parameters=9, figsize=1.3) c.plot_walks(chains=1, filename="walks.png")
def debug_plots(std): print(std) do_weight = True do_walk = True load_second = True res = load_stan_from_folder(std, merge=False, num=0, cut=False) chain, posterior, t, p, f, l, w, ow = res[0] if do_walk: # print("owww ", ow.min(), ow.max()) # print("www ", w.min(), w.max()) chain2 = chain.copy() logw = np.log10(w) a = np.argsort(logw) logw = logw[a] for k in chain: chain2[k] = chain2[k][a] chain2["ow"] = np.log10(ow) chain2["ww"] = logw c = ChainConsumer() c.add_chain(chain2, weights=w, name="calib") c.plot_walks(truth=t, filename="walk_new.png") c = ChainConsumer() if do_weight: c.add_chain(chain, weights=w, name="calib") else: c.add_chain(chain, name="calib") if load_second: res2 = load_stan_from_folder(std + "_calib_data_no_calib_model_and_bias", num=0, merge=False, cut=False) chain, posterior, _, p, f, l, w, ow = res2[0] if do_weight: c.add_chain(chain, weights=w, name="nocalib") else: c.add_chain(chain, name="nocalib") c.plot(filename="output.png", truth=t, figsize=0.75)
om = np.round(chain["Om"][i], decimals=3) key = "%0.3f" % om mus = cosmologies[key](redshifts) mb = chain["mean_MB"][i] + mus - chain["alpha"][i] * chain["mean_x1"][i] + chain["beta"][i] * chain["mean_c"][i] # cc = 1 - norm.cdf(mb, mB_mean, mB_width) + 0.001 cc = 1 - norm.cdf(mb, mB_mean + mean_add, mB_width + sigma_add) w = np.sum(np.log(cc) - chain["mean_c"][i]) weight.append(w) return np.array(weight) if __name__ == "__main__": dir_name = os.path.dirname(__file__) std = dir_name + "/stan_output" res = load_stan_from_folder(std, replace=False, merge=True, cut=False) chain, posterior, t, p, f, l, w, ow = res logw = np.log(w) full_log_correction = logw + ow if False: mean = np.linspace(-2, 2, 17) sigma = np.linspace(-2, 2, 17) print(mean) print(sigma) ms = [] ss = [] ws = [] for m in mean: for s in sigma: