Пример #1
0
    c0 = np.random.normal(true_mu_c0, true_sigma_c0)
    c1 = np.random.uniform(-1, 1)
    injection_parameters = dict(c0=c0, c1=c1)

    data = model(x, **injection_parameters) + np.random.normal(0, sigma, N)
    line = ax1.plot(x, data, "-x", label=labels[i])

    likelihood = GaussianLikelihood(x, data, model, sigma)
    priors = dict(c0=Uniform(-10, 10, "c0"), c1=Uniform(-10, 10, "c1"))

    result = run_sampler(
        likelihood=likelihood,
        priors=priors,
        sampler="nestle",
        nlive=1000,
        outdir=outdir,
        verbose=False,
        label="individual_{}".format(i),
        save=False,
        injection_parameters=injection_parameters,
    )
    ax2.hist(
        result.posterior.c0,
        color=line[0].get_color(),
        density=True,
        alpha=0.5,
        label=labels[i],
    )
    results.append(result)

ax1.set_xlabel("x")
Пример #2
0
n_dim = 3
label = "dirichlet_"
priors = DirichletPriorDict(n_dim=n_dim, label=label)

injection_parameters = dict(
    dirichlet_0=1 / 3,
    dirichlet_1=1 / 3,
    dirichlet_2=1 / 3,
)
data = [injection_parameters[label + str(ii)] * 1000 for ii in range(n_dim)]

likelihood = Multinomial(data=data, n_dimensions=n_dim, label=label)

result = run_sampler(likelihood=likelihood,
                     priors=priors,
                     nlive=100,
                     walks=10,
                     label="multinomial",
                     injection_parameters=injection_parameters)

result.posterior[label + str(n_dim - 1)] = 1 - np.sum(
    [result.posterior[key] for key in priors], axis=0)
result.plot_corner(parameters=injection_parameters)

samples = priors.sample(10000)
samples[label +
        str(n_dim - 1)] = 1 - np.sum([samples[key] for key in samples], axis=0)
result.posterior = pd.DataFrame(samples)
result.plot_corner(parameters=[key for key in samples],
                   filename="outdir/dirichlet_prior_corner.png")
Пример #3
0
for i in range(Nevents):
    c0 = np.random.normal(true_mu_c0, true_sigma_c0)
    c1 = np.random.uniform(-1, 1)
    injection_parameters = dict(c0=c0, c1=c1)

    data = model(x, **injection_parameters) + np.random.normal(0, sigma, N)
    line = ax1.plot(x, data, '-x', label=labels[i])

    likelihood = GaussianLikelihood(x, data, model, sigma)
    priors = dict(c0=Uniform(-10, 10, 'c0'), c1=Uniform(-10, 10, 'c1'))

    result = run_sampler(likelihood=likelihood,
                         priors=priors,
                         sampler='nestle',
                         nlive=1000,
                         outdir=outdir,
                         verbose=False,
                         label='individual_{}'.format(i),
                         save=False,
                         injection_parameters=injection_parameters)
    ax2.hist(result.posterior.c0,
             color=line[0].get_color(),
             normed=True,
             alpha=0.5,
             label=labels[i])
    results.append(result)

ax1.set_xlabel('x')
ax1.set_ylabel('y(x)')
ax1.legend()
fig1.savefig('outdir/hyper_parameter_data.png')