<commit_before>import pymc as pm

import models
from pymc.step_methods.hmc import leapfrog, Hamiltonian
from checks import *

def test_leapfrog_reversible():
    n=3
    start, model, _ = models.non_normal(n)

    with model:
        h = pm.find_hessian(start, model = model)
        print h
        step = pm.HamiltonianMC(model.vars, h, model = model)

    bij = pm.DictToArrayBijection(step.ordering, start)

    logp, dlogp = map(bij.mapf, step.fs)
    H = Hamiltonian(logp, dlogp, step.potential)


    q0 = bij.map(start)
    p0 = np.ones(n)*.05
    for e in [.01, .1, 1.2]:
        for L in [1,2,3,4, 20]:

            q,p = q0,p0

            q,p = leapfrog(H, q,p,L, e)
            q,p = leapfrog(H, q,-p,L,e)

            close_to(q, q0, 1e-8, str((L, e)))
            close_to(-p, p0, 1e-8, str((L, e)))
<commit_msg>remove print<commit_after>import pymc as pm

import models
from pymc.step_methods.hmc import leapfrog, Hamiltonian
from checks import *

def test_leapfrog_reversible():
    n=3
    start, model, _ = models.non_normal(n)

    with model:
        h = pm.find_hessian(start, model = model)
        step = pm.HamiltonianMC(model.vars, h, model = model)

    bij = pm.DictToArrayBijection(step.ordering, start)

    logp, dlogp = map(bij.mapf, step.fs)
    H = Hamiltonian(logp, dlogp, step.potential)


    q0 = bij.map(start)
    p0 = np.ones(n)*.05
    for e in [.01, .1, 1.2]:
        for L in [1,2,3,4, 20]:

            q,p = q0,p0

            q,p = leapfrog(H, q,p,L, e)
            q,p = leapfrog(H, q,-p,L,e)

            close_to(q, q0, 1e-8, str((L, e)))
            close_to(-p, p0, 1e-8, str((L, e)))

{'fraction_non_alphanumeric': 0.14538790470372634, 'fraction_numerical': 0.029321930360415395, 'mean_word_length': 2.3024193548387095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3357342', 'n_tokens_mistral': 700, 'n_tokens_neox': 659, 'n_words': 155}