本文整理汇总了Python中chainconsumer.ChainConsumer类的典型用法代码示例。如果您正苦于以下问题:Python ChainConsumer类的具体用法?Python ChainConsumer怎么用?Python ChainConsumer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChainConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bic_fail_no_posterior
def test_bic_fail_no_posterior():
d = norm.rvs(size=1000)
c = ChainConsumer()
c.add_chain(d, num_eff_data_points=1000, num_free_params=1)
bics = c.comparison.bic()
assert len(bics) == 1
assert bics[0] is None
示例2: plot_all_no_weight
def plot_all_no_weight(folder, output):
""" Plot all chains as one, with and without weights applied """
print("Plotting all as one, with old and new weights")
chain, posterior, t, p, f, l, w, ow = load_stan_from_folder(folder, merge=True)
c = ChainConsumer()
c.add_chain(chain, posterior=posterior, walkers=l)
c.plot(filename=output, truth=t, figsize=0.75)
示例3: test_aic_0
def test_aic_0():
d = norm.rvs(size=1000)
p = norm.logpdf(d)
c = ChainConsumer()
c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=1000)
aics = c.comparison.aic()
assert len(aics) == 1
assert aics[0] == 0
示例4: test_bic_fail_no_num_params
def test_bic_fail_no_num_params():
d = norm.rvs(size=1000)
p = norm.logpdf(d)
c = ChainConsumer()
c.add_chain(d, posterior=p, num_eff_data_points=1000)
bics = c.comparison.bic()
assert len(bics) == 1
assert bics[0] is None
示例5: plot_separate
def plot_separate(folder, output):
""" Plot separate cosmologies """
print("Plotting all cosmologies separately")
res = load_stan_from_folder(folder, merge=False)
c = ChainConsumer()
for i, (chain, posterior, t, p, f, l, w, ow) in enumerate(res):
c.add_chain(chain, weights=w, posterior=posterior, walkers=l, name="%d"%i)
c.plot(filename=output, truth=t, figsize=0.75)
示例6: test_get_chain_via_object
def test_get_chain_via_object(self):
c = ChainConsumer()
c.add_chain(self.data, name="A")
c.add_chain(self.data, name="B")
assert c._get_chain(c.chains[0])[0] == 0
assert c._get_chain(c.chains[1])[0] == 1
assert len(c._get_chain(c.chains[0])) == 1
assert len(c._get_chain(c.chains[1])) == 1
示例7: test_dic_0
def test_dic_0():
d = norm.rvs(size=1000)
p = norm.logpdf(d)
c = ChainConsumer()
c.add_chain(d, posterior=p)
dics = c.comparison.dic()
assert len(dics) == 1
assert dics[0] == 0
示例8: test_shade_alpha_algorithm2
def test_shade_alpha_algorithm2(self):
consumer = ChainConsumer()
consumer.add_chain(self.data)
consumer.add_chain(self.data)
consumer.configure()
alpha0 = consumer.chains[0].config["shade_alpha"]
alpha1 = consumer.chains[0].config["shade_alpha"]
assert alpha0 == 1.0 / 2.0
assert alpha1 == 1.0 / 2.0
示例9: is_unconstrained
def is_unconstrained(chain, param):
c = ChainConsumer()
c.add_chain(chain, parameters=param)
constraints = c.get_summary()[0]
for key in constraints:
val = constraints[key]
if val[0] is None or val[2] is None:
return True
return False
示例10: debug_plots
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)
示例11: test_bic_data_dependence2
def test_bic_data_dependence2():
d = norm.rvs(size=1000)
p = norm.logpdf(d)
c = ChainConsumer()
c.add_chain(d, posterior=p, num_free_params=2, num_eff_data_points=1000)
c.add_chain(d, posterior=p, num_free_params=3, num_eff_data_points=500)
bics = c.comparison.bic()
assert len(bics) == 2
assert bics[0] == 0
expected = 3 * np.log(500) - 2 * np.log(1000)
assert np.isclose(bics[1], expected, atol=1e-3)
示例12: _get_consumer
def _get_consumer(self, results, chain_consumer=None, include_latent=False):
if chain_consumer is None:
from chainconsumer import ChainConsumer
chain_consumer = ChainConsumer()
n = len(self._theta_labels) if include_latent else self._num_actual
chain_consumer.add_chain(results["chain"],
weights=results.get("weights"),
posterior=results.get("posterior"),
parameters=self._theta_labels[:n],
name=self.model_name)
return chain_consumer
示例13: get_instance
def get_instance():
np.random.seed(0)
c = ChainConsumer()
parameters = ["$x$", r"$\Omega_\epsilon$", "$r^2(x_0)$"]
for name in ["Ref. model", "Test A", "Test B", "Test C"]:
# Add some random data
mean = np.random.normal(loc=0, scale=3, size=3)
sigma = np.random.uniform(low=1, high=3, size=3)
data = np.random.multivariate_normal(mean=mean, cov=np.diag(sigma**2), size=100000)
c.add_chain(data, parameters=parameters, name=name)
return c
示例14: test_aic_data_dependence
def test_aic_data_dependence():
d = norm.rvs(size=1000)
p = norm.logpdf(d)
c = ChainConsumer()
c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=1000)
c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=500)
aics = c.comparison.aic()
assert len(aics) == 2
assert aics[0] == 0
expected = (2.0 * 1 * 2 / (500 - 1 - 1)) - (2.0 * 1 * 2 / (1000 - 1 - 1))
assert np.isclose(aics[1], expected, atol=1e-3)
示例15: plot_results
def plot_results(chain, param, chainf, chainf2, chainf3, paramf, t0, x0, x1, c, temp_dir, seed, interped):
cc = ChainConsumer()
cc.add_chain(chain, parameters=param, name="Posterior")
cc.add_chain(chainf, parameters=paramf, name="Minuit")
cc.add_chain(chainf2, parameters=paramf, name="Emcee")
cc.add_chain(chainf3, parameters=paramf, name="Nestle")
truth = {"$t_0$": t0, "$x_0$": x0, "$x_1$": x1, "$c$": c, r"$\mu$": get_mu(interped, x0, x1, c)}
cc.plot(filename=temp_dir + "/surfaces_%d.png" % seed, truth=truth)