def calculatePositionDistribution(hbar):
	print("calculating for hbar=%0.4f" % hbar)
	p = Potential(-mu, lambda_)

	k = Kinetic(mass, tau)

	de = deltaEnergy(k, p)

	m = Metropolis(de, init=initial, valWidth=1, initValWidth=initial_random, hbar=hbar, tau=tau, N=N)

	vals = next(islice(m, iterations, iterations + 1))			# get iterations th metropolis iteration
	return list(np.histogram(vals[0], bins)[0]), vals[1]
示例#2
0
def calculateEnergy(hbar):
    print('calculating for hbar=%0.4f' % hbar)
    m = Metropolis(init=initial,
                   valWidth=random_width,
                   initValWidth=initial_random,
                   hbar=hbar,
                   tau=tau,
                   N=N,
                   m=mass,
                   lambda_=0,
                   mu=mu)

    k = Kinetic(mass, tau)
    p = Potential(mu, 0)
    e = Energy(k, p)

    accept_ratios = []
    energies = []

    for _ in range(iterations):
        d, a = m.__next__()
        accept_ratios.append(a)
        energies.append(e(d))

    energies = np.array(energies)

    # calculate mean energy
    d = energies[:-1] - energies[1:]
    da = running_mean(d, 10)
    if da[0] > 0:
        start = np.argmax(da < 0) + 10
    else:
        start = np.argmax(da > 0) + 10

    energies_cut = energies[start:]

    energies_cut_ac = autoCorrelationNormalized(energies_cut,
                                                np.arange(len(energies_cut)))

    # calculate integrated autocorrelation time
    tint, dtint, w_max = getIntegratedCorrelationTime(energies_cut_ac,
                                                      factor=10)

    step_size = int((tint + dtint) * 2 + 1)

    energies_blocked = block(energies_cut, step_size)
    energy, denergy = np.mean(energies_blocked), np.std(energies_blocked)

    return [energy, denergy], np.mean(accept_ratios)
示例#3
0
tau = args.tau
hbar = args.hbar
initial = args.initial
initial_random = args.initial_random
distance = args.distance
lambda_ = distanceToParameter(distance)
output = args.output

parameters = [
			'iterations', 'N', 'mass', 'mu', 'tau', 'hbar', 'initial', 'initial_random',
            'distance', 'lambda_',
			]

p = Potential(-mu, lambda_)

k = Kinetic(mass, tau)

de = deltaEnergy(k, p)

m = Metropolis(de, init=initial, valWidth=1, initValWidth=initial_random, hbar=hbar, tau=tau, N=N)

root_path = getRootDirectory()
dir_ = root_path / 'data' / 'anharmonic_oscillator_track'
dir_.mkdir(parents=True, exist_ok=True)

file_ = dir_ / ('N%di%dinit%sm%0.4fl%0.4fd%0.4f.csv' % (N, iterations, 'rand' if initial == None else str(initial), mass, lambda_, distance))

if output != '':
	file_ = dir_ / output
config_filename = file_.with_suffix('.cfg')
config = ConfigParser()
示例#4
0
            positions = np.array([float(r) for r in row[1:]])
            data[num] = positions

config = configparser.ConfigParser()
config.read(full_path.with_suffix('.cfg'))

# read config from respective file
m = config['DEFAULT'].getfloat('mass', fallback=1.0)
tau = config['DEFAULT'].getfloat('tau', fallback=1.0)
mu = config['DEFAULT'].getfloat('mu', fallback=1.0)
lambda_ = config['DEFAULT'].getfloat('lambda_', fallback=0)

xdata = np.array(list(data.keys()))

# generate objects to measure the energy
k = Kinetic(m, tau)

p = Potential(mu, lambda_)

e = Energy(k, p)
ydata = np.array([e(data[x]) for x in xdata])

# calculate mean energy
d = ydata[:-1] - ydata[1:]
da = running_mean(d, 10)
if da[0] > 0:
    start = np.argmax(da < 0) + 10
else:
    start = np.argmax(da > 0) + 10

# filesystem stuff