Commit 1c681dd7 authored by Lukas Weber's avatar Lukas Weber

fix vector observables

parent f85ec54f
...@@ -10,9 +10,8 @@ class Observable: ...@@ -10,9 +10,8 @@ class Observable:
self.rebinning_bin_count = np.zeros(num_tasks) self.rebinning_bin_count = np.zeros(num_tasks)
self.autocorrelation_time = np.zeros(num_tasks)+np.nan self.autocorrelation_time = np.zeros(num_tasks)+np.nan
# have to be set later because dimension is unknown self.mean = [None for i in range(num_tasks)]
self.mean = None self.error = [None for i in range(num_tasks)]
self.error = None
class MCArchive: class MCArchive:
def __init__(self, filename): def __init__(self, filename):
...@@ -36,19 +35,8 @@ class MCArchive: ...@@ -36,19 +35,8 @@ class MCArchive:
o.rebinning_bin_count[i] = value['rebinning_bin_count'] o.rebinning_bin_count[i] = value['rebinning_bin_count']
o.autocorrelation_time[i] = value['autocorrelation_time'] o.autocorrelation_time[i] = value['autocorrelation_time']
# fill in dimensions on first occurence of the observable o.mean[i] = value['mean']
if np.all(o.mean == None): o.error[i] = value['error']
o.mean = np.zeros([self.num_tasks, len(value['mean'])]) + np.nan
o.error = np.zeros([self.num_tasks, len(value['error'])]) + np.nan
if o.mean.shape != o.error.shape:
raise Exception('observable "{}": dimension mismatch between mean and error'.format(obs))
else:
if len(value['mean']) != o.mean.shape[1] or len(value['error']) != o.error.shape[1]:
raise Exception('observable "{}": dimension mismatch between different tasks'.format(obs))
o.mean[i,:] = value['mean']
o.error[i,:] = value['error']
def filter_mask(self, filter): def filter_mask(self, filter):
if not filter: if not filter:
...@@ -71,11 +59,15 @@ class MCArchive: ...@@ -71,11 +59,15 @@ class MCArchive:
selection.rebinning_bin_count = orig.rebinning_bin_count[mask] selection.rebinning_bin_count = orig.rebinning_bin_count[mask]
selection.rebinning_bin_length = orig.rebinning_bin_length[mask] selection.rebinning_bin_length = orig.rebinning_bin_length[mask]
selection.autocorrelation_time = orig.autocorrelation_time[mask] selection.autocorrelation_time = orig.autocorrelation_time[mask]
selection.mean = orig.mean[mask,:]
selection.error = orig.error[mask,:] selection.mean = [m for i, m in enumerate(orig.mean) if mask[i]]
selection.error = [m for i, m in enumerate(orig.error) if mask[i]]
if all(len(m) == len(selection.mean[0]) for m in selection.mean):
selection.mean = np.array(selection.mean)
selection.error = np.array(selection.error)
# if it is not a vector observable we can make it simpler for the user if selection.mean.shape[1] == 1:
if selection.mean.shape[-1] == 1:
selection.mean = selection.mean.flatten() selection.mean = selection.mean.flatten()
selection.error = selection.error.flatten() selection.error = selection.error.flatten()
......
...@@ -124,18 +124,19 @@ results merge(const std::vector<std::string> &filenames, const std::vector<evala ...@@ -124,18 +124,19 @@ results merge(const std::vector<std::string> &filenames, const std::vector<evala
size_t vector_idx = i % vector_length; size_t vector_idx = i % vector_length;
obs.mean[vector_idx] += samples[i]; obs.mean[vector_idx] += samples[i];
metadata[obs_name].sample_counter++; if(vector_idx == vector_length-1) {
metadata[obs_name].sample_counter++;
}
} }
} }
} }
for(auto &entry : res.observables) { for(auto &[obs_name, obs] : res.observables) {
auto &obs = entry.second; assert(metadata[obs_name].sample_counter ==
assert(metadata[entry.first].sample_counter ==
obs.rebinning_bin_count * obs.rebinning_bin_length); obs.rebinning_bin_count * obs.rebinning_bin_length);
for(auto &mean : obs.mean) { for(auto &mean : obs.mean) {
mean /= metadata[entry.first].sample_counter; mean /= metadata[obs_name].sample_counter;
} }
} }
...@@ -181,9 +182,8 @@ results merge(const std::vector<std::string> &filenames, const std::vector<evala ...@@ -181,9 +182,8 @@ results merge(const std::vector<std::string> &filenames, const std::vector<evala
} }
} }
for(auto &entry : res.observables) { for(auto &[obs_name, obs] : res.observables) {
auto &obs = entry.second; assert(metadata[obs_name].current_rebin == obs.rebinning_bin_count);
assert(metadata[entry.first].current_rebin == obs.rebinning_bin_count);
for(size_t i = 0; i < obs.error.size(); i++) { for(size_t i = 0; i < obs.error.size(); i++) {
int used_samples = obs.rebinning_bin_count * obs.rebinning_bin_length; int used_samples = obs.rebinning_bin_count * obs.rebinning_bin_length;
double no_rebinning_error = double no_rebinning_error =
......
Markdown is supported
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