Пример #1
0
def comma_algo(add_e_evaluation, add_v_variation, add_s_selection):
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    evo_alg = MuCommaLambda(add_e_evaluation, add_s_selection, crossover,
                            mutation, 0.2, 0.4, 20)
    evo_alg.variation = add_v_variation
    return evo_alg
Пример #2
0
def evol_alg():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    selection = Tournament(SELECTION_SIZE)
    fitness = MultipleValueFitnessFunction()
    evaluator = Evaluation(fitness)
    return MuPlusLambda(evaluator, selection, crossover, mutation, 0.2, 0.4,
                        OFFSPRING_SIZE)
Пример #3
0
def test_just_replication(population):
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    var_or_instance = VarOr(crossover, mutation, 0.0, 0.0)
    _ = var_or_instance(population, 25)
    for cross, mut in zip(var_or_instance.crossover_offspring,
                          var_or_instance.mutation_offspring):
        assert not (cross or mut)
def ev_alg():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(np.random.random)
    selection = Tournament(2)
    training_data = np.linspace(0.1, 1, FULL_TRAINING_DATA_SIZE)
    fitness = DistanceToAverage(training_data)
    evaluator = Evaluation(fitness)
    return MuPlusLambda(evaluator, selection, crossover, mutation,
                        0., 1.0, MAIN_POPULATION_SIZE)
Пример #5
0
def island():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    selection = Tournament(10)
    fitness = MultipleValueFitnessFunction()
    evaluator = Evaluation(fitness)
    ev_alg = MuPlusLambda(evaluator, selection, crossover, mutation, 0.2, 0.4,
                          20)
    generator = MultipleValueChromosomeGenerator(mutation_function, 10)
    return Island(ev_alg, generator, 25)
def test_mutation_is_single_point():
    mutator = SinglePointMutation(mutation_onemax_specific)
    parent = MultipleValueChromosome(
        [np.random.choice([True, False]) for _ in range(10)])
    child = mutator(parent)
    discrepancies = 0
    for i in range(len(parent.values)):
        if child.values[i] != parent.values[i]:
            discrepancies += 1

    assert discrepancies <= 1
Пример #7
0
def create_evolutionary_algorithm():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(generate_0_or_1)
    variation_phase = VarOr(crossover, mutation, crossover_probability=0.4,
                            mutation_probability=0.4)

    fitness = OneMaxFitnessFunction()
    evaluation_phase = Evaluation(fitness)

    selection_phase = Tournament(tournament_size=2)

    return EvolutionaryAlgorithm(variation_phase, evaluation_phase,
                                 selection_phase)
Пример #8
0
def main():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(get_random_float)
    selection = Tournament(10)
    fitness = ZeroMinFitnessFunction()
    local_opt_fitness = ContinuousLocalOptimization(fitness)
    evaluator = Evaluation(local_opt_fitness)
    ea = MuPlusLambda(evaluator, selection, crossover, mutation, 0.4, 0.4, 20)
    generator = MultipleFloatChromosomeGenerator(get_random_float, 8)
    island = Island(ea, generator, 25)

    best_indv_values = []
    best_indv_values.append(island.best_individual().values)
    for i in range(500):
        island.execute_generational_step()
        best_indv_values.append(island.best_individual().values)

    bingo.animation.animate_data(best_indv_values)
Пример #9
0
def main():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(get_random_float)
    selection = Tournament(10)
    fitness = ZeroMinFitnessFunction()
    local_opt_fitness = ContinuousLocalOptimization(fitness)
    evaluator = Evaluation(local_opt_fitness)
    ea = MuPlusLambda(evaluator, selection, crossover, mutation, 0.4, 0.4, 20)
    generator = MultipleFloatChromosomeGenerator(get_random_float, 8)
    island = Island(ea, generator, 25)
    for i in range(25):
        island.execute_generational_step()
        print("\nGeneration #", i)
        print("-" * 80, "\n")
        report_max_min_mean_fitness(island.population)
        print("\npopulation: \n")
        for indv in island.population:
            print(["{0:.2f}".format(val) for val in indv.values])
Пример #10
0
def test_invalid_probabilities():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    with pytest.raises(ValueError):
        _ = VarOr(crossover, mutation, 0.6, 0.41)
Пример #11
0
def var_or():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(mutation_function)
    var_or_instance = VarOr(crossover, mutation, 0.2, 0.4)
    return var_or_instance
def test_fitness_is_not_inherited_mutation():
    mutator = SinglePointMutation(mutation_onemax_specific)
    parent = MultipleValueChromosome(
        [np.random.choice([True, False]) for _ in range(10)])
    child = mutator(parent)
    assert not child.fit_set
def dc_ea(onemax_evaluator):
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(return_true)
    return DeterministicCrowdingEA(onemax_evaluator, crossover, mutation, 0.2,
                                   0.2)