diff --git a/docs/pyerrors/correlators.html b/docs/pyerrors/correlators.html index 673507c4..d52c8589 100644 --- a/docs/pyerrors/correlators.html +++ b/docs/pyerrors/correlators.html @@ -237,8 +237,8 @@ Parameters ---------- - data_input : list - list of Obs or list of arrays of Obs. + data_input : list or array + list of Obs or list of arrays of Obs or array of Corrs padding : list, optional List with two entries where the first labels the padding at the front of the correlator and the second the padding @@ -248,25 +248,56 @@ region indentified for this correlator. """ - if not isinstance(data_input, list): - raise TypeError('Corr__init__ expects a list of timeslices.') + if isinstance(data_input, np.ndarray): # Input is an array of Corrs - if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): - _assert_equal_properties([o for o in data_input if o is not None]) - self.content = [np.asarray([item]) if item is not None else None for item in data_input] - self.N = 1 + # This only works, if the array fulfills the conditions below + if not len(data_input.shape) == 2 and data_input.shape[0] == data_input.shape[1]: + raise Exception("Incompatible array shape") + if not all([isinstance(item, Corr) for item in data_input.flatten()]): + raise Exception("If the input is an array, its elements must be of type pe.Corr") + if not all([item.N == 1 for item in data_input.flatten()]): + raise Exception("Can only construct matrix correlator from single valued correlators") + if not len(set([item.T for item in data_input.flatten()])) == 1: + raise Exception("All input Correlators must be defined over the same timeslices.") - elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): - self.content = data_input + T = data_input[0, 0].T + N = data_input.shape[0] + input_as_list = [] + for t in range(T): + if any([(item.content[t][0] is None) for item in data_input.flatten()]): + if not all([(item.content[t][0] is None) for item in data_input.flatten()]): + warnings.warn("Input ill-defined at different timeslices. Conversion leads to data loss!", RuntimeWarning) + input_as_list.append(None) + else: + array_at_timeslace = np.empty([N, N], dtype="object") + for i in range(N): + for j in range(N): + array_at_timeslace[i, j] = data_input[i, j][t] + input_as_list.append(array_at_timeslace) + data_input = input_as_list - noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements - self.N = noNull[0].shape[0] - if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: - raise Exception("Smearing matrices are not NxN") - if (not all([item.shape == noNull[0].shape for item in noNull])): - raise Exception("Items in data_input are not of identical shape." + str(noNull)) + if isinstance(data_input, list): + + if all([(isinstance(item, Obs) or isinstance(item, CObs)) for item in data_input]): + _assert_equal_properties(data_input) + self.content = [np.asarray([item]) for item in data_input] + if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): + _assert_equal_properties([o for o in data_input if o is not None]) + self.content = [np.asarray([item]) if item is not None else None for item in data_input] + self.N = 1 + + elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): + self.content = data_input + noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements + self.N = noNull[0].shape[0] + if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: + raise Exception("Smearing matrices are not NxN") + if (not all([item.shape == noNull[0].shape for item in noNull])): + raise Exception("Items in data_input are not of identical shape." + str(noNull)) + else: + raise Exception("data_input contains item of wrong type") else: - raise Exception("data_input contains item of wrong type") + raise Exception("Data input was not given as list or correct array") self.tag = None @@ -423,8 +454,27 @@ # There are two ways, the GEVP metod can be called. # 1. return_list=False will return a single eigenvector, normalized according to V*C(t_0)*V=1 # 2. return_list=True will return a new eigenvector for every timeslice. The time t_s is used to order the vectors according to. arXiv:2004.10472 [hep-lat] - def GEVP(self, t0, ts, state=0, sorting="Eigenvalue", return_list=False): - if not return_list: + def GEVP(self, t0, ts=None, state=0, sorted_list=None): + """Solve the general eigenvalue problem on the current correlator + + Parameters + ---------- + t0 : int + The time t0 for G(t)v= lambda G(t_0)v + ts : int + fixed time G(t_s)v= lambda G(t_0)v if return_list=False + If return_list=True and sorting=Eigenvector it gives a reference point for the sorting method. + state : int + The state one is interested in ordered by energy. The lowest state is zero. + sorted list : string + if this argument is set, a list of vectors (len=self.T) is returned. If it is left as None, only one vector is returned. + "Eigenvalue" - The eigenvector is chosen according to which einvenvalue it belongs individually on every timeslice. + "Eigenvector" - Use the method described in arXiv:2004.10472 [hep-lat] to find the set of v(t) belonging to the state. + The referense state is identified by its eigenvalue at t=ts + """ + if sorted_list is None: + if (ts is None): + raise Exception("ts is required if return_list=False") if (self.content[t0] is None) or (self.content[ts] is None): raise Exception("Corr not defined at t0/ts") G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double") @@ -436,7 +486,8 @@ sp_vecs = _GEVP_solver(Gt, G0) sp_vec = sp_vecs[state] return sp_vec - if return_list: + else: + all_vecs = [] for t in range(self.T): try: @@ -447,14 +498,16 @@ Gt[i, j] = self.content[t][i, j].value sp_vecs = _GEVP_solver(Gt, G0) - if sorting == "Eigenvalue": + if sorted_list == "Eigenvalue": sp_vec = sp_vecs[state] all_vecs.append(sp_vec) else: all_vecs.append(sp_vecs) except Exception: all_vecs.append(None) - if sorting == "Eigenvector": + if sorted_list == "Eigenvector": + if (ts is None): + raise Exception("ts is required for the Eigenvector sorting method.") all_vecs = _sort_vectors(all_vecs, ts) all_vecs = [a[state] for a in all_vecs] @@ -1220,8 +1273,8 @@ Parameters ---------- - data_input : list - list of Obs or list of arrays of Obs. + data_input : list or array + list of Obs or list of arrays of Obs or array of Corrs padding : list, optional List with two entries where the first labels the padding at the front of the correlator and the second the padding @@ -1231,25 +1284,56 @@ region indentified for this correlator. """ - if not isinstance(data_input, list): - raise TypeError('Corr__init__ expects a list of timeslices.') + if isinstance(data_input, np.ndarray): # Input is an array of Corrs - if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): - _assert_equal_properties([o for o in data_input if o is not None]) - self.content = [np.asarray([item]) if item is not None else None for item in data_input] - self.N = 1 + # This only works, if the array fulfills the conditions below + if not len(data_input.shape) == 2 and data_input.shape[0] == data_input.shape[1]: + raise Exception("Incompatible array shape") + if not all([isinstance(item, Corr) for item in data_input.flatten()]): + raise Exception("If the input is an array, its elements must be of type pe.Corr") + if not all([item.N == 1 for item in data_input.flatten()]): + raise Exception("Can only construct matrix correlator from single valued correlators") + if not len(set([item.T for item in data_input.flatten()])) == 1: + raise Exception("All input Correlators must be defined over the same timeslices.") - elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): - self.content = data_input + T = data_input[0, 0].T + N = data_input.shape[0] + input_as_list = [] + for t in range(T): + if any([(item.content[t][0] is None) for item in data_input.flatten()]): + if not all([(item.content[t][0] is None) for item in data_input.flatten()]): + warnings.warn("Input ill-defined at different timeslices. Conversion leads to data loss!", RuntimeWarning) + input_as_list.append(None) + else: + array_at_timeslace = np.empty([N, N], dtype="object") + for i in range(N): + for j in range(N): + array_at_timeslace[i, j] = data_input[i, j][t] + input_as_list.append(array_at_timeslace) + data_input = input_as_list - noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements - self.N = noNull[0].shape[0] - if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: - raise Exception("Smearing matrices are not NxN") - if (not all([item.shape == noNull[0].shape for item in noNull])): - raise Exception("Items in data_input are not of identical shape." + str(noNull)) + if isinstance(data_input, list): + + if all([(isinstance(item, Obs) or isinstance(item, CObs)) for item in data_input]): + _assert_equal_properties(data_input) + self.content = [np.asarray([item]) for item in data_input] + if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): + _assert_equal_properties([o for o in data_input if o is not None]) + self.content = [np.asarray([item]) if item is not None else None for item in data_input] + self.N = 1 + + elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): + self.content = data_input + noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements + self.N = noNull[0].shape[0] + if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: + raise Exception("Smearing matrices are not NxN") + if (not all([item.shape == noNull[0].shape for item in noNull])): + raise Exception("Items in data_input are not of identical shape." + str(noNull)) + else: + raise Exception("data_input contains item of wrong type") else: - raise Exception("data_input contains item of wrong type") + raise Exception("Data input was not given as list or correct array") self.tag = None @@ -1406,8 +1490,27 @@ # There are two ways, the GEVP metod can be called. # 1. return_list=False will return a single eigenvector, normalized according to V*C(t_0)*V=1 # 2. return_list=True will return a new eigenvector for every timeslice. The time t_s is used to order the vectors according to. arXiv:2004.10472 [hep-lat] - def GEVP(self, t0, ts, state=0, sorting="Eigenvalue", return_list=False): - if not return_list: + def GEVP(self, t0, ts=None, state=0, sorted_list=None): + """Solve the general eigenvalue problem on the current correlator + + Parameters + ---------- + t0 : int + The time t0 for G(t)v= lambda G(t_0)v + ts : int + fixed time G(t_s)v= lambda G(t_0)v if return_list=False + If return_list=True and sorting=Eigenvector it gives a reference point for the sorting method. + state : int + The state one is interested in ordered by energy. The lowest state is zero. + sorted list : string + if this argument is set, a list of vectors (len=self.T) is returned. If it is left as None, only one vector is returned. + "Eigenvalue" - The eigenvector is chosen according to which einvenvalue it belongs individually on every timeslice. + "Eigenvector" - Use the method described in arXiv:2004.10472 [hep-lat] to find the set of v(t) belonging to the state. + The referense state is identified by its eigenvalue at t=ts + """ + if sorted_list is None: + if (ts is None): + raise Exception("ts is required if return_list=False") if (self.content[t0] is None) or (self.content[ts] is None): raise Exception("Corr not defined at t0/ts") G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double") @@ -1419,7 +1522,8 @@ sp_vecs = _GEVP_solver(Gt, G0) sp_vec = sp_vecs[state] return sp_vec - if return_list: + else: + all_vecs = [] for t in range(self.T): try: @@ -1430,14 +1534,16 @@ Gt[i, j] = self.content[t][i, j].value sp_vecs = _GEVP_solver(Gt, G0) - if sorting == "Eigenvalue": + if sorted_list == "Eigenvalue": sp_vec = sp_vecs[state] all_vecs.append(sp_vec) else: all_vecs.append(sp_vecs) except Exception: all_vecs.append(None) - if sorting == "Eigenvector": + if sorted_list == "Eigenvector": + if (ts is None): + raise Exception("ts is required for the Eigenvector sorting method.") all_vecs = _sort_vectors(all_vecs, ts) all_vecs = [a[state] for a in all_vecs] @@ -2152,8 +2258,8 @@ smearing matrix at every timeslice. Other dependency (eg. spatial) are not suppo Parameters ---------- - data_input : list - list of Obs or list of arrays of Obs. + data_input : list or array + list of Obs or list of arrays of Obs or array of Corrs padding : list, optional List with two entries where the first labels the padding at the front of the correlator and the second the padding @@ -2163,25 +2269,56 @@ smearing matrix at every timeslice. Other dependency (eg. spatial) are not suppo region indentified for this correlator. """ - if not isinstance(data_input, list): - raise TypeError('Corr__init__ expects a list of timeslices.') + if isinstance(data_input, np.ndarray): # Input is an array of Corrs - if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): - _assert_equal_properties([o for o in data_input if o is not None]) - self.content = [np.asarray([item]) if item is not None else None for item in data_input] - self.N = 1 + # This only works, if the array fulfills the conditions below + if not len(data_input.shape) == 2 and data_input.shape[0] == data_input.shape[1]: + raise Exception("Incompatible array shape") + if not all([isinstance(item, Corr) for item in data_input.flatten()]): + raise Exception("If the input is an array, its elements must be of type pe.Corr") + if not all([item.N == 1 for item in data_input.flatten()]): + raise Exception("Can only construct matrix correlator from single valued correlators") + if not len(set([item.T for item in data_input.flatten()])) == 1: + raise Exception("All input Correlators must be defined over the same timeslices.") - elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): - self.content = data_input + T = data_input[0, 0].T + N = data_input.shape[0] + input_as_list = [] + for t in range(T): + if any([(item.content[t][0] is None) for item in data_input.flatten()]): + if not all([(item.content[t][0] is None) for item in data_input.flatten()]): + warnings.warn("Input ill-defined at different timeslices. Conversion leads to data loss!", RuntimeWarning) + input_as_list.append(None) + else: + array_at_timeslace = np.empty([N, N], dtype="object") + for i in range(N): + for j in range(N): + array_at_timeslace[i, j] = data_input[i, j][t] + input_as_list.append(array_at_timeslace) + data_input = input_as_list - noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements - self.N = noNull[0].shape[0] - if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: - raise Exception("Smearing matrices are not NxN") - if (not all([item.shape == noNull[0].shape for item in noNull])): - raise Exception("Items in data_input are not of identical shape." + str(noNull)) + if isinstance(data_input, list): + + if all([(isinstance(item, Obs) or isinstance(item, CObs)) for item in data_input]): + _assert_equal_properties(data_input) + self.content = [np.asarray([item]) for item in data_input] + if all([(isinstance(item, Obs) or isinstance(item, CObs)) or item is None for item in data_input]): + _assert_equal_properties([o for o in data_input if o is not None]) + self.content = [np.asarray([item]) if item is not None else None for item in data_input] + self.N = 1 + + elif all([isinstance(item, np.ndarray) or item is None for item in data_input]) and any([isinstance(item, np.ndarray) for item in data_input]): + self.content = data_input + noNull = [a for a in self.content if not (a is None)] # To check if the matrices are correct for all undefined elements + self.N = noNull[0].shape[0] + if self.N > 1 and noNull[0].shape[0] != noNull[0].shape[1]: + raise Exception("Smearing matrices are not NxN") + if (not all([item.shape == noNull[0].shape for item in noNull])): + raise Exception("Items in data_input are not of identical shape." + str(noNull)) + else: + raise Exception("data_input contains item of wrong type") else: - raise Exception("data_input contains item of wrong type") + raise Exception("Data input was not given as list or correct array") self.tag = None @@ -2201,8 +2338,8 @@ smearing matrix at every timeslice. Other dependency (eg. spatial) are not suppo
Parameters