示例#1
0
print(MPI)
rc('font', **{'family': 'serif', 'serif': ['Times']})
rc('text', usetex=True)
plt.rcParams["font.size"] = 14
plt.rcParams["errorbar.capsize"] = 4

bounds = (-6 * 10**8, 6 * 10**8)
mu = array([1, 2, 3])
cov = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
args = [bounds, mu, cov]

coincidingSeries = {
    'uniform':
    Series(BoxUniformModel(*args), '.', r'$U$'),
    'ppr':
    Series(PowerPosteriorPrior(*args), '+', r'$PPR$'),
    'mix':
    Series(
        StochasticMixtureModel(
            [BoxUniformModel(*args),
             GaussianPeakedPrior(*args)]), 'x', r'mix\((U, G)\)')
}


def generate_offset(series, factor=3):
    result = {}
    for k in series:
        result[k] = Series(OffsetModel(series[k].model, factor * mu),
                           style=series[k].style,
                           label=series[k].label)
    return result
示例#2
0
from gaussian_models.true_gaussian import GaussianPeakedPrior
from gaussian_models.uniform import BoxUniformModel
from gaussian_models.uniform import StrawManResizeablePrior
from general_mixture_model import StochasticMixtureModel

print(MPI)
rc('font', **{'family': 'serif', 'serif': ['Times']})
rc('text', usetex=True)
plt.rcParams['font.size'] = 14

bounds = (-6 * 10**8, 6 * 10**8)
mu = array([1, 2, 3])
cov = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
kwargs = {'noResume': True, 'nLive': 200}

ppr = PowerPosteriorPrior(bounds, mu, cov, file_root='ppr')
tgd = GaussianPeakedPrior(bounds, mu, cov, file_root='tgd')
bun = BoxUniformModel(bounds, mu, cov, file_root='bun')
run = StrawManResizeablePrior(bounds, mu, cov, file_root='run')
mix = StochasticMixtureModel([bun, tgd], file_root='mix')

qr, resizeable = run.nested_sample(**kwargs)
q0, reference = bun.nested_sample(**kwargs)
qp, power = ppr.nested_sample(**kwargs)
qm, samples = mix.nested_sample(**kwargs)

hist_samples = 1000
plt.hist(samples.logZ(hist_samples), label=r'mix\((U, G)\)', alpha=1)
plt.hist(resizeable.logZ(hist_samples),
         label=r'Wrong \( \ln\  {\cal L} \)',
         hatch='\\',
示例#3
0
from mpi4py import MPI
from gaussian_models.power_posterior import PowerPosteriorPrior
from gaussian_models.uniform import BoxUniformModel
from general_mixture_model import StochasticMixtureModel
from offset_model import OffsetModel

print(MPI)
b = 10**3
a = array([-b, -b, -b])
bounds = (a, -a)
mu = array([1, 2, 3])
cov = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
args = [bounds, mu, cov]
kwargs = {'live_points': 120, 'resume': False}

models = {'ppr': PowerPosteriorPrior(*args), 'uniform': BoxUniformModel(*args)}
models['mix'] = StochasticMixtureModel([models['ppr'], BoxUniformModel(*args)])
offsets = {k: OffsetModel(models[k], mu * 2) for k in models}
answers = {
    'model': {k: models[k].nested_sample(**kwargs)
              for k in models},
    'offset': {k: offsets[k].nested_sample(**kwargs)
               for k in offsets}
}
labels = []
alpha = 0.7
fig, ax = answers['offset']['ppr'][1].plot_2d([0, 1],
                                              alpha=alpha,
                                              color='#A000A0')
labels.append('Offset $PPR$')
answers['model']['ppr'][1].plot_2d(ax, alpha=alpha, color='#FF0000')
示例#4
0
plt.rcParams["font.size"] = 14

a = 6 * 10**8
arr_bounds = (array([-a, -a, -a]), array([a, a, a]))
bounds = (-a, a)
mu = array([1, 2, 3])
cov = array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

args = [bounds, mu, cov]
kwargs = {
    'resume': False,
    'live_points': 50,
}

ppr_arr_bounds = PowerPosteriorPrior(arr_bounds,
                                     mu,
                                     cov,
                                     file_root='ppr_arr_bounds')
ppr = PowerPosteriorPrior(*args, file_root='ppr')
tgd = GaussianPeakedPrior(*args, file_root='tgd')
bun = BoxUniformModel(*args, file_root='bun')
run = StrawManResizeablePrior(*args, file_root='run')

mix = StochasticMixtureModel([bun, tgd], file_root='mix')

q0, reference = bun.nested_sample(**kwargs)
qg, gaussian = tgd.nested_sample(**kwargs)
qp, power = ppr.nested_sample(**kwargs)
qpp, power_arr_bounds = ppr_arr_bounds.nested_sample(**kwargs)
qm, samples = mix.nested_sample(**kwargs)

hist_samples = 1000