How to use the deap.algorithms.eaSimple function in deap

To help you get started, we’ve selected a few deap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EpistasisLab / pennai / learn / deapGP / main.py View on Github external
key=operator.attrgetter("height"), max_value=17))
    toolbox.decorate("mutate", gp.staticLimit(
        key=operator.attrgetter("height"), max_value=17))

    pop = toolbox.population(n=population_size)  # population_size arguments
    hof = tools.HallOfFame(1)

    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", numpy.mean)
    mstats.register("std", numpy.std)
    mstats.register("min", numpy.min)
    mstats.register("max", numpy.max)

    pop, log = algorithms.eaSimple(pop, toolbox, cxpb=crossover_rate,
                                   mutpb=mutation_rate, ngen=generations, stats=mstats, halloffame=hof, verbose=False)  # crossover_rate, mutation_rate, generations
    stats_table = []
    statslist = ["avg", "max", "min", "std"]
    statsterm = ["fitness", "size"]
    # make header
    stats_table_header = []
    stats_table_header.append('gen')
    stats_table_header.append('nevals')
    for j in range(len(statsterm)):
        for p in range(len(statslist)):
            stats_table_header.append(statsterm[j] + '_' + statslist[p])
    for i in range(generations + 1):
        stats_table.append([log[i]['gen'], log[i]['nevals']])
        for j in range(len(statsterm)):
            for p in range(len(statslist)):
                stats_table[i].append(
github rsteca / sklearn-deap / evolutionary_search / optimize.py View on Github external
stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.nanmean)
    stats.register("min", np.nanmin)
    stats.register("max", np.nanmax)
    stats.register("std", np.nanstd)

    # History
    hist = tools.History()
    toolbox.decorate("mate", hist.decorator)
    toolbox.decorate("mutate", hist.decorator)
    hist.update(pop)

    if verbose:
        print('--- Evolve in {0} possible combinations ---'.format(np.prod(np.array(maxints) + 1)))

    pop, logbook = algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2,
                                       ngen=generations_number, stats=stats,
                                       halloffame=hof, verbose=verbose)

    current_best_score_ = hof[0].fitness.values[0]
    current_best_params_ = _individual_to_params(hof[0], name_values)

    # Generate score_cache with real parameters
    _, individuals, each_scores = zip(*[(idx, indiv, np.mean(indiv.fitness.values))
                                    for idx, indiv in list(hist.genealogy_history.items())
                                    if indiv.fitness.valid and not np.all(np.isnan(indiv.fitness.values))])
    unique_individuals = {str(indiv): (indiv, score) for indiv, score in zip(individuals, each_scores)}
    score_results = tuple([(_individual_to_params(indiv, name_values), score)
                         for indiv, score in unique_individuals.values()])

    if verbose:
        print("Best individual is: %s\nwith fitness: %s" % (
github DEAP / deap / examples / gp / parity.py View on Github external
def main():
    random.seed(21)
    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)
    
    algorithms.eaSimple(pop, toolbox, 0.5, 0.2, 40, stats, halloffame=hof)
    
    return pop, stats, hof
github DEAP / deap / examples / gp / gp_symbreg.py View on Github external
def main():
    random.seed(318)

    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(fitness=lambda ind: ind.fitness.values,
                                size=lambda ind: len(ind))
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)
    
    algorithms.eaSimple(pop, toolbox, 0.5, 0.1, 40, stats, halloffame=hof)

    infos = stats.select('gen', fitness=['avg'], size=['avg', 'std'])
    print(infos['gen'])
    print(infos['fitness'])
    print(zip(*infos['size']))
    
    return pop, stats, hof
github DEAP / deap / examples / gp / ant.py View on Github external
def main():
    random.seed(69)
    
    with  open("ant/santafe_trail.txt") as trail_file:
      ant.parse_matrix(trail_file)
    
    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)
    
    algorithms.eaSimple(pop, toolbox, 0.5, 0.2, 40, stats, halloffame=hof)
    
    return pop, hof, stats
github DEAP / deap / examples / gp / multiplexer.py View on Github external
def main():
#    random.seed(10)
    pop = toolbox.population(n=40)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)
    
    algorithms.eaSimple(pop, toolbox, 0.8, 0.1, 40, stats, halloffame=hof)
    
    return pop, stats, hof
github llens / QuantumComputingEvolutionaryAlgorithmDesign / Archive / evolutionary_algorithm.py View on Github external
toolbox.register(
        "evaluate", evaluate_quantum_algorithm, input_set=input_set, target_set=target_set, gates=gates)
    toolbox.register("mate", tools.cxTwoPoint)
    toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)
    toolbox.register("select", tools.selTournament, tournsize=3)

    pop = toolbox.population(n=500)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("avg", np.mean)
    stats.register("std", np.std)
    stats.register("min", np.min)
    stats.register("max", np.max)

    algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.5, ngen=50, stats=stats, halloffame=hof, verbose=True)

    print 'Best individual:'
    output_quantum_gates(dna_to_gates(list(hof[0]), gates))

    run_quantum_algorithm_over_set(input_set, target_set, gates, dna_to_gates(list(hof[0]), gates))
github DEAP / deap / examples / ga / nqueens.py View on Github external
def main(seed=0):
    random.seed(seed)

    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    stats = tools.Statistics(lambda ind: ind.fitness.values)
    stats.register("Avg", numpy.mean)
    stats.register("Std", numpy.std)
    stats.register("Min", numpy.min)
    stats.register("Max", numpy.max)

    algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=100, stats=stats,
                        halloffame=hof, verbose=True)

    return pop, stats, hof
github DEAP / deap / examples / gp / symbreg.py View on Github external
def main():
    random.seed(318)

    pop = toolbox.population(n=300)
    hof = tools.HallOfFame(1)
    
    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", numpy.mean)
    mstats.register("std", numpy.std)
    mstats.register("min", numpy.min)
    mstats.register("max", numpy.max)

    pop, log = algorithms.eaSimple(pop, toolbox, 0.5, 0.1, 40, stats=mstats,
                                   halloffame=hof, verbose=True)
    # print log
    return pop, log, hof