Ejemplo n.º 1
0
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)))
Ejemplo n.º 2
0
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)))
Ejemplo n.º 3
0
def test_plots_multidimensional():

    # Test single trace
    from .models import multidimensional_model

    start, model, _ = multidimensional_model()
    with model as model:
        h = np.diag(find_hessian(start))
        step = Metropolis(model.vars, h)
        trace = sample(3000, step, start)

        traceplot(trace)
Ejemplo n.º 4
0
def test_plots():

    # Test single trace
    from pymc.examples import arbitrary_stochastic as asmod

    with asmod.model as model:

        start = model.test_point
        h = find_hessian(start)
        step = Metropolis(model.vars, h)
        trace = sample(3000, step, start)

        forestplot(trace)

        autocorrplot(trace)