From 014c0d12ce850f429ca893bb6fbe1b0b17063b39 Mon Sep 17 00:00:00 2001 From: Jan Neuendorf Date: Tue, 5 Oct 2021 12:19:54 +0200 Subject: [PATCH 1/2] The GEVP method now has the parameter "state", deciding which eigenvector to return. Correlators get theoptional attribute "range", which is preserved under certain operations. Fits and plateaus will default to this range. --- pyerrors/correlators.py | 92 +++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 17 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index dc5f181e..a7f16cb8 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -1,5 +1,6 @@ import numpy as np import autograd.numpy as anp +#from scipy.special.orthogonal import _IntegerType from .pyerrors import * from .fits import standard_fit from .roots import find_root @@ -22,7 +23,7 @@ class Corr: """ - def __init__(self, data_input, padding_front=0, padding_back=0): + def __init__(self, data_input, padding_front=0, padding_back=0,range=None): #All data_input should be a list of things at different timeslices. This needs to be verified if not (isinstance(data_input, list)): @@ -56,6 +57,12 @@ class Corr: self.T = len(self.content) #for convenience: will be used a lot + #The attribute "range" [start,end] marks a range of two timeslices. + #This is useful for keeping track of plateaus and fitranges. + #The range can be inherited from other Corrs, if the operation should not alter a chosen range eg. multiplication with a constant. + if not range is None: + self.range=range + self.gamma_method() @@ -98,6 +105,8 @@ class Corr: newcontent = [None if (item is None) else np.asarray([vector_l.T@item@vector_r]) for item in self.content] return Corr(newcontent) + def sum(self): + return np.sqrt(self.N)*self.projected(np.ones(self.N)) #For purposes of debugging and verification, one might want to see a single smearing level. smearing will return a Corr at the specified i,j. where both are integers 0<=i,j Date: Wed, 6 Oct 2021 13:16:04 +0200 Subject: [PATCH 2/2] I changed the name from range to prange (hope i did not miss something) There is now an Eigenvalue method using the cholesky method you put in the example. I do not really use that, but it seems like a logical inclusion. I gave the standard fit an option to seht the number of fit parameters by hand, because it does not work automatically if the function is not consistent between calls. --- pyerrors/correlators.py | 96 ++++++++++++++++++++++++++++------------- pyerrors/fits.py | 22 ++++++---- 2 files changed, 80 insertions(+), 38 deletions(-) diff --git a/pyerrors/correlators.py b/pyerrors/correlators.py index a7f16cb8..aedf0e54 100644 --- a/pyerrors/correlators.py +++ b/pyerrors/correlators.py @@ -3,6 +3,7 @@ import autograd.numpy as anp #from scipy.special.orthogonal import _IntegerType from .pyerrors import * from .fits import standard_fit +from .linalg import * from .roots import find_root from matplotlib import pyplot as plt from matplotlib.ticker import NullFormatter # useful for `logit` scale @@ -23,7 +24,7 @@ class Corr: """ - def __init__(self, data_input, padding_front=0, padding_back=0,range=None): + def __init__(self, data_input, padding_front=0, padding_back=0,prange=None): #All data_input should be a list of things at different timeslices. This needs to be verified if not (isinstance(data_input, list)): @@ -61,7 +62,7 @@ class Corr: #This is useful for keeping track of plateaus and fitranges. #The range can be inherited from other Corrs, if the operation should not alter a chosen range eg. multiplication with a constant. if not range is None: - self.range=range + self.prange=prange self.gamma_method() @@ -143,7 +144,7 @@ class Corr: if(all([x is None for x in newcontent])): raise Exception("Corr could not be symmetrized: No redundant values") - return Corr(newcontent,range= self.range if hasattr(self,"range") else None) + return Corr(newcontent,prange= self.prange if hasattr(self,"prange") else None) def anti_symmetric(self): @@ -158,7 +159,7 @@ class Corr: newcontent.append(0.5 * (self.content[t] - self.content[self.T - t])) if(all([x is None for x in newcontent])): raise Exception("Corr could not be symmetrized: No redundant values") - return Corr(newcontent,range= self.range if hasattr(self,"range") else None) + return Corr(newcontent,prange= self.prange if hasattr(self,"prange") else None) #This method will symmetrice the matrices and therefore make them positive definit. @@ -186,6 +187,32 @@ class Corr: return sp_vec + def Eigenvalue(self,t0,state=1): + G=self.smearing_symmetric() + G0=G.content[t0] + L = mat_mat_op(anp.linalg.cholesky, G0) + Li = mat_mat_op(anp.linalg.inv, L) + LT=L.T + LTi=mat_mat_op(anp.linalg.inv, LT) + newcontent=[] + for t in range(self.T): + Gt=G.content[t] + M=Li@Gt@LTi + eigenvalues = eigh(M)[0] + #print(eigenvalues) + eigenvalue=eigenvalues[-state] + newcontent.append(eigenvalue) + return Corr(newcontent) + + + + + + + + + + def roll(self, dt): return Corr(list(np.roll(np.array(self.content, dtype=object), dt))) @@ -260,6 +287,17 @@ class Corr: raise Exception('m_eff is undefined at all timeslices') return Corr(newcontent, padding_back=1) + elif variant is 'arccosh': + newcontent=[] + for t in range(1,self.T-1): + if (self.content[t] is None) or (self.content[t+1] is None)or (self.content[t-1] is None): + newcontent.append(None) + else: + newcontent.append((self.content[t+1]+self.content[t-1])/(2*self.content[t])) + if(all([x is None for x in newcontent])): + raise Exception("m_eff is undefined at all timeslices") + return np.arccosh(Corr(newcontent,padding_back=1,padding_front=1)) + else: raise Exception('Unkown variant.') @@ -275,8 +313,8 @@ class Corr: if fitrange is None: - if hasattr(self,"range"): - fitrange=self.range + if hasattr(self,"prange"): + fitrange=self.prange else: fitrange=[0, self.T] @@ -294,8 +332,8 @@ class Corr: #we want to quickly get a plateau def plateau(self, plateau_range=None, method="fit"): if not plateau_range: - if hasattr(self,"range"): - plateau_range=self.range + if hasattr(self,"prange"): + plateau_range=self.prange else: raise Exception("no plateau range provided") if self.N != 1: @@ -316,15 +354,15 @@ class Corr: - def set_range(self,range): - if not len(range)==2: + def set_prange(self,prange): + if not len(prange)==2: raise Exception("range must be a list or array with two values") - if not ((isinstance(range[0],int)) and (isinstance(range[1],int))): + if not ((isinstance(prange[0],int)) and (isinstance(prange[1],int))): raise Exception("start and end point must be integers") - if not (0<=range[0]<=self.T and 0<=range[1]<=self.T and range[0]