Beispiel #1
0
def test_epsilon_lexicase_shapes():
    """test_selection.py: epsilon lexicase selection returns correct shape"""
    np.random.seed(42)
    few = FEW(seed_with_ml=False, population_size=257, lex_size=False)
    few.term_set = [node('x', loc=0)]
    pop = few.init_pop()
    offspring = few.epsilon_lexicase(np.random.rand(257, 100), [])
    assert len(offspring) == 257

    # smaller popsize than tournament size
    few = FEW(seed_with_ml=False, population_size=2, lex_size=False)
    few.term_set = [node('x', loc=0)]
    pop = few.init_pop()
    offspring = few.epsilon_lexicase(np.random.rand(2, 100), [])
    assert len(offspring) == 2
Beispiel #2
0
def test_lex_size():
    """test_selection.py: lex_size flag on/off"""

    few = FEW(seed_with_ml=False, population_size=257, lex_size=True)

    Fitness_mat = np.random.rand(257, 10)
    size_mat = np.random.randint(1, 100, size=257)

    locs = few.epsilon_lexicase(Fitness_mat,
                                size_mat,
                                num_selections=100,
                                survival=True)
    assert len(locs) == 100

    few = FEW(seed_with_ml=False, population_size=257, lex_size=False)

    Fitness_mat = np.random.rand(257, 10)
    size_mat = np.random.rand(257, 1)

    locs = few.epsilon_lexicase(Fitness_mat,
                                size_mat,
                                num_selections=100,
                                survival=True)
    assert len(locs) == 100