-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpermutation_group_utils.py
More file actions
28 lines (22 loc) · 976 Bytes
/
permutation_group_utils.py
File metadata and controls
28 lines (22 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from collections import defaultdict
import numpy as np
from sympy.combinatorics import Permutation, PermutationGroup
def find_simple_generators(trafos):
# We try to find as simple-looking generator matrices as possible by
# favoring permutations where nodes stay together, i.e.
# the sum of differences of images of neighbouring nodes is small
simpleness = defaultdict(list)
for trafo in trafos:
s = np.sum(np.abs(np.diff(trafo)))
simpleness[s].append(trafo)
simple_generators = []
permutation_group = PermutationGroup()
for _, t in sorted(simpleness.items()):
for trafo in t:
p = Permutation(trafo)
if p not in permutation_group:
simple_generators.append(p)
permutation_group = PermutationGroup(*simple_generators)
if permutation_group.order() == len(trafos):
return simple_generators, permutation_group
assert False