예제 #1
0
    def coreFunc(n_steps):
        """function for multiprocessing support
        
        Required Inputs
            n_steps :: int :: the number of LF steps
        """

        model = Model(x0.copy(),
                      pot,
                      step_size=step_size,
                      n_steps=n_steps,
                      accept_kwargs={'get_delta_hs': True})
        model.sampler.accept.store_acceptance = True

        prob = 1.
        delta_hs = 1.
        av_dh = -1
        accept_rates = []
        delta_hs = []
        samples = []
        while av_dh < 0:
            model.run(n_samples=n_samples, n_burn_in=n_burn_in)
            accept_rates += model.sampler.accept.accept_rates[n_burn_in:]
            delta_hs += model.sampler.accept.delta_hs[n_burn_in:]
            samples.append(model.samples.copy())
            av_dh = np.mean(delta_hs)
            if av_dh < 0: tqdm.write('running again -ve av_dh')

        accept_rates = np.asarray(accept_rates)
        samples = np.concatenate(tuple(samples), axis=0)
        prob = accept_rates.mean()
        meas_av_exp_dh = np.asscalar((1. / np.exp(delta_hs)).mean())

        # ans = errors.uWerr(accept_rates)                    # get errors
        # f_aav, f_diff, _, itau, itau_diff, _, acns = ans    # extract data
        mean = accept_rates.mean()
        err = np.std(accept_rates) / np.sqrt(n_samples)
        th_err = np.std(accept_rates) / np.sqrt(n_samples)
        theory = acceptance(dtau=step_size, delta_h=av_dh)

        return mean, theory, err, th_err
 
 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)
 
 # theoretical functions
 tintTh = lambda dtau,pacc: ihmc(float(dtau*n_steps*m), float(pacc))
 paccTn = lambda dtau: acceptance(dtau=dtau, tau=dtau*n_steps, n=n, m=m)
 opTh = None
 
 main(x0, pot, file_name, n_samples, n_burn_in, 
         mixing_angles, step_sizes, 
         separations = separations, opFn = magnetisation_sq,
         tintTh=tintTh, paccTh = paccTn, opTh = opTh,
         plot_res=plot_res,
         n_steps = n_steps, save = True)
 
예제 #3
0
sites = 20
n_steps = 1
dtau = 0.1
tau = n_steps * dtau
mass = 1

a['subtitle'] = r"Lattice: " \
    + r"${}$; $a={:.1f}; \delta\tau={:.1f}; n={}; M=10^7$".format(
        (sites,), n_steps, dtau, n_steps)

# add integrated autocorrelation theory
# format :: {'lines':lines, 'x':angle_fracs, 'subtitle':subtitle, 'op_name':op_name}
# lines are [[y, err, label],..., [y, err, label]]
from theory.autocorrelations import M2_Fix, M2_Exp
from theory.acceptance import acceptance

x = a['x']  # fractions of pi
pacc = a['lines'][3][0][0]  # 3rd key, 0th line, y-value

m = M2_Exp(tau=tau, m=1)
y = np.asarray([
    m.integrated(tau=tau, m=mass, pa=pa_i, theta=theta * np.pi)
    for theta, pa_i in zip(x, pacc)
])
a['lines'][0].append([y, None, r'Theory'])

y = np.full(x.shape, acceptance(tau=tau, dtau=dtau, m=mass, n=sites))
a['lines'][3].append([y, None, r'Theory'])

plot(save=saveOrDisplay(save, file_name), **a)
n, dim = 20, 1
x0 = np.random.random((n, ) * dim)
spacing = 1.0

n_samples, n_burn_in = 10000, 50
c_len = 500

mixing_angles = [.5 * np.pi]
angle_labels = [r'\frac{\pi}{2}']

separations = range(c_len)
opFn = lambda samples: twoPoint(samples, separation=0)
op_name = r'$\hat{O} = x^2$'
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)

acFunc = lambda t, pa, theta: hmc(pa, tau * m, 1. / tau, t)

print '> Trajectory Length: tau: {}'.format(tau)
print '> Step Size: {}'.format(step_size)
print '> Theoretical <x^2>: {}'.format(op_theory)
print '> Theoretical <P_acc>: {}'.format(pacc_theory)

if '__main__' == __name__:
    routine.main(x0,
                 pot,
                 file_name,
                 n_samples=n_samples,
                 n_burn_in=n_burn_in,
                 spacing=spacing,
step_size = .1
n_steps = 1
points = 100
tau = n_steps * step_size

n_samples, n_burn_in = 1000, 20
angle_fracs = np.linspace(0, .02, points, True)

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)
acth = AC_Theory(tau=n_steps * step_size, m=pot.m)
iTauTheory = acth.integrated

if '__main__' == __name__:
    intac.main(x0,
               pot,
               file_name,
               n_samples=n_samples,
               n_burn_in=n_burn_in,
               spacing=spacing,
               step_size=step_size,
               n_steps=n_steps,
               opFn=opFn,
예제 #6
0
    spacing = 1.

    # number of samples/burnin per point
    n_samples, n_burn_in = 100000, 1000

    mixing_angles = np.array([np.pi / 8.])
    min_step = 0.1
    max_step = 0.7
    data_res = 100
    plot_res = 1000
    step_sizes = np.linspace(min_step, max_step, data_res)
    separations = np.arange(500)

    # theoretical functions
    tintTh = None
    paccTn = lambda dtau: acceptance(dtau=dtau, tau=dtau * 1, n=n, m=m)
    opTh = lambda null: x2_1df(m, n, spacing, 0)

    main(x0,
         pot,
         file_name,
         n_samples,
         n_burn_in,
         mixing_angles,
         step_sizes,
         separations=separations,
         opFn=x_sq,
         tintTh=tintTh,
         paccTh=paccTn,
         opTh=opTh,
         plot_res=plot_res,