Пример #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 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)
Пример #3
0
def evol_alg():
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(NumberGenerator(-1))
    selection = Tournament(SELECTION_SIZE)
    fitness = MultipleValueFitnessFunction()
    evaluator = Evaluation(fitness)
    return MuPlusLambda(evaluator, selection, crossover, mutation, 0.2, 0.4,
                        OFFSPRING_SIZE)
Пример #4
0
def ev_alg(full_training_data):
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(np.random.random)
    selection = Tournament(2)
    fitness = DistanceToAverage(full_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)
Пример #6
0
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)

    island.evolve(1)
    report_max_min_mean_fitness(island)
    island.evolve(500)
    report_max_min_mean_fitness(island)
Пример #9
0
def test_island_hof(mocker):
    hof = mocker.Mock()
    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)
    island = Island(ev_alg, generator, 25, hall_of_fame=hof)

    island.evolve(10)

    hof.update.assert_called_once()
    hof_update_pop = hof.update.call_args[0][0]
    for h, i in zip(hof_update_pop, island.population):
        assert h == i
Пример #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
Пример #12
0
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
Пример #13
0
def dc_ea(onemax_evaluator):
    crossover = SinglePointCrossover()
    mutation = SinglePointMutation(return_true)
    return DeterministicCrowdingEA(onemax_evaluator, crossover, mutation, 0.2,
                                   0.2)