Ejemplo n.º 1
0
def test_node_hash():
    from EvoDAG.node import Add, Mul
    add = Add([21, 3])
    sets = set()
    sets.add(add.signature())
    add2 = Add([21, 3])
    assert add2.signature() in sets
    assert Add([3, 21]).signature() in sets
    assert Mul([2, 3]).signature() == Mul([3, 2]).signature()
Ejemplo n.º 2
0
def test_node_mul():
    from EvoDAG.node import Mul
    gp, args = create_problem_node()
    r = Mul.cumprod([x.hy for x in args])
    n = Mul(list(range(len(args))), ytr=gp._ytr, mask=gp._mask)
    coef = n.compute_weight([r])[0]
    assert n.eval(args)
    r = r * coef
    assert n.hy.SSE(r) == 0
    assert n.hy_test.SSE(r) == 0
Ejemplo n.º 3
0
def test_node_mul():
    from EvoDAG.node import Mul
    gp, args = create_problem_node()
    r = Mul.cumprod([x.hy for x in args])
    n = Mul(list(range(len(args))), ytr=gp._ytr, mask=gp._mask)
    coef = n.compute_weight([r])[0]
    assert n.eval(args)
    r = r * coef
    assert n.hy.SSE(r) == 0
    assert n.hy_test.SSE(r) == 0
Ejemplo n.º 4
0
def test_indindividual_decision_function():
    Add.nargs = 2
    Mul.nargs = 2
    vars = Model.convert_features(X)
    for x in vars:
        x._eval_ts = x._eval_tr.copy()
    vars = [Variable(k, weight=np.ones(1)) for k in range(len(vars))]
    for i in range(len(vars)):
        ind = Individual([vars[i]])
        ind.decision_function(X)
        hy = tonparray(ind._ind[0].hy)
        [assert_almost_equals(a, b) for a, b in zip(X[:, i], hy)]
    ind = Individual([
        Sin(0, weight=np.ones(1)),
        Add(range(2), np.ones(2)), vars[0], vars[-1]
    ])
    ind.decision_function(X)
    print(ind._ind[0].hy, ind._ind[1].hy)
    hy = tonparray(ind._ind[0].hy)
    y = np.sin(X[:, 0] + X[:, -1])
    [assert_almost_equals(a, b) for a, b in zip(y, hy)]
    y = np.sin((X[:, 0] + X[:, 1]) * X[:, 0] + X[:, 2])
    ind = Individual([
        Sin(0, weight=1),
        Add(range(2), weight=np.ones(2)),
        Mul(range(2), weight=1),
        Add(range(2), weight=np.ones(2)), vars[0], vars[1], vars[0], vars[2]
    ])
    ind.decision_function(X)
    # assert v.hy.SSE(v.hy_test) == 0
    hy = tonparray(ind._ind[0].hy)
    [assert_almost_equals(a, b) for a, b in zip(hy, y)]
    default_nargs()