refactor: calculation of permutations in correlator module simplified.

This commit is contained in:
Fabian Joswig 2022-02-17 09:32:34 +00:00
parent ffdda97c65
commit 0e073da5c6

View file

@ -1,4 +1,5 @@
import warnings
from itertools import permutations
import numpy as np
import autograd.numpy as anp
import matplotlib.pyplot as plt
@ -1057,7 +1058,7 @@ def _sort_vectors(vec_set, ts):
if vec_set[t] is None:
sorted_vec_set.append(None)
elif not t == ts:
perms = permutation([i for i in range(N)])
perms = [list(o) for o in permutations([i for i in range(N)], N)]
best_score = 0
for perm in perms:
current_score = 1
@ -1075,19 +1076,6 @@ def _sort_vectors(vec_set, ts):
return sorted_vec_set
def permutation(lst): # Shamelessly copied
if len(lst) == 1:
return [lst]
ll = []
for i in range(len(lst)):
m = lst[i]
remLst = lst[:i] + lst[i + 1:]
# Generating all permutations where m is first
for p in permutation(remLst):
ll.append([m] + p)
return ll
def _GEVP_solver(Gt, G0): # Just so normalization an sorting does not need to be repeated. Here we could later put in some checks
sp_val, sp_vecs = scipy.linalg.eig(Gt, G0)
sp_vecs = [sp_vecs[:, np.argsort(sp_val)[-i]] for i in range(1, sp_vecs.shape[0] + 1)]