def get_coordinate_samples():
    return supercubos.LatinSampler(rng=np.random.default_rng(
        seed=SAMPLE_SEED)).get_sym_sample(
            PARAM_MINS,
            PARAM_MAXES,
            NUM_EMULATION_SAMPLES,
        )
def get_errorcheck_coords():
    return supercubos.LatinSampler(rng=np.random.default_rng(
        seed=SAMPLE_SEED)).get_sym_sample(
            PARAM_MINS,
            PARAM_MAXES,
            NUM_ERRORCHECK_SAMPLES,
        )
def do_estimation(sample_size, num_pcs):
    rng = np.random.default_rng(seed=SEED)
    lh = supercubos.LatinSampler(rng=rng).get_lh_sample(
        PARAM_MINS, PARAM_MAXES, sample_size)

    density_model = get_density_model()
    shear_model = get_shear_model(density_model.excess_surface_density)

    def wrapped_esd_func(params):
        a_sz = params[0:1]
        con = params[1:2]
        alpha = params[2:3]
        beta = params[3:4]
        gamma = np.array([GAMMA])
        return shear_model.stacked_excess_surface_density(
            RADII, a_sz, con, alpha, beta, gamma).squeeze()

    esds = _pool_map(wrapped_esd_func, lh)

    data = RADII[:, None] * esds
    emulator = maszcal.emulate.PcaEmulator.create_from_data(
        coords=lh,
        data=data,
        interpolator_class=maszcal.interpolate.GaussianProcessInterpolator,
        interpolator_kwargs={'kernel': Matern()},
        num_components=num_pcs,
    )

    return get_emulator_errors(PARAM_MINS, PARAM_MAXES, emulator,
                               wrapped_esd_func)
Example #4
0
def do_estimation(sample_size, num_pcs):
    rng = np.random.default_rng(seed=SEED)
    lh = supercubos.LatinSampler(rng=rng).get_lh_sample(PARAM_MINS, PARAM_MAXES, sample_size)

    density_model = get_density_model()
    two_halo_conv = get_two_halo_convergence()
    two_halo_emulator = get_2h_emulator(two_halo_conv)
    corrected_lensing_func = get_corrected_lensing_func(density_model, two_halo_emulator)
    hmf_interp = get_hmf_interp()
    conv_model = get_convergence_model(hmf_interp, corrected_lensing_func)

    def wrapped_conv_func(params):
        a_sz = params[0:1]
        a_2h = params[1:2]
        con = params[2:3]
        alpha = params[3:4]
        beta = params[4:5]
        gamma = np.array([GAMMA])
        conv = conv_model.stacked_convergence(THETAS, a_sz, a_2h, con, alpha, beta, gamma).squeeze()
        return THETAS * conv

    convs = _pool_map(wrapped_conv_func, lh)

    emulator = maszcal.emulate.PcaEmulator.create_from_data(
        coords=lh,
        data=convs,
        interpolator_class=maszcal.interpolate.GaussianProcessInterpolator,
        interpolator_kwargs={'kernel': Matern()},
        num_components=num_pcs,
    )

    return get_emulator_errors(PARAM_MINS, PARAM_MAXES, emulator, wrapped_conv_func)
Example #5
0
 def _get_z_mu_samples(z_lims, mu_lims, num_emulator_samples):
     param_mins = np.stack((z_lims, mu_lims))[:, 0]
     param_maxes = np.stack((z_lims, mu_lims))[:, 1]
     return supercubos.LatinSampler().get_lh_sample(
         param_mins=param_mins,
         param_maxes=param_maxes,
         num_samples=num_emulator_samples,
     )
def get_2nd_order_emulator_errors(PARAM_MINS, PARAM_MAXES, emulator, esd_func):
    rand = supercubos.LatinSampler().get_rand_sample(
        param_mins=PARAM_MINS,
        param_maxes=PARAM_MAXES,
        num_samples=NUM_ERRORCHECK_SAMPLES,
    )
    data_check = _pool_map(esd_func, rand)
    emulated_data = emulator(rand)
    return (emulated_data - data_check) / data_check
    nothing = np.array([])

    np.savetxt(DIR + filename + '.header.txt', nothing, header=header)
    np.save(DIR + filename + '.npy', array)


def generate_chain_filename():
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
    return DIR + SETUP_SLUG + '-mcmc-chains_' + timestamp + '.h5'


if __name__ == '__main__':
    print('Creating emulator...')

    lh = supercubos.LatinSampler(rng=np.random.default_rng(
        seed=SAMPLE_SEED)).get_lh_sample(PARAM_MINS, PARAM_MAXES,
                                         NUM_EMULATOR_SAMPLES)

    density_model = get_density_model()
    two_halo_esd = get_two_halo_esd()
    esd_emulator = get_esd_emulator(two_halo_esd)
    corrected_lensing_func = get_corrected_lensing_func(
        density_model, esd_emulator)
    shear_model = get_shear_model(corrected_lensing_func)

    def wrapped_esd_func(params):
        a_sz = params[0:1]
        a_2h = params[1:2]
        con = params[2:3]
        alpha = params[3:4]
        beta = params[4:5]
    nothing = np.array([])

    np.savetxt(DIR + filename + '.header.txt', nothing, header=header)
    np.save(DIR + filename + '.npy', array)


def generate_chain_filename():
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")
    return DIR + SETUP_SLUG + '-mcmc-chains_' + timestamp + '.h5'


if __name__ == '__main__':
    print('Creating emulator...')

    lh = supercubos.LatinSampler().get_sym_sample(PARAM_MINS, PARAM_MAXES,
                                                  NUM_EMULATOR_SAMPLES)

    density_model = get_density_model()
    shear_model = get_shear_model(density_model.excess_surface_density)

    def wrapped_esd_func(params):
        a_sz = params[0:1]
        con = params[1:2]
        alpha = params[2:3]
        beta = params[3:4]
        gamma = np.array([GAMMA])
        return shear_model.stacked_excess_surface_density(
            SIM_DATA.radii, a_sz, con, alpha, beta, gamma).squeeze()

    esds = _pool_map(wrapped_esd_func, lh)
 def coordinate_samples():
     param_mins = np.array([np.log(1e12), 0.8, 0.05, 1])
     param_maxes = np.array([np.log(8e15), 6, 2, 6])
     return supercubos.LatinSampler().get_sym_sample(
         param_mins, param_maxes, 100)