Exemple #1
0
def get_new_cor(chain, mean_add=0, sigma_add=0):

    mB_mean, mB_width = get_approximate_mb_correction()

    data = {
        "mB_mean": mB_mean,
        "mB_width": mB_width,
        "snana_dummy": True,
        "sim": False
    }
    d = get_analysis_data(**data)
    redshifts = d["redshifts"]
    cosmologies = get_cosmology_dictionary()

    weight = []
    for i in range(chain["mean_MB"].size):
        om = np.round(chain["Om"][i], decimals=3)
        key = "%0.3f" % om
        mus = cosmologies[key](redshifts)

        mb = chain["mean_MB"][i] + mus - chain["alpha"][i] * chain["mean_x1"][i] + chain["beta"][i] * chain["mean_c"][i]

        # cc = 1 - norm.cdf(mb, mB_mean, mB_width) + 0.001
        cc = 1 - norm.cdf(mb, mB_mean + mean_add, mB_width + sigma_add)
        w = np.sum(np.log(cc) - chain["mean_c"][i])
        weight.append(w)
    return np.array(weight)
Exemple #2
0
def add_weight_to_chain(chain_dictionary, n_sne):
    file = os.path.abspath(inspect.stack()[0][1])
    dir_name = os.path.dirname(file)
    data_dir = os.path.abspath(dir_name + "/../data")
    pickle_file = data_dir + os.sep + "supernovae_passed.npy"
    supernovae = np.load(pickle_file)
    d = get_cosmology_dictionary()

    weights = calculate_bias(chain_dictionary, supernovae, d)
    existing = chain_dictionary["weight"]

    logw = n_sne * weights - existing
    logw -= logw.min()
    weights = np.exp(-logw)
    chain_dictionary["weight"] = weights
    chain_dictionary["old_weight"] = existing
    return chain_dictionary
Exemple #3
0
def approx_bias():
    file = os.path.abspath(inspect.stack()[0][1])
    dir_name = os.path.dirname(file)
    data_dir = os.path.abspath(dir_name + "/../data")
    pickle_file = data_dir + os.sep + "supernovae_passed.npy"
    supernovae = np.load(pickle_file)
    d = get_cosmology_dictionary()
    data = get_analysis_data()
    n = 1000
    init_vals = [init_fn(data=data) for i in range(n)]
    keys = list(init_vals[0].keys())
    chain_dictionary = {}
    for key in keys:
        chain_dictionary[key] = np.array([elem[key] for elem in init_vals])
    weights, mean_abs = calculate_bias(chain_dictionary, supernovae, d, return_mbs=True)
    import matplotlib.pyplot as plt
    plt.scatter(mean_abs, weights)
    plt.show()
Exemple #4
0
def add_weight_to_chain(chain_dictionary, n_sne):
    print(n_sne)
    file = os.path.abspath(inspect.stack()[0][1])
    dir_name = os.path.dirname(file)
    data_dir = os.path.abspath(dir_name + "/../data")

    dump_file = os.path.abspath(data_dir + "/SHINTON_SPEC_SALT2.npy")
    supernovae = np.load(dump_file)

    d = get_cosmology_dictionary()
    # import matplotlib.pyplot as plt
    # plt.hist(supernovae['S2mb'], 30)
    # plt.show()
    # exit()
    weights = calculate_bias(chain_dictionary, supernovae, d)
    existing = chain_dictionary["weight"]
    logw = n_sne * weights - existing
    logw -= logw.min()
    weights = np.exp(-logw)
    chain_dictionary["weight"] = weights
    chain_dictionary["old_weight"] = existing
    return chain_dictionary