当前位置: 首页>>代码示例>>Python>>正文


Python ChainConsumer.configure_contour方法代码示例

本文整理汇总了Python中chainconsumer.ChainConsumer.configure_contour方法的典型用法代码示例。如果您正苦于以下问题:Python ChainConsumer.configure_contour方法的具体用法?Python ChainConsumer.configure_contour怎么用?Python ChainConsumer.configure_contour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainconsumer.ChainConsumer的用法示例。


在下文中一共展示了ChainConsumer.configure_contour方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_r_s

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
    
    rs_fid = get_r_s([0.273])[0]
    
    daval = (alpha/(1+epsilon)) * da / rs_fid
    
    hrc = hs * rs_fid / (alpha * (1 + epsilon) * (1 + epsilon)) / c
    res = np.vstack((omch2, daval, z/hrc)).T
    return res
    
p1 = [r"$\Omega_c h^2$", r"$\alpha$", r"$\epsilon$"]
p2 = [r"$\Omega_c h^2$", r"$D_A(z)/r_s$", r"$cz/H(z)/r_s $"]


if False:
    consumer = ChainConsumer()
    consumer.configure_contour(sigmas=[0,1.3])
    consumer.add_chain(load_directory("../bWigMpBin/bWigMpBin_z0"), parameters=p1, name="$0.2<z<0.6$")
    consumer.add_chain(load_directory("../bWigMpBin/bWigMpBin_z1"), parameters=p1, name="$0.4<z<0.8$")
    consumer.add_chain(load_directory("../bWigMpBin/bWigMpBin_z2"), parameters=p1, name="$0.6<z<1.0$")
    consumer.plot(figsize="column", filename="wigglez_multipole_alphaepsilon.pdf", truth=[0.113, 1.0, 0.0])
    print(consumer.get_latex_table())

if True:
    c = ChainConsumer()
    c.configure_contour(sigmas=[0,1,2])
    c.add_chain(convert_directory("../bWigMpBin/bWigMpBin_z0", 0.44), parameters=p2, name="$0.2<z<0.6$")
    c.add_chain(convert_directory("../bWigMpBin/bWigMpBin_z1", 0.60), parameters=p2, name="$0.4<z<0.8$")
    c.add_chain(convert_directory("../bWigMpBin/bWigMpBin_z2", 0.73), parameters=p2, name="$0.6<z<1.0$")
    print(c.get_latex_table())
    #c.plot(figsize="column", filename="wigglez_multipole_dah.pdf")
开发者ID:Samreay,项目名称:Wigglez,代码行数:32,代码来源:get_da_hz.py

示例2: EfficiencyModelUncorrected

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
        model_good = EfficiencyModelUncorrected(cs, zs, ts, calibration, zeros, ls, ss, t0s, name="Good%d" % i)
        model_good.fit(sampler, chain_consumer=c)

        model_un = EfficiencyModelUncorrected(cs[mask], zs[mask], ts[mask], calibration,
                                              zeros, ls[mask], ss[mask], t0s[mask], name="Uncorrected%d" % i)
        model_un.fit(sampler, chain_consumer=c)

        biased_chain = c.chains[-1]
        # model_cor.fit(sampler, chain_consumer=c)

        filename = dir_name + "/output/weights.txt"
        if not os.path.exists(filename):
            weights = []
            for i, row in enumerate(biased_chain):
                weights.append(get_weights(row[0], row[1], row[2], row[3], row[4], row[5], threshold))
                print(100.0 * i / biased_chain.shape[0])
            weights = np.array(weights)
            np.savetxt(filename, weights)
        else:
            weights = np.loadtxt(filename)
        weights = (1 / np.power(weights, mask.sum()))
        c.add_chain(biased_chain, name="Importance Sampled", weights=weights)

    c.configure_bar(shade=True)
    c.configure_general(bins=1.0, colours=colours)
    c.configure_contour(sigmas=[0, 0.01, 1, 2], contourf=True, contourf_alpha=0.2)
    c.plot(filename=plot_file, truth=theta, figsize=(7, 7), legend=False, parameters=6)
    for i in range(len(c.chains)):
        c.plot_walks(filename=walk_file % c.names[i], chain=i, truth=theta)
开发者ID:dessn,项目名称:sn-bhm,代码行数:31,代码来源:efficiency_model_8.py

示例3: ChainConsumer

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
    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)
开发者ID:dessn,项目名称:sn-bhm,代码行数:32,代码来源:efficiency_model_7.py

示例4: ChainConsumer

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]

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)
开发者ID:dessn,项目名称:sn-bhm,代码行数:31,代码来源:load.py

示例5: ChainConsumer

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    dir_name = os.path.dirname(__file__)
    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 = 3
    colours = ["#D32F2F", "#1E88E5"] * n
    for i in range(n):
        mean, sigma, observed, cut = get_data(seed=i)

        model_un = EfficiencyModelUncorrected(observed)
        model_cor = EfficiencyModelCorrected(observed, cut)

        pgm_file = os.path.abspath(dir_name + "/output/pgm.png")
        fig = model_cor.get_pgm(pgm_file)

        sampler = EnsembleSampler(num_steps=10000, num_burn=1000, temp_dir=t % i, num_walkers=50)
        model_un.fit(sampler, chain_consumer=c)
        model_cor.fit(sampler, chain_consumer=c)

    c.configure_bar(shade=True)
    c.configure_general(colours=colours)
    c.configure_contour(shade=True, shade_alpha=0.3)
    # c.plot_walks(truth=[mean, sigma], filename=walk_file % "no", chain=0)
    # c.plot_walks(truth=[mean, sigma], filename=walk_file % "cor", chain=1)
    c.plot(filename=plot_file, figsize=(5, 5), truth=[mean, sigma], legend=False)
开发者ID:dessn,项目名称:sn-bhm,代码行数:31,代码来源:efficiency_model_2.py

示例6: BatchMetropolisHastings

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
        theta2 = theta + ls.tolist() + t0s.tolist() + ss.tolist()
        kwargs = {"num_steps": 6000, "num_burn": 250000, "save_interval": 60, "plot_covariance": True, "covariance_adjust": 10000}
        sampler = BatchMetropolisHastings(num_walkers=w, kwargs=kwargs, temp_dir=t % i, num_cores=4)

        model_good = EfficiencyModelUncorrected(cs, zs, ts, types, calibration, zeros, ls, ss, t0s, name="Good%d" % i)
        model_good.fit(sampler, chain_consumer=c)
        print("Good sampler finished")
        mtypes = [t for t, m in zip(types, mask) if m]
        model_un = EfficiencyModelUncorrected(cs[mask], zs[mask], ts[mask], mtypes, calibration,
                                              zeros, ls[mask], ss[mask], t0s[mask], name="Uncorrected%d" % i)
        model_un.fit(sampler, chain_consumer=c)
        print("Uncorrected sampler finished")
        print("Getting weights")
        biased_chain = c.chains[-1]
        filename = dir_name + "/output/weights.txt"
        if not os.path.exists(filename):
            weights = Parallel(n_jobs=4, verbose=100, batch_size=100)(delayed(get_weight_from_row)(row, threshold) for row in biased_chain)
            weights = np.array(weights)
            np.savetxt(filename, weights)
        else:
            weights = np.loadtxt(filename)
        weights = (1 / np.power(weights, mask.sum()))
        c.add_chain(biased_chain, name="Importance Sampled", weights=weights)
        print("Weights finished")

    c.configure_bar(shade=True)
    c.configure_general(bins=1.0, colours=colours)
    c.configure_contour(sigmas=[0, 0.01, 1, 2], shade=True, shade_alpha=0.2)
    c.plot(filename=plot_file, truth=theta, figsize=(10, 10), legend=False, parameters=10)
    for i in range(len(c.chains)):
        c.plot_walks(filename=walk_file % c.names[i], chain=i, truth=theta)
开发者ID:dessn,项目名称:sn-bhm,代码行数:33,代码来源:efficiency_model_9.py

示例7: EnsembleSampler

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
    sampler = EnsembleSampler(temp_dir=temp_dir, num_steps=20000)
    my_model.fit(sampler, chain_consumer=c)
    c.add_chain(np.random.multivariate_normal(res.parameters[1:], res.covariance, size=int(1e7)),
                name="Summary Stats", parameters=["$t_0$", "$x_0$", "$x_1$", "$c$"])

    if False:
        if not os.path.exists(mcmc_chain):
            res2, fitted_model2 = sncosmo.mcmc_lc(lcs[0], model, ['t0', 'x0', 'x1', 'c'], nwalkers=20,
                                                  nburn=500, nsamples=4000)
            mcchain = res2.samples
            np.save(mcmc_chain, mcchain)
        else:
            mcchain = np.load(mcmc_chain)
        c.add_chain(mcchain, name="sncosmo mcmc", parameters=["$t_0$", "$x_0$", "$x_1$", "$c$"])
    print("Plot surfaces")
    c.configure_contour(shade=True, shade_alpha=0.2, sigmas=[0.0, 1.0, 2.0, 3.0])
    c.configure_bar(shade=True)
    c.plot(filename=surface, figsize=(7, 7))
    if False:
        fig = sncosmo.plot_lc(lcs[0], model=fitted_model, errors=res.errors)
        fig.savefig(temp_dir + os.sep + "lc_simple.png", bbox_inches="tight", dpi=300)

    alpha = 0.14
    beta = 3.15

    c2 = ChainConsumer()
    means = []
    stds = []
    print("Add chains")
    for i in range(len(c.chains)):
        chain = c.chains[i]
开发者ID:dessn,项目名称:sn-bhm,代码行数:33,代码来源:simple.py

示例8: get_supernova_data

# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import configure_contour [as 别名]
    for n in ["deep", "shallow"]:
        is_shallow = n == "shallow"
        # bias_file = os.path.dirname(__file__) + "/output/cosmology/bias_%s.npy" % n
        temp_dir2 = os.path.dirname(__file__) + "/output/cosmology2_%s" % n
        if not os.path.exists(temp_dir2):
            os.makedirs(temp_dir2)
        logging.basicConfig(level=logging.DEBUG)

        zs, mu_mcmc, mu_minuit, std_mcmc, std_minuit = get_supernova_data(shallow=is_shallow)

        plot_cosmology(zs, mu_mcmc, mu_minuit, std_mcmc, std_minuit, n)
        fitter_mcmc = SimpleCosmologyFitter("mcmc", zs, mu_mcmc, std_mcmc)
        fitter_minuit = SimpleCosmologyFitter("minuit", zs, mu_minuit, std_minuit)

        sampler = EnsembleSampler(temp_dir=temp_dir2, save_interval=60, num_steps=8000, num_burn=1000)
        c = fitter_mcmc.fit(sampler=sampler)
        cc.add_chain(c.chains[-1], parameters=c.parameters[-1], name="%s MCMC" % n.title())
        c = fitter_minuit.fit(sampler=sampler, chain_consumer=c)
        cc.add_chain(c.chains[-1], parameters=c.parameters[-1], name="%s Max. Like." % n.title())
        c.names = ["MCMC", "Max. Like."]
        c.plot(filename="output/comparison_%s.png" % n, parameters=2, figsize=(5.5, 5.5), truth=[0.3, -1.0])
        c.plot(filename="output/comparison_%s.pdf" % n, parameters=2, figsize=(5.5, 5.5), truth=[0.3, -1.0])
        print(c.get_latex_table())
    print(cc.get_latex_table())
    cc.configure_general(colours=["#1E88E5", "#1E88E5", "#D32F2F", "#D32F2F"],
                         linewidths=[1, 2, 1, 2],
                         linestyles=["-", "--", "-", "--"])
    cc.configure_contour(shade=[True, False, True, False])
    cc.plot(filename="output/comparison.png", parameters=2, figsize=(5.5, 5.5), truth=[0.3, -1.0])
    cc.plot(filename="output/comparison.pdf", parameters=2, figsize=(5.5, 5.5), truth=[0.3, -1.0])
开发者ID:dessn,项目名称:sn-bhm,代码行数:32,代码来源:simple_cosmology_test.py


注:本文中的chainconsumer.ChainConsumer.configure_contour方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。