This is a general example to illustrate that most parameters that you can pass to the configuration methods accept lists. """ import numpy as np from numpy.random import normal, multivariate_normal from chainconsumer import ChainConsumer if __name__ == "__main__": np.random.seed(2) cov = normal(size=(2, 2)) + np.identity(2) d1 = multivariate_normal(normal(size=2), 0.5 * (cov + cov.T), size=100000) cov = normal(size=(2, 2)) + np.identity(2) d2 = multivariate_normal(normal(size=2), 0.5 * (cov + cov.T), size=100000) cov = normal(size=(2, 2)) + np.identity(2) d3 = multivariate_normal(normal(size=2), 0.5 * (cov + cov.T), size=100000) c = ChainConsumer() c.add_chain(d1, parameters=["$x$", "$y$"]) c.add_chain(d2) c.add_chain(d3) c.configure_general(linestyles=["-", "--", ":"], linewidths=[1.0, 2.0, 2.5], colours=["#1E88E5", "#D32F2F", "#111111"]) c.configure_contour(shade=[True, True, False], shade_alpha=[0.2, 0.1, 0.0]) c.configure_bar(shade=[True, False, False]) fig = c.plot() fig.set_size_inches(2.5 + fig.get_size_inches()) # Resize fig for doco. You don't need this.
t = os.path.abspath(dir_name + "/output/data_%d") plot_file = os.path.abspath(dir_name + "/output/surfaces.png") walk_file = os.path.abspath(dir_name + "/output/walk_%s.png") c = ChainConsumer() n = 2 colours = ["#4CAF50", "#D32F2F", "#1E88E5"] * n # , "#FFA000"] * n for i in range(n): mean, sigma, cut, observed, mask = get_data(seed=i) model_good = EfficiencyModelUncorrected(observed, name="Good") model_un = EfficiencyModelUncorrected(observed[mask]) model_cor = EfficiencyModelCorrected(observed[mask], cut) sampler = EnsembleSampler(num_steps=25000, num_burn=1000, temp_dir=t % i) model_good.fit(sampler, chain_consumer=c) model_un.fit(sampler, chain_consumer=c) biased_chain = c.chains[-1] # model_cor.fit(sampler, chain_consumer=c) mus = biased_chain[:, 0] sigmas = biased_chain[:, 1] weights = 1 / get_weights(cut, mus, sigmas, mask.sum()) c.add_chain(biased_chain, name="Importance Sampled", weights=weights) c.configure_bar(shade=True) c.configure_general(colours=colours, bins=0.5) c.configure_contour(contourf=True, contourf_alpha=0.2) c.plot(filename=plot_file, figsize=(5, 5), truth=[mean, sigma], legend=False)
Choose custom sigma levels and display point cloud. In this example we display more sigma levels, turn on the point cloud, and disable the parameter summaries on the top of the marginalised distributions. Note that because of the very highly correlated distribution we have, it is useful to increase the number of bins the plots are generated with, to capture the thinness of the correlation. """ import numpy as np from numpy.random import normal, multivariate_normal from chainconsumer import ChainConsumer if __name__ == "__main__": np.random.seed(1) cov = normal(size=(3, 3)) data = multivariate_normal(normal(size=3), 0.5 * (cov + cov.T), size=100000) c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$"]) c.configure_bar(summary=False).configure_general(bins=1.4) c.configure_contour(cloud=True, sigmas=np.linspace(0, 2, 10)) fig = c.plot() fig.set_size_inches( 2.5 + fig.get_size_inches()) # Resize fig for doco. You don't need this.
if __name__ == "__main__": dir_name = os.path.dirname(os.path.abspath(__file__)) output = dir_name + "/output/complete.png" output2 = dir_name + "/output/complete2.png" folders = ["simple", "approx"] # "stan_mc", use_weight = [False, True] c = ChainConsumer() for f, u in zip(folders, use_weight): loc = dir_name + os.sep + f + "/stan_output" t = None try: chain, posterior, t, p, ff, l, w, ow = load_stan_from_folder(loc, merge=True) if u: c.add_chain(chain, posterior=posterior, walkers=l, name=f) c.add_chain(chain, weights=w, posterior=posterior, walkers=l, name="full") else: c.add_chain(chain, posterior=posterior, walkers=l, name=f) except Exception as e: print(e) print("No files found in %s" % loc) print(p) c.configure_general(linestyles=['-', '--', '-'], colours=["#1E88E5", "#555555", "#D32F2F"]) #4CAF50 c.configure_bar(shade=[True, True, True]) c.configure_contour(shade=[True, True, True]) pp = ['$\\Omega_m$', '$\\alpha$', '$\\beta$', '$\\langle M_B \\rangle$', '$\\langle x_1 \\rangle$', '$\\langle c \\rangle$'] #, '$\\sigma_{\\rm m_B}$', '$\\sigma_{x_1}$', '$\\sigma_c$'] c.plot(filename=output, truth=t, parameters=pp) c.plot(filename=output2, truth=t)