Commit 5f93adf3 authored by Manuel Schrauth's avatar Manuel Schrauth
Browse files

something experimental

parent c2619cf7
Pipeline #14261 failed with stage
in 3 minutes and 50 seconds
......@@ -94,6 +94,14 @@ def size2sizekey(size, rule):
return size
def downsample(data, n):
# cut off remainder
end = n * int(len(data)/n)
# reshape
res = data[:end].reshape(-1, n)
# apply bin average and return
return np.mean(res, 1)
# computes mean and stderr of an observable using the method
# defined in obs.protocoll (e.g. Bootstrap resampling)
......@@ -108,26 +116,70 @@ def mrqvcompute(obs, data, nsamples):
if len(length) != 1:
raise ValueError("Error: Data series do not have the same length")
results = np.zeros(nsamples)
(N, ) = length # unpack set
results = np.zeros(nsamples)
for i in range(nsamples):
(N, ) = length # unpack set
ind = np.random.choice(N,N)
data_shuffled = dict()
dat_shuffled = dict()
for key in data:
if hasattr(data[key], '__len__'):
data_shuffled.update({key: data[key][ind]})
dat = data[key]
dat_shuffled.update({key: dat[ind]})
else:
data_shuffled.update({key: data[key]})
dat_shuffled.update({key: data[key]})
results[i] = obs._call(data_shuffled)
results[i] = obs._call(dat_shuffled)
mean = np.mean(results)
stderr = np.sqrt(np.sum((results-mean)**2) / (nsamples-1))
return mean, stderr
# experimental!
elif obs.protocoll == "bootstrap2":
length = set()
for i, dat in enumerate(data.values()):
if hasattr(dat, '__len__'):
length.add(len(dat))
if len(length) != 1:
raise ValueError("Error: Data series do not have the same length")
(N, ) = length # unpack set
downsamplefactor = 100
nlen = int(N/downsamplefactor)
lll = []
for i in range(nlen):
dr = dict()
for key in data:
if hasattr(data[key], '__len__'):
dr.update({key: data[key][i*downsamplefactor:(i+1)*downsamplefactor]})
else:
dr.update({key: data[key]})
lll.append(obs._call(dr))
lll = np.array(lll)
results2 = np.zeros(nsamples)
for i in range(nsamples):
ind = np.random.choice(nlen,nlen)
results2[i] = np.mean(lll[ind])
mean2 = np.mean(results2)
stderr2 = np.sqrt(np.sum((results2-mean2)**2) / (nsamples-1))
return mean2, stderr2
elif obs.protocoll == "jackknife":
raise NotImplementedError("Jackknife is not implemented!")
......@@ -139,7 +191,6 @@ def mrqvcompute(obs, data, nsamples):
# compute mean and standard error of data using bootstrap resampling
def simple_bootstrap(data, nsamples=250):
sample_mean_all = []
for _ in range(nsamples):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment