Exemplo n.º 1
0
 def kgAcceptance(self, n_steps = 20, step_size = .1, tol = 1e-2, print_out = True):
     """calculates the value <P_acc> for the free field
     
     Optional Inputs
         n_steps         :: int      :: LF trajectory lengths
         step_size       :: int      :: Leap Frog step size
         m :: float :: parameter used in potentials
         tol :: float :: tolerance level of deviation from expected value
         print_out :: bool :: prints info if True
     """
     passed = True
     
     pot = KG()
     n_samples = 1000
     delta_hs, measured_acc = self._runDeltaH(pot, n_samples = n_samples, 
         step_size=step_size, n_steps=n_steps)
     av_dh = np.asscalar(delta_hs.mean())
     expected_acc = erfc(.5*np.sqrt(av_dh))
     
     passed *= np.abs(measured_acc - expected_acc) <= tol
     
     meas_av_exp_dh  = np.asscalar(np.exp(-delta_hs).mean())
     if print_out:
         utils.display('<P_acc> using ' + pot.name, passed,
             details = {
                 'Inputs':['a: {}'.format(self.spacing),'m: {}'.format(pot.m),
                     'shape: {}'.format(self.lattice_shape), 'samples: {}'.format(n_samples),
                     'n steps: {}'.format(n_steps), 'step size: {}'.format(step_size)],
                 'Outputs':['expected: {}'.format(expected_acc),
                     'measured: {}'.format(measured_acc),
                     '<exp{{-𝛿H}}>: {}'.format(meas_av_exp_dh),
                     '<𝛿H>: {}'.format(av_dh)]
                 })
     return passed
Exemplo n.º 2
0
 def kgCorrelation(self, mu = 1., tol = 1e-2, print_out = True):
     """calculates the value <x(0)x(0)> for the QHO
     
     Optional Inputs
         mu :: float :: parameter used in potentials
         tol :: float :: tolerance level of deviation from expected value
         print_out :: bool :: prints info if True
     """
     passed = True
     
     pot = KG(m=mu)
     measured_xx = self._runCorrelation(pot)
     expected_xx = theory.operators.x2_1df(1, self.n, self.spacing, 0)
     
     passed *= np.abs(measured_xx - expected_xx) <= tol
     
     if print_out:
         utils.display('<x(0)x(t)> using ' + pot.name, passed,
             details = {
                 'Inputs':['a: {}'.format(self.spacing),'µ: {}'.format(mu),
                     'shape: {}'.format(self.lattice_shape), 'samples: {}'.format(self.n)],
                 'Outputs':['expected: {}'.format(expected_xx),
                     'measured: {}'.format(measured_xx)]
                 })
     return passed
Exemplo n.º 3
0
 def kgDeltaH(self, n_steps = 20, step_size = .1, tol = 1e-1, print_out = True):
     """Tests to see if <exp{-\delta H}> == 1
     
     Optional Inputs
         n_steps         :: int      :: LF trajectory lengths
         step_size       :: int      :: Leap Frog step size
         tol :: float :: tolerance level of deviation from expected value
         print_out :: bool :: prints info if True
     """
     passed = True
     pot = KG()
     delta_hs, av_acc = self._runDeltaH(pot)
     meas_av_exp_dh  = np.asscalar(np.exp(-delta_hs).mean())
     passed *= np.abs(meas_av_exp_dh - 1) <= tol
     
     if print_out:
         utils.display('<exp{-𝛿H}> using ' + pot.name, passed,
             details = {
                 'Inputs':['a: {}'.format(self.spacing),'n steps: {}'.format(n_steps),
                     'step size: {}'.format(step_size),
                     'lattice: {}'.format(self.lattice_shape)],
                 'Outputs':['<exp{{-𝛿H}}>: {}'.format(meas_av_exp_dh),
                     '<Prob. Accept>: {}'.format(av_acc)]
                 })
     return passed
Exemplo n.º 4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*- 
import numpy as np
from models import Basic_HMC as Model
from hmc.potentials import Klein_Gordon as KG

pot = KG(m=0.)

n, dim = 10, 1
x0 = np.random.random((n,)*dim)

n_samples = 1000000
n_burn_in = 50
step_size = .2
n_steps   = 20

model = Model(x0.copy(), pot, step_size=step_size, n_steps=n_steps)
model.run(n_samples=n_samples, n_burn_in=n_burn_in, verbose=True)
    store.store(all_plot, file_name, '_allPlot')
    
    plot(save = saveOrDisplay(save, file_name), **all_plot)
    
if __name__ == '__main__':
    from hmc.potentials import Klein_Gordon as KG
    import numpy as np
    from theory.operators import magnetisation_sq
    from theory.acceptance import acceptance
    from theory.clibs.autocorrelations.fixed import ihmc
    
    m         = 0.1
    n_steps   = 20
    
    file_name = __file__
    pot = KG(m=m)
    
    n, dim  = 20, 1
    x0 = np.random.random((n,)*dim)
    spacing = 1.
    
    # number of samples/burnin per point
    n_samples, n_burn_in = 100000, 1000
    
    mixing_angles = np.array([.5*np.pi])
    min_step = 0.2
    max_step = 0.7
    data_res = 100
    plot_res = 1000
    step_sizes = np.linspace(min_step, max_step, data_res)
    separations = np.arange(500)
#!/usr/bin/env python
import numpy as np

from common import dynamics_constEn_1d
from hmc.potentials import Klein_Gordon as KG

file_name = __file__
pot = KG(debug=True)

n, dim = 100, 1
x0 = np.random.random((n, ) * dim)

if '__main__' == __name__:
    dynamics_constEn_1d.main(x0,
                             pot,
                             file_name,
                             all_lines=False,
                             step_size=0.1,
                             n_steps=100,
                             save=True)
#!/usr/bin/env python
import numpy as np

from common import intac
from hmc.potentials import Klein_Gordon as KG
from correlations.corr import twoPoint
from theory.operators import x2_1df
from theory.autocorrelations import M2_Fix as AC_Theory

file_name = __file__
pot = KG()

n, dim = 20, 1
x0 = np.random.random((n,)*dim)
spacing    = 1.
step_size  = .1
n_steps    = 1
points     = 50
tau        = n_steps*step_size

n_samples, n_burn_in = 100000, 20
h_res = np.linspace(-0.15, 0.15, 100, True)
l_res = np.linspace(0.151, 0.85, points, True)
angle_fracs = np.concatenate([h_res,l_res,h_res+1,l_res+1,h_res+2])

opFn = lambda samples: twoPoint(samples, separation=0)
op_name = r'$\hat{O}_{pq} = \phi_0^2$'

# theoretical calculations
op_theory   = x2_1df(mu=pot.m, n=x0.size, a=spacing, sep=0)
pacc_theory = acceptance(dtau=step_size, tau=tau, n=x0.size, m=pot.m, t=tau*n_samples)
if __name__ == '__main__':

    # utils.logs.logging.root.setLevel(utils.logs.logging.DEBUG)

    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)

    for pot in [SHO(), KG(), QHO()]:

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

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

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

        test = Reversibility(pot, dynamics)
        utils.newTest(test.id)
Exemplo n.º 9
0
import numpy as np

from common import corr1d_xx
from hmc.potentials import Klein_Gordon as KG

file_name = __file__
pot = KG(phi_4=1, m=1)

n, dim = 20, 1
x0 = np.random.random((n, ) * dim)
spacing = 0.5

if '__main__' == __name__:
    corr1d_xx.main(x0,
                   pot,
                   file_name,
                   n_samples=100000,
                   n_burn_in=25,
                   spacing=spacing,
                   c_len=30,
                   step_size=0.1,
                   n_steps=20,
                   save=True,
                   free=False)