From 3e60403a51faa890daa7b41eae394714b1eec4fb Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Tue, 2 Nov 2021 14:12:39 +0000 Subject: [PATCH] reweighted property added to Corr --- pyerrors/correlators.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index ca1fb8a8..269b975e 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -3,7 +3,7 @@ import numpy as np import autograd.numpy as anp import matplotlib.pyplot as plt import scipy.linalg -from .pyerrors import Obs, dump_object +from .pyerrors import Obs, dump_object, reweight from .fits import least_squares from .linalg import eigh, inv, cholesky from .roots import find_root @@ -65,6 +65,16 @@ class Corr: def __getitem__(self, idx): return self.content[idx] + @property + def reweighted(self): + bool_array = np.array([list(map(lambda x: x.reweighted, o)) for o in self.content]) + if np.all(bool_array == 1): + return True + elif np.all(bool_array == 0): + return False + else: + raise Exception("Reweighting status of correlator corrupted.") + def gamma_method(self): """Apply the gamma method to the content of the Corr.""" for item in self.content: @@ -223,6 +233,15 @@ class Corr: """Reverse the time ordering of the Corr""" return Corr(self.content[::-1]) + def reweight(self, weight): + new_content = [] + for t_slice in self: + if t_slice is None: + new_content.append(None) + else: + new_content.append(np.array(reweight(weight, t_slice))) + return Corr(new_content) + def T_symmetry(self, partner, parity=+1): """Return the time symmetry average of the correlator and its partner