Merge pull request #99 from fjosw/feature/GEVP_t0

GEVP rehaul
This commit is contained in:
Fabian Joswig 2022-05-18 09:46:24 +01:00 committed by GitHub
commit 2a86c059f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -266,9 +266,11 @@ class Corr:
symmetric_corr = self.matrix_symmetric()
if sorted_list is None:
if (ts is None):
raise Exception("ts is required if sorted_list=None")
raise Exception("ts is required if sorted_list=None.")
if (ts <= t0):
raise Exception("ts has to be larger than t0.")
if (self.content[t0] is None) or (self.content[ts] is None):
raise Exception("Corr not defined at t0/ts")
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")
for i in range(self.N):
for j in range(self.N):
@ -281,8 +283,8 @@ class Corr:
elif sorted_list in ["Eigenvalue", "Eigenvector"]:
if sorted_list == "Eigenvalue" and ts is not None:
warnings.warn("ts has no effect when sorting by eigenvalue is chosen.", RuntimeWarning)
all_vecs = []
for t in range(self.T):
all_vecs = [None] * (t0 + 1)
for t in range(t0 + 1, self.T):
try:
G0, Gt = np.empty([self.N, self.N], dtype="double"), np.empty([self.N, self.N], dtype="double")
for i in range(self.N):
@ -302,7 +304,7 @@ class Corr:
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]
all_vecs = [a[state] if a is not None else None for a in all_vecs]
else:
raise Exception("Unkown value for 'sorted_list'.")

View file

@ -230,8 +230,8 @@ def test_matrix_corr():
corr_mat = pe.Corr(np.array([[corr_aa, corr_ab], [corr_ab, corr_aa]]))
corr_mat.item(0, 0)
vec_0 = corr_mat.GEVP(0, 0, sorted_list=None)
vec_1 = corr_mat.GEVP(0, 0, state=1, sorted_list=None)
vec_0 = corr_mat.GEVP(0, 1, sorted_list=None)
vec_1 = corr_mat.GEVP(0, 1, state=1, sorted_list=None)
corr_0 = corr_mat.projected(vec_0)
corr_1 = corr_mat.projected(vec_1)
@ -240,7 +240,7 @@ def test_matrix_corr():
assert np.all([o == 0 for o in corr_1 - corr_aa])
corr_mat.GEVP(0, sorted_list="Eigenvalue")
corr_mat.GEVP(0, 0, sorted_list="Eigenvector")
corr_mat.GEVP(0, 1, sorted_list="Eigenvector")
corr_mat.matrix_symmetric()