本文整理汇总了Python中chainconsumer.ChainConsumer.plot_walks方法的典型用法代码示例。如果您正苦于以下问题:Python ChainConsumer.plot_walks方法的具体用法?Python ChainConsumer.plot_walks怎么用?Python ChainConsumer.plot_walks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainconsumer.ChainConsumer
的用法示例。
在下文中一共展示了ChainConsumer.plot_walks方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: debug_plots
# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import plot_walks [as 别名]
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")
示例2: plot_single_cosmology
# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import plot_walks [as 别名]
def plot_single_cosmology(folder, output, i=0, output_walk=None):
print("Plotting cosmology realisation %d" % i)
res = load_stan_from_folder(folder, merge=False)
c = ChainConsumer()
chain, posterior, t, p, f, l, w, ow = res[i]
c.add_chain(chain, weights=w, posterior=posterior, walkers=l, name="%d"%i)
c.plot(filename=output, truth=t, figsize=0.75)
if output_walk is not None:
c.plot_walks(filename=output_walk)
示例3: plot_all
# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import plot_walks [as 别名]
def plot_all(folder, output, output_walk=None):
""" Plot all chains as one """
print("Plotting all as one")
chain, posterior, t, p, f, l, w, ow = load_stan_from_folder(folder, merge=True)
c = ChainConsumer()
c.add_chain(chain, weights=w, posterior=posterior, walkers=l)
c.plot(filename=output, truth=t, figsize=0.75)
if output_walk is not None:
c.plot_walks(filename=output_walk)
示例4: EfficiencyModelUncorrected
# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import plot_walks [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)
示例5: range
# 需要导入模块: from chainconsumer import ChainConsumer [as 别名]
# 或者: from chainconsumer.ChainConsumer import plot_walks [as 别名]
for i in range(n):
mean, std, observed, errors, alpha, actual, uo, oe, am = get_data(seed=i)
theta_good = [mean, std] + actual.tolist()
theta_bias = [mean, std] + am.tolist()
kwargs = {"num_steps": 70000, "num_burn": 20000, "save_interval": 300,
"plot_covariance": True, "unify_latent": True} # , "callback": v.callback
sampler = BatchMetropolisHastings(num_walkers=w, kwargs=kwargs, temp_dir=t % i, num_cores=4)
model_good = EfficiencyModelUncorrected(uo, oe, name="Good%d" % i)
model_good.fit(sampler, chain_consumer=c)
print("Good ", model_good.get_log_posterior(theta_good), c.posteriors[-1][-1])
model_un = EfficiencyModelUncorrected(observed, errors, name="Uncorrected%d" % i)
model_un.fit(sampler, chain_consumer=c)
print("Uncorrected ", model_un.get_log_posterior(theta_bias), c.posteriors[-1][-1])
model_cor = EfficiencyModelCorrected(observed, errors, alpha, name="Corrected%d" % i)
model_cor.fit(sampler, chain_consumer=c)
print("Corrected ", model_cor.get_log_posterior(theta_bias), c.posteriors[-1][-1])
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.3)
c.plot(filename=plot_file, truth=theta_bias, figsize=(5, 5), legend=False)
for i in range(len(c.chains)):
c.plot_walks(filename=walk_file % c.names[i], chain=i, truth=[mean, std])
# c.divide_chain(i, w).configure_general(rainbow=True) \
# .plot(figsize=(5, 5), filename=plot_file.replace(".png", "_%s.png" % c.names[i]),
# truth=theta_bias)