Ejemplo n.º 1
0
def test_compute_weight():
    gp, args = create_problem_node()
    mask = SparseArray.fromlist(np.ones(len(gp._mask)))
    n = Add(list(range(len(args))), ytr=gp._ytr, mask=mask)
    D = np.array([tonparray(i.hy) for i in args]).T
    coef = n.compute_weight([x.hy for x in args])
    r = np.linalg.lstsq(D, tonparray(gp._ytr))[0]
    [assert_almost_equals(a, b) for a, b in zip(coef, r)]
Ejemplo n.º 2
0
def test_node_add():
    gp, args = create_problem_node()
    n = Add(list(range(len(args))), ytr=gp._ytr, mask=gp._mask)
    coef = n.compute_weight([x.hy for x in args])
    assert n.eval(args)
    # a = map(lambda (a, b): a.hy * b, zip(args, coef))
    a = [a.hy * b for a, b in zip(args, coef)]
    r = n.cumsum(a)
    assert n.hy.SSE(r) == 0
    assert n.hy_test.SSE(r) == 0
Ejemplo n.º 3
0
def test_node_add():
    gp, args = create_problem_node()
    n = Add(list(range(len(args))), ytr=gp._ytr, mask=gp._mask)
    D = np.array([tonparray(i.hy) for i in args]).T
    coef = n.compute_weight([x.hy for x in args])
    assert n.eval(args)
    # a = map(lambda (a, b): a.hy * b, zip(args, coef))
    a = [_a.hy * b for _a, b in zip(args, coef)]
    r = n.cumsum(a)
    print((D * coef).sum(axis=1)[:4], "*")
    print(tonparray(n.hy)[:4])
    print(tonparray(r)[:4])
    print(tonparray(gp._mask)[:4])
    assert n.hy.SSE(r) == 0
    assert n.hy_test.SSE(r) == 0