refactor!: Renamed methods smearing into index and smearing_symmetric

into matrix_symmetric
This commit is contained in:
Fabian Joswig 2022-02-08 14:06:04 +00:00
parent b8b3d6191f
commit 1196935e4e
2 changed files with 12 additions and 16 deletions

View file

@ -120,7 +120,7 @@
"Many methods we could use for regular correlators do not work with matrix-correlators. \n", "Many methods we could use for regular correlators do not work with matrix-correlators. \n",
"In order to get the effective mass, we need to convert to a regular correlator first. \n", "In order to get the effective mass, we need to convert to a regular correlator first. \n",
"\n", "\n",
"One way to do it, is to pick a smearing out of the matrix:" "One way to do it, is to pick an element out of the matrix:"
] ]
}, },
{ {
@ -130,7 +130,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"single_smearing = matrix_V1V1.smearing(0,0)" "single_smearing = matrix_V1V1.index(0,0)"
] ]
}, },
{ {
@ -138,7 +138,7 @@
"id": "5c25a23c", "id": "5c25a23c",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**Corr.smearing(i,j)** picks the element [i,j] from every matrix and returns a correlator containing one Obs per timeslice. \n", "**Corr.index(i,j)** picks the element [i,j] from every matrix and returns a correlator containing one Obs per timeslice. \n",
"But there is a more usefull way to retrieve a single value per timeslice. \n", "But there is a more usefull way to retrieve a single value per timeslice. \n",
"We might want a linear combination of different sources and sinks. \n", "We might want a linear combination of different sources and sinks. \n",
"We can formalize this as\n", "We can formalize this as\n",
@ -214,7 +214,7 @@
"This gives us a new correlator with one Obs per timeslice. We then calculate its effective mass and plot it. \n", "This gives us a new correlator with one Obs per timeslice. We then calculate its effective mass and plot it. \n",
"We tell the **Corr.show** method to show another correlator as a comparison. \n", "We tell the **Corr.show** method to show another correlator as a comparison. \n",
"\n", "\n",
"We can see, that the projected correlator (*blue*) converges to a mass plateau much quicker than the single smearing." "We can see, that the projected correlator (*blue*) converges to a mass plateau much quicker than the single smearing level."
] ]
}, },
{ {

View file

@ -16,10 +16,10 @@ class Corr:
Everything, this class does, can be achieved using lists or arrays of Obs. Everything, this class does, can be achieved using lists or arrays of Obs.
But it is simply more convenient to have a dedicated object for correlators. But it is simply more convenient to have a dedicated object for correlators.
One often wants to add or multiply correlators of the same length at every timeslice and it is inconvenient One often wants to add or multiply correlators of the same length at every timeslice and it is inconvenient
to iterate over all timeslices for every operation. This is especially true, when dealing with smearing matrices. to iterate over all timeslices for every operation. This is especially true, when dealing with matrices.
The correlator can have two types of content: An Obs at every timeslice OR a GEVP The correlator can have two types of content: An Obs at every timeslice OR a GEVP
smearing matrix at every timeslice. Other dependency (eg. spatial) are not supported. matrix at every timeslice. Other dependency (eg. spatial) are not supported.
""" """
@ -174,7 +174,7 @@ class Corr:
newcontent = [None if (self.content[t] is None or vector_l[t] is None or vector_r[t] is None) else np.asarray([vector_l[t].T @ self.content[t] @ vector_r[t]]) for t in range(self.T)] newcontent = [None if (self.content[t] is None or vector_l[t] is None or vector_r[t] is None) else np.asarray([vector_l[t].T @ self.content[t] @ vector_r[t]]) for t in range(self.T)]
return Corr(newcontent) return Corr(newcontent)
def smearing(self, i, j): def item(self, i, j):
"""Picks the element [i,j] from every matrix and returns a correlator containing one Obs per timeslice. """Picks the element [i,j] from every matrix and returns a correlator containing one Obs per timeslice.
Parameters Parameters
@ -185,7 +185,7 @@ class Corr:
Second index to be picked. Second index to be picked.
""" """
if self.N == 1: if self.N == 1:
raise Exception("Trying to pick smearing from projected Corr") raise Exception("Trying to pick item from projected Corr")
newcontent = [None if(item is None) else item[i, j] for item in self.content] newcontent = [None if(item is None) else item[i, j] for item in self.content]
return Corr(newcontent) return Corr(newcontent)
@ -239,13 +239,13 @@ class Corr:
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) return Corr(newcontent, prange=self.prange)
def smearing_symmetric(self): def matrix_symmetric(self):
"""Symmetrizes the matrices and therefore make them positive definite.""" """Symmetrizes the correlator matrices on every timeslice."""
if self.N > 1: if self.N > 1:
transposed = [None if (G is None) else G.T for G in self.content] transposed = [None if (G is None) else G.T for G in self.content]
return 0.5 * (Corr(transposed) + self) return 0.5 * (Corr(transposed) + self)
if self.N == 1: if self.N == 1:
raise Exception("Trying to symmetrize a smearing matrix, that already has N=1.") raise Exception("Trying to symmetrize a correlator matrix, that already has N=1.")
def GEVP(self, t0, ts=None, state=0, sorted_list=None): def GEVP(self, t0, ts=None, state=0, sorted_list=None):
"""Solve the general eigenvalue problem on the current correlator """Solve the general eigenvalue problem on the current correlator
@ -307,7 +307,7 @@ class Corr:
return all_vecs return all_vecs
def Eigenvalue(self, t0, state=1): def Eigenvalue(self, t0, state=1):
G = self.smearing_symmetric() G = self.matrix_symmetric()
G0 = G.content[t0] G0 = G.content[t0]
L = cholesky(G0) L = cholesky(G0)
Li = inv(L) Li = inv(L)
@ -798,8 +798,6 @@ class Corr:
content_string += "Description: " + self.tag + "\n" content_string += "Description: " + self.tag + "\n"
if self.N != 1: if self.N != 1:
return content_string return content_string
# This avoids a crash for N>1. I do not know, what else to do here. I like the list representation for N==1. We could print only one "smearing" or one matrix. Printing everything will just
# be a wall of numbers.
if range[1]: if range[1]:
range[1] += 1 range[1] += 1
@ -878,8 +876,6 @@ class Corr:
newcontent.append(None) newcontent.append(None)
else: else:
newcontent.append(self.content[t] / y.content[t]) newcontent.append(self.content[t] / y.content[t])
# Here we set the entire timeslice to undefined, if one of the smearings has encountered an division by zero.
# While this might throw away perfectly good values in other smearings, we will never have to check, if all values in our matrix are defined
for t in range(self.T): for t in range(self.T):
if newcontent[t] is None: if newcontent[t] is None:
continue continue