def entry_formatter_lambda(allSolutions, entryIndex): # solution = (bestOrig, bestOrig.size, testMSE) solution = allSolutions[entryIndex] def latexTextColor(color, x): return r"\textbf{\textcolor{" + str(color) + "}{" + str(x) + "}}" value = float(solution[2]) valueSc = scientificNotationLatex(value) colorValue = printer.getLatexColorCode(value, [ allSolutions[0][2], (allSolutions[-1][2] + allSolutions[0][2]) / 2.0, allSolutions[-1][2] ], ["darkgreen", "orange", "darkred!50!white"]) size = int(solution[1]) sizeStr = r"\textcolor{darkblue}{\textbf{" + str(size) + r"}}" # colorSize = printer.getLatexColorCode(value, sizeColorScale, ["darkred!50!white", "orange", "darkgreen"]) sol = solution[0] sol = shortenLongConstants(sol) sol = sol[:STR_LEN_LIMIT] + " [..]" if len( sol) > STR_LEN_LIMIT else sol # sol = r"\texttt{" + sol + "}" return r"{0} ({1}) ({2})".format(sol, latexTextColor(colorValue, valueSc), sizeStr)
def entry_formatter_lambda(allSolutions, entryIndex): entry = allSolutions[entryIndex] value = round(float(entry[1]), 2) nameFormatter = lambda x: r"\textcolor{darkblue}{" + str(x) + "}" if "CDGP" in str(x) else x color = printer.getLatexColorCode(value, [allSolutions[0][1], (allSolutions[-1][1] + allSolutions[0][1]) / 2.0, allSolutions[-1][1]], ["darkgreen", "orange", "darkred!50!white"]) return "{0} ({1})".format(nameFormatter(entry[0]), r"\textbf{\textcolor{" + color + "}{" + str(value) + "}}") # percentage of runs
def get_freqCounterexamples(props): if len(props) == 0: return "-" counterex = {} for p in props: # e.g. "ArrayBuffer((Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None), (Map(m1 -> 1.0, m2 -> 2.0, r -> 1.0),None) s = p["tests.collected"] cxs = re.findall("\(Map\((?:[^,]+ -> [^,]+(?:, )?)+\),None\)", s) # ^ makes to match all charecters other than ',' # cxs = <class 'list'>: ['(Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None)', '(Map(m1 -> 1.0, m2 -> 2.0, r -> 1.0),None)'] for cx in cxs: # e.g. cx = (Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None) if "None" in cx: # we are interested only in the noncomplete tests cx = cx[len("(Map("):-len("),None)")] # cx = 'm1 -> 0.0, m2 -> 0.0, r -> 0.0' fargs = re.findall( "[^,]+ -> [^,]+(?:, )?", cx) # findall returns non-overlapping matches in string fargs = [a.replace(", ", "") for a in fargs] fargs.sort(key=lambda a: a.split(" -> ")[0]) sargs = ",".join(fargs).replace(" -> ", "=") if sargs in counterex: counterex[sargs] += 1 else: counterex[sargs] = 1 counterex_items = list(counterex.items()) if len(counterex_items) == 0: return "n/a" else: counterex_items.sort(key=lambda x: (x[1], x[0]), reverse=True) NUM_SHOWN = 5 # For some strange reason makecell doesn't work, even when it is a suggested answer (https://tex.stackexchange.com/questions/2441/how-to-add-a-forced-line-break-inside-a-table-cell) # return "\\makecell{" + "{0} ({1})\\\\{2} ({3})".format(counterex_items[0][0], counterex_items[0][1], # counterex_items[1][0], counterex_items[1][1]) + "}" res = "\\pbox[l][" + str( 17 * min(NUM_SHOWN, len(counterex_items))) + "pt][b]{20cm}{" for i in range(NUM_SHOWN): if i >= len(counterex_items): break if i > 0: res += "\\\\ \\ " # res += "{0} ({1})".format(counterex_items[i][0], counterex_items[i][1]) # absolute value percent = round(100.0 * float(counterex_items[i][1]) / len(props), 1) color = printer.getLatexColorCode( percent, [0., 50., 100.], ["darkred!50!white", "orange", "darkgreen"]) res += "{0} ({1})".format( counterex_items[i][0], r"\textbf{\textcolor{" + color + "}{" + str(percent) + "\%}}") # percentage of runs res += "}" return res
def entry_formatter_lambda(allSolutions, entryIndex): # entry = (name, best.testMSE) entry = allSolutions[entryIndex] value = float(entry[1]) valueSc = scientificNotationLatex(value) def nameFormatter(x): if "CDGP" in str(x): return r"\textcolor{darkblue}{" + str(x) + "}" elif x == "ALL": return r"\underline{ALL}" else: return x color = printer.getLatexColorCode(value, [allSolutions[0][1], (allSolutions[-1][1] + allSolutions[0][1]) / 2.0, allSolutions[-1][1]], ["darkgreen", "orange", "darkred!50!white"]) return "{0} ({1})".format(nameFormatter(entry[0]), r"\textbf{\textcolor{" + color + "}{" + str(valueSc) + "}}") # percentage of runs
def entry_formatter_lambda(allSolutions, entryIndex): # entry = (name, best.testMSE) entry = allSolutions[entryIndex] value = round(float(entry[1]), 2) def nameFormatter(x): if "CDGP" in str(x): return r"\textcolor{darkblue}{" + str(x) + "}" elif x == "ALL": return r"\underline{ALL}" else: return x color = printer.getLatexColorCode( value, [ allSolutions[-1][1], (allSolutions[-1][1] + allSolutions[0][1]) / 2.0, allSolutions[0][1] ], list(reversed(["darkgreen", "orange", "darkred!50!white"]))) return "{0} ({1})".format( nameFormatter(entry[0]), r"\textbf{\textcolor{" + color + "}{" + str(value) + "}}")
def entry_formatter_lambda(allSolutions, entryIndex): # solution = (bestOrig, bestOrig.size, best.isOptimal) solution = allSolutions[entryIndex] def latexTextColor(color, x): return r"\textbf{\textcolor{" + str(color) + "}{" + str(x) + "}}" value = round(float(solution[2]), 2) colorValue = printer.getLatexColorCode( value, [0.0, 0.5, 1.0], ["darkred!50!white", "orange", "darkgreen"]) size = int(solution[1]) sizeStr = r"\textcolor{darkblue}{\textbf{" + str(size) + r"}}" # colorSize = printer.getLatexColorCode(value, sizeColorScale, ["darkred!50!white", "orange", "darkgreen"]) sol = solution[0] sol = shortenLongConstants(sol) sol = sanitizeLatex(sol) sol = sol[:STR_LEN_LIMIT] + " [..]" if len( sol) > STR_LEN_LIMIT else sol sol = r"\texttt{" + sol + "}" return r"{0} ({1}) ({2})".format(sol, latexTextColor(colorValue, value), sizeStr)
def get_freqCounterexamples(props): if len(props) == 0: return "-" counterex = {} for p in props: # e.g. "ArrayBuffer((Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None), (Map(m1 -> 1.0, m2 -> 2.0, r -> 1.0),None) s = p["tests.collected"] # ?: - switches off the capturing effect cxs = re.findall( "\(Map\((?:[^,]+ -> [^,]+(?:, )?)+\),(?:Some\([^)]+\)+|None)\)", s) # ^ makes to match all charecters other than ',' # cxs = <class 'list'>: ['(Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None)', '(Map(m1 -> 1.0, m2 -> 2.0, r -> 1.0),None)'] used_keys = [] # safety for cx in cxs: # e.g. cx = (Map(m1 -> 0.0, m2 -> 0.0, r -> 0.0),None) # if "None" in cx: # we are interested only in the noncomplete tests if True: cx = cx[len("(Map("):-len(")")] # cx = 'm1 -> 0.0, m2 -> 0.0, r -> 0.0' fargs = re.findall( "[^,]+ -> [^,]+(?:, |[)])", cx) # findall returns non-overlapping matches in string for i in range(len(fargs)): x = fargs[i] if x[-1] == ")": x = x[:-1] x = x.replace(", ", "") fargs[i] = x fargs.sort(key=lambda a: a.split(" -> ")[0]) output = re.findall("(Some\([^)]+\)+|None)", cx)[0] sargs = ",".join(fargs).replace(" -> ", "=") + ";" + output if sargs not in used_keys: used_keys.append(sargs) else: print( "({0}) Warning: duplicate test case during a run! {1}" .format(p["evoplotter.file"], sargs)) if sargs in counterex: counterex[sargs] += 1 else: counterex[sargs] = 1 counterex_items = list(counterex.items()) if len(counterex_items) == 0: return "n/a" else: counterex_items.sort(key=lambda x: (x[1], x[0]), reverse=True) NUM_SHOWN = 7 # For some strange reason makecell doesn't work, even when it is a suggested answer (https://tex.stackexchange.com/questions/2441/how-to-add-a-forced-line-break-inside-a-table-cell) # return "\\makecell{" + "{0} ({1})\\\\{2} ({3})".format(counterex_items[0][0], counterex_items[0][1], # counterex_items[1][0], counterex_items[1][1]) + "}" res = "\\pbox[l][" + str( 17 * min(NUM_SHOWN, len(counterex_items))) + "pt][b]{20cm}{" for i in range(NUM_SHOWN): if i >= len(counterex_items): break if i > 0: res += "\\\\ \\ " test, numRuns = counterex_items[i] percent = round(100.0 * float(numRuns) / len(props), 1) color = printer.getLatexColorCode( percent, [0., 50., 100.], ["darkred!50!white", "orange", "darkgreen"]) txtTest = r"\texttt{" + sanitizeLatex(test) + "}" txtPercent = r"\textbf{\textcolor{" + color + "}{" + str( percent) + "\%}}" res += r"{0} ({1})".format(txtTest, txtPercent) # percentage of runs res += "}" return res