5 import numpy.linalg as nplag
11 def reduce_matrix_search_for_base_recurse(wset, columns, contains, ignore):
13 for x in range(0, len(columns)):
14 if x in contains or x in ignore:
17 for i in range(0, len(wset)):
18 if wset[i] == 1 and columns[x][i] == 1:
24 for i in range(0, len(newset)):
25 newset[i] = newset[i] | columns[x][i]
29 if onecount == len(newset):
30 bases.append(set(contains))
32 rbases = reduce_matrix_search_for_base_recurse(newset, columns, contains, ignore)
34 if not rbase in bases:
39 def reduce_matrix_search_for_base(columns):
42 for i in range(0, len(columns)):
43 wset = list(columns[i])
45 bases.extend(reduce_matrix_search_for_base_recurse(wset, columns, {i}, ignore))
48 def reduce_matrix_remove_symbol(A, symrow, indx):
50 for i in range(0, len(A)):
53 def reduce_matrix(A, symrow, bases):
54 # Remove fixed symbols
59 for y in range(0, len(A)):
64 if (strue and not sfalse) or (sfalse and not strue):
65 reduce_matrix_remove_symbol(A, symrow, i)
68 # Remove duplicate symbols
73 for y in range(0, len(A)):
74 column.append(A[y][i])
76 reduce_matrix_remove_symbol(A, symrow, i)
78 columns.append(column)
83 for i in range(len(columns) - 1, -1,-1):
84 columnsr.append(columns[i])
85 basesx = reduce_matrix_search_for_base(columnsr)
92 for x in range(0, len(A)):
98 for fl in os.listdir(sf(conf.result_folder)):
99 if os.path.isfile(os.path.join(sf(conf.result_folder), fl)):
102 hashs.pop('NoConfig')
106 with open(sf(conf.config_map_file)) as f:
108 w = line.rstrip().split(sep=':')
109 if not w[0] or not w[0] in hashs:
111 sol = utils.config_strtoint(w[1], False)
114 for hash, data in hashs.items():
115 with open(os.path.join(sf(conf.result_folder), hash)) as f:
118 vec.append(float(ln))
122 def build_matrix(hashs):
125 for hash,data in hashs.items():
129 for y in range(0, len(A[0])):
130 symrow.append([abs(A[0][y])])
131 for x in range(0, len(A)):
132 for y in range(0, len(A[0])):
140 print("Collect data...")
141 hashs = collect_data()
143 print('Build matrix...')
144 A, B, symrow = build_matrix(hashs)
147 print('Simplify matrix...')
149 reduce_matrix(A, symrow, [bases])
152 print('Figuring values...')
153 R = nplag.lstsq(A, B)
156 print('--------------------')
157 utils.build_symbol_map()
158 for i in range(0, len(R[0])):
160 print("Base", end=' ')
164 print("Base", end=' ')
166 for x in range(0, len(bases)):
168 print("Base" + x, end=' ')
170 print(utils.smap[s], end=' ')
175 #################################################################################
177 if __name__ == '__main__':