Beispiel #1
0
if __name__ == "__main__":
    import sys

    sys.path.append("..")

    pfn, dir_name, file = setup(__file__)

    model = TestModel()
    data = TestDataset()

    sampler = DynestySampler(temp_dir=dir_name, max_iter=None)

    fitter = Fitter(dir_name)
    fitter.add_model_and_dataset(model, data)
    fitter.set_sampler(sampler)
    fitter.set_num_walkers(1)
    fitter.fit(file)

    if fitter.should_plot():

        res, = fitter.load()

        posterior, weight, chain, evidence, model, data, extra = res
        import matplotlib.pyplot as plt

        fig, ax = plt.subplots(nrows=2)
        ax[0].plot(weight)
        ax[1].plot(evidence)
        plt.show()

        from chainconsumer import ChainConsumer
Beispiel #2
0
        BAOExtractor(r_s, extra_ks=(0.095, 0.22)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.23)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.24)),
    ]

    recon = True
    for p in ps:
        n = f"$k = {p.extra_ks[1]:0.2f}\, h / {{\\rm Mpc}}$"
        model = PowerNoda2019(postprocess=p, recon=recon)
        data = PowerSpectrum_SDSS_DR12_Z061_NGC(min_k=0.02, max_k=0.30, postprocess=p, recon=recon)
        fitter.add_model_and_dataset(model, data, name=n)

    sampler = DynestySampler(temp_dir=dir_name)

    fitter.set_sampler(sampler)
    fitter.set_num_walkers(30)
    fitter.fit(file)

    if fitter.should_plot():
        from chainconsumer import ChainConsumer

        c = ChainConsumer()
        for posterior, weight, chain, model, data, extra in fitter.load():
            print(extra["name"])
            c.add_chain(chain, weights=weight, parameters=model.get_labels(), **extra)
        c.configure(shade=True, bins=25, legend_artists=True, cmap="plasma", sigmas=[0, 1, 2])
        extents = None  # {"$\\alpha$": (0.88, 1.18), "$A$": (0, 10), "$b$": (1.5, 1.8), r"$\gamma_{rec}$": (1, 8)}
        params = ["$\\alpha$", "$A$", "$b$"]
        truth = {"$\\Omega_m$": 0.31, "$\\alpha$": 1.0}
        c.analysis.get_latex_table(filename=pfn + "_params.txt")
        c.plotter.plot_summary(filename=[pfn + "_summary.png", pfn + "_summary.pdf"], errorbar=True, truth=truth, extents=extents, parameters=params)
Beispiel #3
0
from barry.models.test import TestModel
from barry.datasets.test import TestDataset
from barry.samplers import EnsembleSampler

if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    model = TestModel()
    data = TestDataset()

    sampler = EnsembleSampler(num_walkers=10,
                              num_steps=1000,
                              num_burn=300,
                              temp_dir=dir_name)

    fitter = Fitter(dir_name)
    fitter.add_model_and_dataset(model, data)
    fitter.set_sampler(sampler)
    fitter.set_num_walkers(2)
    fitter.fit(file)

    if fitter.should_plot():
        from chainconsumer import ChainConsumer

        res, = fitter.load()

        posterior, weight, chain, evidence, model, data, extra = res
        c = ChainConsumer()
        c.add_chain(chain, weights=weight, parameters=model.get_labels())
        c.plotter.plot(filename=pfn + "_contour.png")
Beispiel #4
0
                             marg="full")
    model4 = PowerBeutler2017(recon="iso",
                              isotropic=False,
                              fix_params=["om"],
                              poly_poles=[0, 2, 4],
                              correction=Correction.HARTLAP,
                              marg="full")

    for d in datasets:
        if 4 in d.fit_poles:
            fitter.add_model_and_dataset(model4, d, name=d.name)
        else:
            fitter.add_model_and_dataset(model, d, name=d.name)

    fitter.set_sampler(sampler)
    fitter.set_num_walkers(5)
    fitter.set_num_concurrent(100)
    fitter.fit(file)

    # Everything below is nasty plotting code ###########################################################
    if fitter.should_plot():
        import logging

        logging.info("Creating plots")

        from chainconsumer import ChainConsumer

        counter = 0
        c = ChainConsumer()
        for i, (posterior, weight, chain, evidence, model, data,
                extra) in enumerate(fitter.load()):