def test_obj(): k = lambda x:MagicMock(fitness=MagicMock(values=x)) assert soft_maximum_worst_case(MagicMock(fitness=MagicMock(values=[1, -1.1]))) < soft_maximum_worst_case(MagicMock(fitness=MagicMock(values=[0.1, -0.1]))) assert soft_maximum_worst_case(k([17, -5])) < soft_maximum_worst_case(MagicMock(fitness=MagicMock(values=[7, 5]))) print(soft_maximum_worst_case(k([10, 10, 10, 2, 10])), soft_maximum_worst_case(k([1, 1, 1, 1, 1]))) assert soft_maximum_worst_case(k([10, 10, 10, -10, 10])) < soft_maximum_worst_case(k([1, 1, 1, 1, 1])) assert soft_maximum_worst_case(k([-100, -100])) < soft_maximum_worst_case(k([1, 1, 1, 1, 1]))
def statsa(): stats = Statistics(key=lambda ind: soft_maximum_worst_case(ind)) stats.register("avg", numpy.mean) stats.register("std", numpy.std) stats.register("min", numpy.min) stats.register("max", numpy.max) stats.register("len", len) return stats
def statsa(): stats = Statistics(key=lambda ind: soft_maximum_worst_case(ind)) stats.register("avg", numpy.mean) stats.register("std", numpy.std) stats.register("min", numpy.min) stats.register("max", numpy.max) stats.register("len", len) return stats
def draw(history): ax = plt.figure() ax.set_figheight(30) ax.set_figwidth(30) graph = networkx.DiGraph(history.genealogy_tree) graph = graph.reverse() # Make the grah top-down colors_inds = (history.genealogy_history[i] for i in graph) colors = [soft_maximum_worst_case(ind) if ind.fitness.valid else -10 for ind in colors_inds] positions = networkx.drawing.nx_agraph.graphviz_layout(graph, prog="dot") networkx.draw(graph, positions, node_color=colors, ax=ax.add_subplot(111), figsize=(30, 30), node_size=150) ax.savefig('{path}/zen/logs/history/{runid}.png'.format(path=path, runid=runid))
def draw(history, toolbox): ax = plt.figure() ax.set_figheight(30) ax.set_figwidth(30) graph = networkx.DiGraph(history.genealogy_tree) graph = graph.reverse() # Make the grah top-down colors_inds = (history.genealogy_history[i] for i in graph) colors = [soft_maximum_worst_case(ind) if ind.fitness.valid else -10 for ind in colors_inds] positions = networkx.drawing.nx_agraph.graphviz_layout(graph, prog="dot") networkx.draw(graph, positions, node_color=colors, ax=ax.add_subplot(111), figsize=(30, 30), node_size=150) ax.savefig('logs/history/{runid}.png'.format(runid=runid))
def objective(self): return soft_maximum_worst_case(self)
def objective(self): return soft_maximum_worst_case(self)