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)
82 basesx = reduce_matrix_search_for_base(columns)
89 for x in range(0, len(A)):
95 for fl in os.listdir(sf(conf.result_folder)):
96 if os.path.isfile(os.path.join(sf(conf.result_folder), fl)):
103 with open(sf(conf.config_map_file)) as f:
105 w = line.rstrip().split(sep=':')
106 if not w[0] or not w[0] in hashs:
108 sol = utils.config_strtoint(w[1], False)
111 for hash, data in hashs.items():
112 with open(os.path.join(sf(conf.result_folder), hash)) as f:
115 vec.append(float(ln))
119 def build_matrix(hashs):
122 for hash,data in hashs.items():
126 for y in range(0, len(A[0])):
127 symrow.append([abs(A[0][y])])
128 for x in range(0, len(A)):
129 for y in range(0, len(A[0])):
137 print("Collect data...")
138 hashs = collect_data()
140 print('Build matrix...')
141 A, B, symrow = build_matrix(hashs)
144 print('Simplify matrix...')
146 reduce_matrix(A, symrow, [bases])
149 print('Figuring values...')
150 R = nplag.lstsq(A, B)
153 print('--------------------')
154 utils.build_symbol_map()
155 for i in range(0, len(R[0])):
157 print("Base", end=' ')
161 print("Base", end=' ')
163 for x in range(0, len(bases)):
165 print("Base" + x, end=' ')
167 print(utils.smap[s], end=' ')
172 #################################################################################
174 if __name__ == '__main__':