Пример #1
0
def test_random_valid_mutation_with_all(RandomForestPipeline, pset):
    """ Test if a valid mutation is applied at random.

    I am honestly not sure of the best way to test this.
    Because of the random nature, we repeat this enough times to ensure each mutation is tried with
    probability >0.99999.
    """

    applied_mutation = defaultdict(int)
    N = _min_trials(n_mutations=4)

    for i in range(N):
        ind_clone = RandomForestPipeline.copy_as_new()
        random_valid_mutation_in_place(ind_clone, pset)
        if _mut_shrink_is_applied(RandomForestPipeline, ind_clone)[0]:
            applied_mutation['shrink'] += 1
        elif _mut_insert_is_applied(RandomForestPipeline, ind_clone)[0]:
            applied_mutation['insert'] += 1
        elif _mut_replace_terminal_is_applied(RandomForestPipeline,
                                              ind_clone)[0]:
            applied_mutation['terminal'] += 1
        elif _mut_replace_primitive_is_applied(RandomForestPipeline,
                                               ind_clone)[0]:
            applied_mutation['primitive'] += 1
        else:
            assert False, "No mutation (or one that is unaccounted for) is applied."

    assert all([n > 0 for (mut, n) in applied_mutation.items()])
Пример #2
0
def test_random_valid_mutation_without_insert(RandomForestPipeline, pset):
    """ Test if a valid mutation is applied at random.

    I am honestly not sure of the best way to test this.
    Because of the random nature, we repeat this enough times to ensure each mutation is tried with
    probability >0.99999.
    """
    # The tested individual contains no terminals and one primitive,
    # and thus is not eligible for replace_terminal and mutShrink.
    # When specifying max_length=1 it is also not eligible for mut_insert
    applied_mutation = defaultdict(int)

    for i in range(_min_trials(n_mutations=3)):
        ind_clone = RandomForestPipeline.copy_as_new()
        random_valid_mutation_in_place(ind_clone, pset, max_length=2)
        if _mut_shrink_is_applied(RandomForestPipeline, ind_clone)[0]:
            applied_mutation['shrink'] += 1
        elif _mut_replace_terminal_is_applied(RandomForestPipeline,
                                              ind_clone)[0]:
            applied_mutation['terminal'] += 1
        elif _mut_replace_primitive_is_applied(RandomForestPipeline,
                                               ind_clone)[0]:
            applied_mutation['primitive'] += 1
        else:
            assert False, "No mutation (or one that is unaccounted for) is applied."

    assert all([n > 0 for (mut, n) in applied_mutation.items()])
Пример #3
0
def test_random_valid_mutation_without_terminal(GNB, pset):
    """ Test if a valid mutation is applied at random.

    I am honestly not sure of the best way to test this.
    Because of the random nature, we repeat this enough times to ensure
    each mutation is tried with probability >0.99999.
    """
    # The tested individual contains no terminals and one primitive,
    # and thus is not eligible for replace_terminal and mutShrink.
    applied_mutation = defaultdict(int)

    for i in range(_min_trials(n_mutations=2)):
        ind_clone = GNB.copy_as_new()
        random_valid_mutation_in_place(ind_clone, pset)
        if _mut_insert_is_applied(GNB, ind_clone)[0]:
            applied_mutation["insert"] += 1
        elif _mut_replace_primitive_is_applied(GNB, ind_clone)[0]:
            applied_mutation["primitive"] += 1
        else:
            assert False, "No mutation (or one that is unaccounted for) is applied."

    assert all([count > 0 for (mut, count) in applied_mutation.items()])
Пример #4
0
def test_random_valid_mutation_without_shrink(LinearSVC, pset):
    """ Test if a valid mutation is applied at random.

    I am honestly not sure of the best way to test this.
    Because of the random nature, we repeat this enough times to ensure
    each mutation is tried with probability >0.99999.
    """

    applied_mutation = defaultdict(int)

    for i in range(_min_trials(n_mutations=3)):
        ind_clone = LinearSVC.copy_as_new()
        random_valid_mutation_in_place(ind_clone, pset)
        if _mut_insert_is_applied(LinearSVC, ind_clone)[0]:
            applied_mutation["insert"] += 1
        elif _mut_replace_terminal_is_applied(LinearSVC, ind_clone)[0]:
            applied_mutation["terminal"] += 1
        elif _mut_replace_primitive_is_applied(LinearSVC, ind_clone)[0]:
            applied_mutation["primitive"] += 1
        else:
            assert False, "No mutation (or one that is unaccounted for) is applied."

    assert all([count > 0 for (mut, count) in applied_mutation.items()])