Ejemplo n.º 1
0
def main():
    TRUE_WIMP = MockGen.TRUE_WIMP
    events = []
    with open('mock.txt') as f:
        events = f.read().splitlines()
    events = [float(num) for num in events]
    # define events
    E_thr = 6 * const.keV
    # pick start
    theta = np.zeros((N, 2))
    # initialize MCMC parameters
    theta[0] = [const.M_D, 1000 * const.sigma]
    # initialize values for energy
    Emin = 1 * const.keV
    Emax = fn.max_recoil_energy()
    del_Er = 1
    E_r = np.arange(Emin, Emax, del_Er)
    events = lik.find_indices(E_r, events)
    # Metropolis Hastings loop
    acceptance = []
    for i in tqdm(range(1, N)):
        proposed_theta = proposal(theta[i - 1])
        prev_lik = lik.events_likelihood(E_r, events, theta[i - 1], const.AXe,
                                         E_thr, del_Er)
        new_lik = lik.events_likelihood(E_r, events, proposed_theta, const.AXe,
                                        E_thr, del_Er)
        ratio = new_lik - prev_lik
        if ratio >= 0:
            theta[i] = proposed_theta
            acceptance.append(1)
        elif np.log(np.random.rand()) < ratio:
            theta[i] = proposed_theta
            acceptance.append(1)
        else:
            theta[i] = theta[i - 1]
    print(len(acceptance) / (N + 1))
    f = open('data.txt', 'w')
    for thetas in theta:
        f.write(str(thetas) + '\n')
    f.close()