Example #1
0
def test_ensemble_model():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gps = [
        RootGP(generations=np.inf,
               tournament_size=2,
               early_stopping_rounds=-1,
               classifier=False,
               seed=seed,
               popsize=10).fit(X[:-10], y[:-10], test_set=X)
        for seed in range(3)
    ]
    ens = Ensemble([gp.model() for gp in gps])
    res = [gp.decision_function() for gp in gps]
    res = np.median([x.full_array() for x in res], axis=0)
    res = SparseArray.fromlist(res)
    print(res)
    # res = Add.cumsum(res) * (1 / 3.)
    r2 = ens.decision_function(None)
    print(res.full_array()[:10], r2.full_array()[:10])
    print(res.SSE(r2))
    assert res.SSE(r2) == 0
Example #2
0
def test_regression():
    from EvoDAG import RootGP
    from EvoDAG.sparse_array import SparseArray
    from EvoDAG.model import Ensemble
    x = np.linspace(-1, 1, 100)
    y = 4.3*x**2 + 3.2 * x - 3.2
    gps = [RootGP(classifier=False,
                  seed=seed,
                  popsize=10,
                  generations=2).fit([SparseArray.fromlist(x)], y,
                                     test_set=[SparseArray.fromlist(x)])
           for seed in range(3)]
    ens = Ensemble([gp.model() for gp in gps])
    hy = np.median([gp.predict() for gp in gps], axis=0)
    hy1 = ens.predict(X=[SparseArray.fromlist(x)])
    assert np.all(hy == hy1)
Example #3
0
def test_init_regression():
    from EvoDAG.model import Ensemble
    m = Ensemble.init(n_estimators=4, n_jobs=4, seed=10,
                      classifier=False).fit(X, cl)
    hy = m.predict(X)
    assert np.unique(hy).shape[0] > 3
    default_nargs()
Example #4
0
def test_init2():
    from EvoDAG.model import Ensemble
    m = Ensemble.init(n_estimators=4, n_jobs=1, seed=10, early_stopping_rounds=100).fit(X, cl)
    hy = m.predict(X)
    print((cl == hy).mean(), cl, hy)
    assert (cl == hy).mean() > 0.9
    default_nargs()
Example #5
0
def test_init2():
    from EvoDAG.model import Ensemble
    m = Ensemble.init(n_estimators=4, n_jobs=1, seed=10).fit(X, cl)
    hy = m.predict(X)
    print([x.full_array() for x in m.decision_function(X)])
    print((cl == hy).mean(), cl, hy)
    assert (cl == hy).mean() > 0.9
    default_nargs()
Example #6
0
def test_regression():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    x = np.linspace(-1, 1, 100)
    y = 4.3 * x**2 + 3.2 * x - 3.2
    gps = [
        RootGP(classifier=False, seed=seed, popsize=10,
               generations=2).fit([SparseArray.fromlist(x)],
                                  y,
                                  test_set=[SparseArray.fromlist(x)])
        for seed in range(3)
    ]
    ens = Ensemble([gp.model() for gp in gps])
    hy = np.median([gp.predict() for gp in gps], axis=0)
    hy1 = ens.predict(X=[SparseArray.fromlist(x)])
    print(hy, hy1)
    assert np.all(hy == hy1)
Example #7
0
def test_multiple_outputs_ensemble():
    from EvoDAG import EvoDAG
    from EvoDAG.model import Ensemble
    y = cl.copy()
    gp = [EvoDAG(generations=np.inf,
                 tournament_size=2,
                 multiple_outputs=True,
                 early_stopping_rounds=-1,
                 seed=x,
                 popsize=10).fit(X[:-10], y[:-10], test_set=X[-10:])
          for x in range(2)]
    ens = Ensemble([x.model() for x in gp])
    assert ens.multiple_outputs
    hy = ens.predict(X)
    u = np.unique(y)
    for i in np.unique(hy):
        assert i in u
Example #8
0
def test_regression():
    from EvoDAG import EvoDAG as evodag
    from EvoDAG.model import Ensemble
    x = np.linspace(-1, 1, 100)
    y = 4.3*x**2 + 3.2 * x - 3.2
    gps = [evodag.init(classifier=False,
                       seed=seed,
                       popsize=10,
                       generations=2).fit([SparseArray.fromlist(x)], y,
                                          test_set=[SparseArray.fromlist(x)])
           for seed in range(3)]
    model = [_.model() for _ in gps]
    ens = Ensemble(model)
    X = [SparseArray.fromlist(x)]
    hy = np.median([m.decision_function(X).finite().full_array() for m in model], axis=0)
    hy1 = ens.predict(X)
    print(hy, hy1)
    assert np.all(hy == hy1)
Example #9
0
def test_ensemble():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    y = cl.copy()
    gps = [RootGP(generations=np.inf,
                  tournament_size=2,
                  early_stopping_rounds=-1,
                  seed=seed,
                  multiple_outputs=True,
                  popsize=10).fit(X[:-10],
                                  y[:-10],
                                  test_set=X)
           for seed in range(2, 5)]
    ens = Ensemble([gp.model() for gp in gps])
    res = [gp.model().decision_function(X) for gp in gps]
    res = np.array([np.median([x[j].finite().full_array() for x in res], axis=0) for j in range(3)]).T
    r2 = ens.decision_function(X)
    print(res, r2)
    assert np.fabs(res - r2).sum() == 0
Example #10
0
def test_ensemble():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    from EvoDAG.node import Add
    y = cl.copy()
    gps = [RootGP(generations=np.inf,
                  tournament_size=2,
                  early_stopping_rounds=-1,
                  seed=seed,
                  popsize=10).fit(X[:-10],
                                  y[:-10],
                                  test_set=X)
           for seed in range(2, 5)]
    ens = Ensemble([gp.model() for gp in gps])
    res = [gp.decision_function() for gp in gps]
    res = [Add.cumsum([x[j] for x in res]) for j in range(3)]
    res = [x / 3. for x in res]
    r2 = ens.decision_function(None)
    for a, b in zip(res, r2):
        assert a.SSE(b) == 0
    r2 = ens.predict(None)
Example #11
0
def test_ensemble():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    from EvoDAG.node import Add
    y = cl.copy()
    gps = [
        RootGP(generations=np.inf,
               tournament_size=2,
               early_stopping_rounds=-1,
               seed=seed,
               multiple_outputs=True,
               popsize=10).fit(X[:-10], y[:-10], test_set=X)
        for seed in range(2, 5)
    ]
    ens = Ensemble([gp.model() for gp in gps])
    res = [gp.decision_function() for gp in gps]
    res = [Add.cumsum([x[j] for x in res]) for j in range(3)]
    res = [x * (1 / 3.) for x in res]
    r2 = ens.decision_function(None)
    for a, b in zip(res, r2):
        print(a.SSE(b), a.data, b.data, b.full_array())
        assert a.SSE(b) == 0
Example #12
0
def test_ensemble_model():
    from EvoDAG.model import EvoDAG as evodag
    from EvoDAG.model import Ensemble
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gps = [
        evodag(generations=np.inf,
               tournament_size=2,
               early_stopping_rounds=-1,
               classifier=False,
               seed=seed,
               popsize=10).fit(X[:-10], y[:-10], test_set=X)
        for seed in range(3)
    ]
    ens = Ensemble([gp.model for gp in gps])
    res = [gp.decision_function(X) for gp in gps]
    res = np.median([x.finite().full_array() for x in res], axis=0)
    r2 = ens.decision_function(X)
    print(res, r2)
    assert np.fabs(res - r2).mean() == 0
Example #13
0
def test_ensemble_model():
    from EvoDAG import RootGP
    from EvoDAG.model import Ensemble
    from EvoDAG.node import Add
    y = cl.copy()
    mask = y == 0
    y[mask] = 1
    y[~mask] = -1
    gps = [RootGP(generations=np.inf,
                  tournament_size=2,
                  early_stopping_rounds=-1,
                  seed=seed,
                  popsize=10).fit(X[:-10],
                                  y[:-10],
                                  test_set=X)
           for seed in range(3)]
    ens = Ensemble([gp.model() for gp in gps])
    res = [gp.decision_function() for gp in gps]
    res = Add.cumsum(res) / 3
    r2 = ens.decision_function(None)
    assert res.SSE(r2) == 0
    a = SparseArray.fromlist(ens.predict(None))
    assert r2.sign().SSE(a) == 0
Example #14
0
def test_init():
    from EvoDAG.model import Ensemble
    m = Ensemble.init(n_estimators=4, n_jobs=4, seed=10).fit(X, cl)
    hy = m.predict(X)
    assert (cl == hy).mean() > 0.9
    default_nargs()