def testLattice():
    test = test_lattice.Test()
    utils.newTest(test.id)
    assert test.wrap(print_out=True)
    assert test.laplacian(print_out=True)
    assert test.gradSquared(print_out=True)
    pass
def testHMC():
    test = test_hmc.Test(rng)
    utils.newTest(test.id)

    n_burn_in = 15
    tol = 1e-1

    # assert test.hmcSho1d(n_samples = 1000, n_burn_in = n_burn_in, tol = tol)
    # assert test.hmcGaus2d(n_samples = 10000, n_burn_in = n_burn_in, tol = tol)
    assert test.hmcQho(n_samples=100, n_burn_in=n_burn_in, tol=tol)
    pass
def testAutocorrelations():
    test = test_autocorrelations.Fixed(tol=1e-4)
    utils.newTest(test.id)

    assert test.integratedAutocorrelations()
    assert test.laplaceTransformAutocorrelations()

    test = test_autocorrelations.Exp(tol=1e-4)
    utils.newTest(test.id)
    assert test.integratedAutocorrelations()
    assert test.laplaceTransformAutocorrelations()
    assert test.autocorrelations()
    pass
def testMomentum():
    utils.newTest('hmc.Momentum')
    test = test_momentum.Test(rng=rng)

    rand4 = np.random.random(4)
    p41 = np.mat(rand4.reshape(4, 1))
    p22 = np.mat(rand4.reshape(2, 2))
    p14 = np.mat(rand4.reshape(1, 4))

    assert test.vectors(p41, print_out=True)
    assert test.vectors(p22, print_out=True)
    assert test.vectors(p14, print_out=True)

    assert test.mixing(print_out=True)
    pass
def testDynamics():
    dim = 1
    n = 10
    spacing = 1.
    step_size = [0.01, .1]
    n_steps = [1, 500]

    samples = 5
    step_sample = np.linspace(n_steps[0], n_steps[1], samples, True,
                              dtype=int),
    step_sizes = np.linspace(step_size[0], step_size[1], samples, True)

    x_nd = np.random.random((n, ) * dim)
    p0 = np.random.random((n, ) * dim)
    x0 = Periodic_Lattice(x_nd)

    dynamics = Leap_Frog(duE=None,
                         n_steps=n_steps[-1],
                         step_size=step_size[-1])

    for pot in [
            Simple_Harmonic_Oscillator(),
            Klein_Gordon(),
            Quantum_Harmonic_Oscillator()
    ]:

        dynamics.duE = pot.duE

        test = test_dynamics.Constant_Energy(pot, dynamics)
        utils.newTest(test.id)
        assert test.run(p0, x0, step_sample, step_sizes)

        test = test_dynamics.Reversibility(pot, dynamics)
        utils.newTest(test.id)
        assert test.run(p0, x0)
    pass
Beispiel #6
0
        
        # get a list of the functions from the potential
        f_list = [getattr(self.pot, abbrev) for full,abbrev in self.fns.iteritems()]
        
        # create a list of passed functions
        passed_fns = []
        failed_fns = []
        for i in f_list: # iterate functions
            # for idx in idx_list:                # iterate through indices
            try:
                i_ret = i(x=x, p=p)
                passed_fns.append(i.__name__)
            except Exception as e:
                passed = False
                checks.fullTrace()
                failed_fns.append(i.__name__+':{}'.format(e))
        
        if self.print_out:
            utils.display(name, passed,
                details = {
                    'passed functions':passed_fns,
                    'failed functions':failed_fns
                    })
        
        return passed
#
if __name__ == '__main__':
    test = Test()
    utils.newTest(test.id)
    test.bvg()
    test.qho()
def testPotentials():
    test = test_potentials.Test()
    utils.newTest(test.id)
    assert test.bvg()
    assert test.qho()
    pass
def testExpectations():
    test = test_expect.Test(rng=rng, spacing=.1, length=100, dim=1)
    utils.newTest(test.id)
    assert test.kgCorrelation(mu=1., tol=1e-1)
    assert test.kgDeltaH(tol=1e-1)
    pass