mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
comments extended
This commit is contained in:
parent
4d746802d2
commit
2b30623235
1 changed files with 15 additions and 35 deletions
|
@ -58,9 +58,9 @@ class Corr:
|
||||||
self.T = len(self.content) #for convenience: will be used a lot
|
self.T = len(self.content) #for convenience: will be used a lot
|
||||||
|
|
||||||
|
|
||||||
#The attribute "range" [start,end] marks a range of two timeslices.
|
#The attribute "range" [start,end] marks a range of two timeslices.
|
||||||
#This is useful for keeping track of plateaus and fitranges.
|
#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.
|
#The range can be inherited from other Corrs, if the operation should not alter a chosen range eg. multiplication with a constant.
|
||||||
if not prange is None:
|
if not prange is None:
|
||||||
self.prange=prange
|
self.prange=prange
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ class Corr:
|
||||||
newcontent.append(0.5 * (self.content[t] + self.content[self.T - t]))
|
newcontent.append(0.5 * (self.content[t] + self.content[self.T - t]))
|
||||||
if(all([x is None for x in newcontent])):
|
if(all([x is None for x in newcontent])):
|
||||||
raise Exception("Corr could not be symmetrized: No redundant values")
|
raise Exception("Corr could not be symmetrized: No redundant values")
|
||||||
|
|
||||||
return Corr(newcontent,prange= self.prange if hasattr(self,"prange") else None)
|
return Corr(newcontent, prange=self.prange if hasattr(self,"prange") else None)
|
||||||
|
|
||||||
def anti_symmetric(self):
|
def anti_symmetric(self):
|
||||||
|
|
||||||
|
@ -192,12 +192,12 @@ class Corr:
|
||||||
G0=G.content[t0]
|
G0=G.content[t0]
|
||||||
L = mat_mat_op(anp.linalg.cholesky, G0)
|
L = mat_mat_op(anp.linalg.cholesky, G0)
|
||||||
Li = mat_mat_op(anp.linalg.inv, L)
|
Li = mat_mat_op(anp.linalg.inv, L)
|
||||||
LT=L.T
|
LT=L.T
|
||||||
LTi=mat_mat_op(anp.linalg.inv, LT)
|
LTi=mat_mat_op(anp.linalg.inv, LT)
|
||||||
newcontent=[]
|
newcontent=[]
|
||||||
for t in range(self.T):
|
for t in range(self.T):
|
||||||
Gt=G.content[t]
|
Gt=G.content[t]
|
||||||
M=Li@Gt@LTi
|
M=Li@Gt@LTi
|
||||||
eigenvalues = eigh(M)[0]
|
eigenvalues = eigh(M)[0]
|
||||||
#print(eigenvalues)
|
#print(eigenvalues)
|
||||||
eigenvalue=eigenvalues[-state]
|
eigenvalue=eigenvalues[-state]
|
||||||
|
@ -205,14 +205,6 @@ class Corr:
|
||||||
return Corr(newcontent)
|
return Corr(newcontent)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def roll(self, dt):
|
def roll(self, dt):
|
||||||
return Corr(list(np.roll(np.array(self.content, dtype=object), dt)))
|
return Corr(list(np.roll(np.array(self.content, dtype=object), dt)))
|
||||||
|
|
||||||
|
@ -307,7 +299,7 @@ class Corr:
|
||||||
raise Exception("Correlator must be projected before fitting")
|
raise Exception("Correlator must be projected before fitting")
|
||||||
|
|
||||||
#The default behaviour is:
|
#The default behaviour is:
|
||||||
#1 use explicit fitrange
|
#1 use explicit fitrange
|
||||||
# if none is provided, use the range of the corr
|
# if none is provided, use the range of the corr
|
||||||
# if this is also not set, use the whole length of the corr (This could come with a warning!)
|
# if this is also not set, use the whole length of the corr (This could come with a warning!)
|
||||||
|
|
||||||
|
@ -316,7 +308,7 @@ class Corr:
|
||||||
if hasattr(self,"prange"):
|
if hasattr(self,"prange"):
|
||||||
fitrange=self.prange
|
fitrange=self.prange
|
||||||
else:
|
else:
|
||||||
fitrange=[0, self.T]
|
fitrange=[0, self.T]
|
||||||
|
|
||||||
xs = [x for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
xs = [x for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
||||||
ys = [self.content[x][0] for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
ys = [self.content[x][0] for x in range(fitrange[0], fitrange[1]) if not self.content[x] is None]
|
||||||
|
@ -333,8 +325,8 @@ class Corr:
|
||||||
def plateau(self, plateau_range=None, method="fit"):
|
def plateau(self, plateau_range=None, method="fit"):
|
||||||
if not plateau_range:
|
if not plateau_range:
|
||||||
if hasattr(self,"prange"):
|
if hasattr(self,"prange"):
|
||||||
plateau_range=self.prange
|
plateau_range=self.prange
|
||||||
else:
|
else:
|
||||||
raise Exception("no plateau range provided")
|
raise Exception("no plateau range provided")
|
||||||
if self.N != 1:
|
if self.N != 1:
|
||||||
raise Exception("Correlator must be projected before getting a plateau.")
|
raise Exception("Correlator must be projected before getting a plateau.")
|
||||||
|
@ -350,11 +342,11 @@ class Corr:
|
||||||
return returnvalue
|
return returnvalue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unsupported plateau method: " + method)
|
raise Exception("Unsupported plateau method: " + method)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_prange(self,prange):
|
def set_prange(self,prange):
|
||||||
if not len(prange)==2:
|
if not len(prange)==2:
|
||||||
raise Exception("range must be a list or array with two values")
|
raise Exception("range must be a list or array with two values")
|
||||||
if not ((isinstance(prange[0],int)) and (isinstance(prange[1],int))):
|
if not ((isinstance(prange[0],int)) and (isinstance(prange[1],int))):
|
||||||
|
@ -362,18 +354,10 @@ class Corr:
|
||||||
if not (0<=prange[0]<=self.T and 0<=prange[1]<=self.T and prange[0]<prange[1] ):
|
if not (0<=prange[0]<=self.T and 0<=prange[1]<=self.T and prange[0]<prange[1] ):
|
||||||
raise Exception("start and end point must define a range in the interval 0,T")
|
raise Exception("start and end point must define a range in the interval 0,T")
|
||||||
|
|
||||||
self.prange=prange
|
self.prange=prange
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Plotting routine for correlator
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#quick and dirty plotting function to view Correlator inside Jupyter
|
|
||||||
#If one would not want to import pyplot, this could easily be replaced by a call to pe.plot_corrs
|
|
||||||
#This might be a bit more flexible later
|
|
||||||
def show(self, x_range=None, comp=None, logscale=False, plateau=None, fit_res=None, save=None, ylabel=None):
|
def show(self, x_range=None, comp=None, logscale=False, plateau=None, fit_res=None, save=None, ylabel=None):
|
||||||
"""Plots the correlator, uses tag as label if available.
|
"""Plots the correlator, uses tag as label if available.
|
||||||
|
|
||||||
|
@ -453,10 +437,6 @@ class Corr:
|
||||||
def print(self, range=[0, None]):
|
def print(self, range=[0, None]):
|
||||||
print(self.__repr__(range))
|
print(self.__repr__(range))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self, range=[0, None]):
|
def __repr__(self, range=[0, None]):
|
||||||
if range[1]:
|
if range[1]:
|
||||||
range[1] += 1
|
range[1] += 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue