def main(n_corr, p): energy_coolng(n_corr, p) pop_size=500 #toolbox.register("select",selElitistAndTournament, k_elitist=int(0.1*pop_size), k_tournament=pop_size - int(0.1*pop_size), tournsize=3) toolbox.register("select",tools.selTournament, tournsize=3) toolbox.register("mate", gp.cxOnePoint) toolbox.register("expr_mut", gp.genFull, min_=0, max_=3) toolbox.register("mutate", gp.mutUniform, expr=toolbox.expr_mut, pset=pset) toolbox.decorate("mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) toolbox.decorate("mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) pop = toolbox.population(n=pop_size) hof = tools.HallOfFame(3) stats_fit = tools.Statistics(lambda ind: ind.fitness.values) stats_size = tools.Statistics(len) mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size) mstats.register("avg", np.mean) mstats.register("std", np.std) mstats.register("min", np.min) mstats.register("max", np.max) cxpb = 0.7 mutpb = 0.3 ngen = 100 params = ['best_of_each_specie', 2, 'yes'] neat_cx = True neat_alg = True neat_pelit = 0.5 neat_h = 0.15 problem = "EnergyCooling" pop, log = eaneatGP.neat_GP(pop, toolbox, cxpb, mutpb, ngen, neat_alg, neat_cx, neat_h, neat_pelit, n_corr, p, params, problem, stats=mstats, halloffame=hof, verbose=True) #pop, log = algorithms.eaSimple(pop, toolbox, cxpb, mutpb, ngen, problem, p, n_corr,stats=mstats, halloffame=hof, verbose=True) return pop, log, hof
def main(n_corr, num_p): problem = "BreastCancer" name_database = "breast-cancer-wisconsin" pop_size = 100 energy_coolng(n_corr, num_p, problem, name_database) toolbox.register("select", tools.selTournament, tournsize=3) toolbox.register("mate", neat_gp.cxSubtree) toolbox.register("expr_mut", gp.genFull, min_=0, max_=3) toolbox.register("mutate", gp.mutUniform, expr=toolbox.expr_mut, pset=pset) toolbox.decorate( "mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) toolbox.decorate( "mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) pop = toolbox.population(n=pop_size) hof = tools.HallOfFame(3) stats_fit = tools.Statistics(lambda ind: ind.fitness.values) stats_size = tools.Statistics(len) mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size) mstats.register("avg", np.mean) mstats.register("std", np.std) mstats.register("min", np.min) mstats.register("max", np.max) cxpb = 0.7 mutpb = 0.3 ngen = 100 params = ['best_of_each_specie', 2, 'yes'] neat_cx = True neat_alg = True neat_pelit = 0.5 neat_h = 0.15 neat_beta = 0.5 pop, log = eaneatGP.neat_GP(pop, toolbox, cxpb, mutpb, ngen, neat_alg, neat_cx, neat_h, neat_pelit, n_corr, num_p, params, problem, neat_beta, stats=mstats, halloffame=hof, verbose=True) return pop, log, hof
def main(n_corr, num_p): problem = "EnergyCooling" name_database="energy_efficiency_Cooling" pop_size = 500 energy_coolng(n_corr, num_p, problem, name_database) toolbox.register("select",tools.selTournament, tournsize=3) toolbox.register("mate", neat_gp.cxSubtree) toolbox.register("expr_mut", gp.genFull, min_=0, max_=3) toolbox.register("mutate", gp.mutUniform, expr=toolbox.expr_mut, pset=pset) toolbox.decorate("mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) toolbox.decorate("mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) pop = toolbox.population(n=pop_size) hof = tools.HallOfFame(3) stats_fit = tools.Statistics(lambda ind: ind.fitness.values) stats_size = tools.Statistics(len) mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size) mstats.register("avg", np.mean) mstats.register("std", np.std) mstats.register("min", np.min) mstats.register("max", np.max) cxpb = 0.7 mutpb = 0.3 ngen = 100 params = ['best_of_each_specie', 2, 'yes'] neat_cx = False neat_alg = False neat_pelit = 0.5 neat_h = 0.15 pop, log = eaneatGP.neat_GP(pop, toolbox, cxpb, mutpb, ngen, neat_alg, neat_cx, neat_h, neat_pelit, n_corr, num_p, params, problem, stats=mstats, halloffame=hof, verbose=True) return pop, log, hof
def main(n_corr, p, problem, database_name, pset, config): pop_size = config["population_size"] cxpb = config["cxpb"] # 0.9 mutpb = config["mutpb"] # 0.1 tournament_size = config["tournament_size"] ngen = config["generations"] params = ['best_of_each_specie', 2, 'yes'] neat_cx = config["neat_cx"] neat_alg = config["neat_alg"] neat_pelit = config["neat_pelit"] neat_h = config["neat_h"] beta = config["neat_beta"] creator.create("FitnessMin", base.Fitness, weights=(-1.0, )) creator.create("FitnessTest", base.Fitness, weights=(-1.0, )) creator.create("Individual", neat_gp.PrimitiveTree, fitness=creator.FitnessMin, fitness_test=creator.FitnessTest) toolbox = base.Toolbox() if neat_cx: toolbox.register("expr", gp.genFull, pset=pset, min_=0, max_=3) else: toolbox.register("expr", gp.genHalfAndHalf, pset=pset, min_=0, max_=7) toolbox.register("individual", tools.initIterate, creator.Individual, toolbox.expr) toolbox.register("population", init_conf.initRepeat, list, toolbox.individual) toolbox.register("compile", gp.compile, pset=pset) name_database = database_name direccion = "./data_corridas/%s/train_%d_%d.txt" train_test(n_corr, p, problem, name_database, toolbox, config) toolbox.register("select", tools.selTournament, tournsize=tournament_size) toolbox.register("mate", neat_gp.cxSubtree) if neat_cx: toolbox.register("expr_mut", gp.genFull, min_=0, max_=3) else: toolbox.register("expr_mut", gp.genHalfAndHalf, min_=0, max_=7) toolbox.register("mutate", neat_gp.mutUniform, expr=toolbox.expr_mut, pset=pset) toolbox.decorate( "mate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) toolbox.decorate( "mutate", gp.staticLimit(key=operator.attrgetter("height"), max_value=17)) pop = toolbox.population(n=pop_size) hof = tools.HallOfFame(3) stats_fit = tools.Statistics(lambda ind: ind.fitness.values) stats_size = tools.Statistics(len) mstats = tools.MultiStatistics(fitness=stats_fit, size=stats_size) mstats.register("avg", np.mean) mstats.register("std", np.std) mstats.register("min", np.min) mstats.register("max", np.max) pop, log = eaneatGP.neat_GP(pop, toolbox, cxpb, mutpb, ngen, neat_alg, neat_cx, neat_h, neat_pelit, n_corr, p, params, problem, beta, stats=mstats, halloffame=hof, verbose=True) return pop, log, hof