Пример #1
0
def make_sum_of_masses_plot(log_mass: bool = False):
    """ Plot the posterior distribution for the sum of neutrino masses for two hierarchies and
     a range of upper bounds."""

    data = load_neutrino_constraints()

    for i, hierarchy in enumerate(Hierarchy):
        for j, upper_bound in enumerate(SUM_OF_MASSES_ONE_SIGMA):
            data.sum_of_masses_one_sigma = upper_bound
            data.sum_of_masses_offset = SUM_OF_MASSES_OFFSET[j]
            linestyle = LINESTYLES[j]

            likeligrid = get_posterior(hierarchy, data, n_samples=N_SAMPLES)

            y = likeligrid.mass_posterior[:, 3]
            if log_mass:
                plt.plot(likeligrid.mass_log_bins, y, linestyle=linestyle, color=COLOURS[j])
            else:
                mass = likeligrid.mass_bins
                y /= np.sum(y)
                plt.plot(mass, y, linestyle=linestyle, color=COLOURS[j])

    plt.xlim([0, 0.2])
    plt.xlabel('$\Sigma_\\nu$ [eV]')
    plt.ylabel('p($\Sigma_\\nu$ )')
    print_figure('sum_of_masses_posteriors')
    plt.show()
def make_mass_plot(log_mass: bool = False):

    data = load_neutrino_constraints()
    fig, axes = plt.subplots(nrows=1, ncols=2, sharex=True, sharey=False, figsize=(12, 6))

    for i, hierarchy in enumerate(Hierarchy):
        for j, upper_bound in enumerate(SUM_OF_MASSES_ONE_SIGMA):
            data.sum_of_masses_one_sigma = upper_bound
            data.sum_of_masses_offset = SUM_OF_MASSES_OFFSET[j]
            linestyle = LINESTYLES[j]

            likeligrid = get_posterior(hierarchy, data, n_samples=N_SAMPLES)

            for m in range(3):
                y = likeligrid.mass_posterior[:, m]

                if log_mass:
                    axes[i].plot(likeligrid.mass_log_bins, y, linestyle=linestyle, color=COLOURS[m])
                else:
                    mass = likeligrid.mass_bins
                    y /= np.sum(y)
                    axes[i].plot(mass, y, linestyle=linestyle, color=COLOURS[m])

        axes[i].set_xlabel('m/eV')
        axes[i].set_ylabel('p(m)')
        axes[i].set_xlim([0, 0.09])

    print_figure('mass_posteriors')
    plt.show()
def make_mu_sigma_figures(sum_of_masses_one_sigma=0.0445):
    """ Make plots for the two hierarchies with matching colour scheme. """

    data = load_neutrino_constraints(sum_of_masses_one_sigma)

    posterior_list = []
    for i, hierarchy in enumerate(Hierarchy):
        posterior = get_posterior(hierarchy, data, n_samples=N_SAMPLES)
        posterior_list.append(posterior)

    print_evidence(posterior_list)
    make_plots(posterior_list, data.sum_of_masses_one_sigma)
def calculate_evidence_value(sum_of_masses_one_sigma: float, offset: float,
                             new_splittings: bool):
    """ Get evidences for the two hierarchies. """

    data = load_neutrino_constraints(sum_of_masses_one_sigma,
                                     sum_of_masses_offset=offset,
                                     new_splittings=new_splittings)

    posterior_list = []
    for i, hierarchy in enumerate(Hierarchy):
        posterior = get_posterior(hierarchy, data)
        posterior_list.append(posterior)

    delta_chi2_boost = DELTA_CHI2_BOOSTS[
        1] if new_splittings else DELTA_CHI2_BOOSTS[0]

    print_evidence(posterior_list, delta_chi2_boost)
""" Estimate the model evidence using nested sampling. """

import dynesty as dy
import numpy as np

from inference.sampling import log_pdf
from neutrinos.constraints import load_neutrino_constraints
from neutrinos.hierarchies import Hierarchy

MAX_MASS = 1.0
DATA = load_neutrino_constraints()
HIERARCHY = Hierarchy.Normal


def prior_map(cube):
    """ Our three masses have uniform priors so mapping of the prior quantile is trivial. """

    return cube * MAX_MASS


def evaluate_log_likelihood_of_parameters(param_vector):

    # Order the neutrino masses for ease of likelihood eval
    if not np.all(np.diff(param_vector) >= 0):
        return -1e100  # Faster to exclude unsorted region then compensate Z for missing volume. (factor of 6)

    if HIERARCHY == Hierarchy.Normal:
        msqr1 = param_vector[1]**2 - param_vector[
            0]**2  # M ^ 2 - S ^ 2 ie m2 - m1
        msqr2 = param_vector[2]**2 - param_vector[
            1]**2  # L ^ 2 - M ^ 2 ie m3 - m2
import numpy as np

from inference.ultranest_log import run_ultranest
from neutrinos.constraints import load_neutrino_constraints
from neutrinos.hierarchies import Hierarchy

SUM_OF_MASSES_ONE_SIGMA = np.array([0.089, 0.12, 0.102]) * 0.5
SUM_OF_MASSES_OFFSET = [0, 0, 0]  # Corresponding offsets
MAX_CALLS = 300_000
data = load_neutrino_constraints()

for hierarchy in [Hierarchy.Inverted]:
    for j, upper_bound in enumerate(SUM_OF_MASSES_ONE_SIGMA):
        data.sum_of_masses_one_sigma = upper_bound
        data.sum_of_masses_offset = SUM_OF_MASSES_OFFSET[j]

        run_ultranest(hierarchy, data, MAX_CALLS)