コード例 #1
0
def test_trace():
    from EvoDAG import RootGP
    from EvoDAG.node import Add
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    Add.nargs = 3
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                function_set=[Add],
                classifier=False,
                early_stopping_rounds=-1,
                seed=0,
                popsize=4)
    gp.X = X[:-10]
    gp.Xtest = X[-10:]
    gp.y = y[:-10]
    gp.create_population()
    a = gp.random_offspring()
    gp.population.replace(a)
    print(a.position, a.variable, a._weight, gp.population.hist[0].variable)
    s = gp.trace(a)
    print(len(s), s)
    assert a._weight.shape[0] + 1 == len(s)
コード例 #2
0
def test_replace_individual():
    from EvoDAG import RootGP
    gp = RootGP(generations=1, tournament_size=2, classifier=False, popsize=5)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    print(gp.population.popsize)
    a = gp.random_offspring()
    assert a.position == 0
    gp.population.replace(a)
    assert np.any([x == a for x in gp.population.population])
    print(a.position, len(gp.population.population))
    assert a.position == len(gp.population.population)
コード例 #3
0
ファイル: test_root.py プロジェクト: mgraffg/EvoDAG
def test_fit_stopping_criteria_estopping():
    from EvoDAG import RootGP
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                early_stopping_rounds=4,
                seed=0,
                popsize=4)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    while not gp.stopping_criteria():
        a = gp.random_offspring()
        gp.population.replace(a)
    print(len(gp.population.hist) - gp.population.estopping.position)
    assert (len(gp.population.hist) - gp.population.estopping.position) <= 9
コード例 #4
0
ファイル: test_root.py プロジェクト: mgraffg/EvoDAG
def test_replace_individual():
    from EvoDAG import RootGP
    gp = RootGP(generations=1,
                tournament_size=2,
                popsize=5)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    print(gp.population.popsize)
    a = gp.random_offspring()
    assert a.position == 0
    gp.population.replace(a)
    assert np.any([x == a for x in gp.population.population])
    print(a.position, len(gp.population.population))
    assert a.position == len(gp.population.population)
コード例 #5
0
ファイル: test_root.py プロジェクト: pombredanne/EvoDAG
def test_fit_stopping_criteria_estopping():
    from EvoDAG import RootGP
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                early_stopping_rounds=4,
                classifier=False,
                seed=0,
                popsize=4)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    while not gp.stopping_criteria():
        a = gp.random_offspring()
        gp.population.replace(a)
    print(len(gp.population.hist) - gp.population.estopping.position)
    assert (len(gp.population.hist) - gp.population.estopping.position) <= 9
コード例 #6
0
ファイル: test_root.py プロジェクト: mgraffg/EvoDAG
def test_fit_stopping_criteria_gens():
    from EvoDAG import RootGP
    from EvoDAG.node import Add
    Add.nargs = 2
    gp = RootGP(generations=2,
                early_stopping_rounds=None,
                tournament_size=2,
                seed=1,
                popsize=4)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    for i in range(gp.popsize):
        assert not gp.stopping_criteria()
        a = gp.random_offspring()
        gp.population.replace(a)
    assert gp.stopping_criteria()
コード例 #7
0
ファイル: test_root.py プロジェクト: mgraffg/EvoDAG
def test_random_offspring():
    from EvoDAG import RootGP
    from EvoDAG.node import Add
    gp = RootGP(generations=1,
                seed=1,
                tournament_size=2,
                popsize=10)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    randint = np.random.randint
    mock = MagicMock(return_value=0)
    np.random.randint = mock
    a = gp.random_offspring()
    np.random.randint.assert_called_with(len(gp.function_set))
    assert isinstance(a, Add)
    assert np.isfinite(a.fitness)
    np.random.randint = randint
コード例 #8
0
ファイル: test_root.py プロジェクト: pombredanne/EvoDAG
def test_fit_stopping_criteria_gens():
    from EvoDAG import RootGP
    from EvoDAG.node import Add
    Add.nargs = 2
    gp = RootGP(generations=2,
                early_stopping_rounds=None,
                tournament_size=2,
                classifier=False,
                seed=1,
                popsize=4)
    gp.X = X
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gp.y = y
    gp.create_population()
    for i in range(gp.popsize):
        assert not gp.stopping_criteria()
        a = gp.random_offspring()
        gp.population.replace(a)
    assert gp.stopping_criteria()
コード例 #9
0
ファイル: test_root.py プロジェクト: mgraffg/EvoDAG
def test_trace():
    from EvoDAG import RootGP
    from EvoDAG.node import Add
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    Add.nargs = 3
    gp = RootGP(generations=np.inf,
                tournament_size=2,
                function_set=[Add],
                early_stopping_rounds=-1,
                seed=0,
                popsize=4)
    gp.X = X[:-10]
    gp.Xtest = X[-10:]
    gp.y = y[:-10]
    gp.create_population()
    a = gp.random_offspring()
    gp.population.replace(a)
    print(a.position, a.variable, a._weight, gp.population.hist[0].variable)
    s = gp.trace(a)
    assert len(s) == 4