Changeset 1102
 Timestamp:
 03/10/21 21:13:26 (4 weeks ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

framspy/FramsticksLib.py
r1101 r1102 138 138 for i in range(n): 139 139 assert square_matrix[i][i] == 0, "Not a correct dissimilarity matrix, diagonal expected to be 0" 140 assert (square_matrix == square_matrix.T).all(), "Probably not a correct dissimilarity matrix, expecting symmetry, verify this" # could introduce tolerance in comparison (e.g. class field DISSIMIL_DIFF_TOLERANCE=10^5) so that miniscule differences do not fail here 140 non_symmetric_diff = square_matrix  square_matrix.T 141 non_symmetric_count = np.count_nonzero(non_symmetric_diff) 142 if non_symmetric_count > 0: 143 non_symmetric_diff_abs = np.abs(non_symmetric_diff) 144 max_pos1d = np.argmax(non_symmetric_diff_abs) # location of largest discrepancy 145 max_pos2d_XY = np.unravel_index(max_pos1d, non_symmetric_diff_abs.shape) # 2D coordinates of largest discrepancy 146 max_pos2d_YX = max_pos2d_XY[1], max_pos2d_XY[0] # 2D coordinates of largest discrepancy mirror 147 worst_guy_XY = square_matrix[max_pos2d_XY] # this distance and the other below (its mirror) are most different 148 worst_guy_YX = square_matrix[max_pos2d_YX] 149 print("[WARN] Dissimilarity matrix: expecting symmetry, but %g out of %d pairs were asymmetrical, max difference was %g (%g %%)" % 150 (non_symmetric_count / 2, 151 n * (n  1) / 2, 152 non_symmetric_diff_abs[max_pos2d_XY], 153 non_symmetric_diff_abs[max_pos2d_XY] * 100 / ((worst_guy_XY + worst_guy_YX) / 2))) # max diff is not necessarily max % 141 154 return square_matrix 142 155 … … 147 160 for g in genotype_list: 148 161 valid.append(frams.Geno.newFromString(g).is_valid._int() == 1) 149 assert len(genotype_list) == len(valid), " Submitted %d genotypes, received %d validity values" % (len(genotype_list), len(valid))162 assert len(genotype_list) == len(valid), "Tested %d genotypes, received %d validity values" % (len(genotype_list), len(valid)) 150 163 return valid 151 164 … … 175 188 176 189 parsed_args = parseArguments() 177 frams DLL= FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.simsettings)190 framsLib = FramsticksLib(parsed_args.path, parsed_args.lib, parsed_args.simsettings) 178 191 179 192 print("Sending a direct command to Framsticks library that calculates \"4\"+2 yields", frams.Simulator.eval("return \"4\"+2;")) 180 193 181 simplest = frams DLL.getSimplest('1' if parsed_args.genformat is None else parsed_args.genformat)194 simplest = framsLib.getSimplest('1' if parsed_args.genformat is None else parsed_args.genformat) 182 195 print("\tSimplest genotype:", simplest) 183 parent1 = frams DLL.mutate([simplest])[0]196 parent1 = framsLib.mutate([simplest])[0] 184 197 parent2 = parent1 185 198 MUTATE_COUNT = 10 186 199 for x in range(MUTATE_COUNT): # example of a chain of 10 mutations 187 parent2 = frams DLL.mutate([parent2])[0]200 parent2 = framsLib.mutate([parent2])[0] 188 201 print("\tParent1 (mutated simplest):", parent1) 189 202 print("\tParent2 (Parent1 mutated %d times):" % MUTATE_COUNT, parent2) 190 offspring = frams DLL.crossOver(parent1, parent2)203 offspring = framsLib.crossOver(parent1, parent2) 191 204 print("\tCrossover (Offspring):", offspring) 192 print('\tDissimilarity of Parent1 and Offspring:', frams DLL.dissimilarity([parent1, offspring])[0, 1])193 print('\tPerformance of Offspring:', frams DLL.evaluate([offspring]))194 print('\tValidity of Parent1, Parent 2, and Offspring:', frams DLL.isValid([parent1, parent2, offspring]))205 print('\tDissimilarity of Parent1 and Offspring:', framsLib.dissimilarity([parent1, offspring])[0, 1]) 206 print('\tPerformance of Offspring:', framsLib.evaluate([offspring])) 207 print('\tValidity of Parent1, Parent 2, and Offspring:', framsLib.isValid([parent1, parent2, offspring]))
Note: See TracChangeset
for help on using the changeset viewer.