Ejemplo n.º 1
0
def test_getparams_terms():
    t = F.Term("t")
    x, y, z = [sympy.Symbol(l) for l in "xyz"]
    yield assert_equal, set(F.getparams(x * y * t)), set([x, y])
    yield assert_equal, set(F.getterms(x * y * t)), set([t])

    matrix_expr = np.array([[x, y * t], [y, z]])
    yield assert_equal, set(F.getparams(matrix_expr)), set([x, y, z])
    yield assert_equal, set(F.getterms(matrix_expr)), set([t])
Ejemplo n.º 2
0
def test_nonlin1():
    # Fit an exponential curve, with the exponent stratified by a factor
    # with a common intercept and multiplicative factor in front of the
    # exponential
    x = F.Term('x')
    fac = F.Factor('f', 'ab')

    
    f = F.Formula([sympy.exp(fac.stratify(x).mean)]) + F.I

    params = F.getparams(f.mean)
    yield assert_equal, set([str(p) for p in params]), set(['_x0', '_x1', '_b0', '_b1'])
    
    test1 = set(['1',
                 'exp(_x0*f_a + _x1*f_b)',
                 '_b0*f_a*exp(_x0*f_a + _x1*f_b)',
                 '_b0*f_b*exp(_x0*f_a + _x1*f_b)'])
    test2 = set(['1',
                 'exp(_x0*f_a + _x1*f_b)',
                 '_b1*f_a*exp(_x0*f_a + _x1*f_b)',
                 '_b1*f_b*exp(_x0*f_a + _x1*f_b)'])
    yield assert_true, test1 or test2

    n = F.make_recarray([(2,3,'a'),(4,5,'b'),(5,6,'a')], 'xyf', ['d','d','S1'])
    p = F.make_recarray([1,2,3,4], ['_x0', '_x1', '_b0', '_b1'])
    A = f.design(n, p)
    print A, A.dtype
Ejemplo n.º 3
0
def test_nonlin1():
    # Fit an exponential curve, with the exponent stratified by a factor
    # with a common intercept and multiplicative factor in front of the
    # exponential
    x = F.Term("x")
    fac = F.Factor("f", "ab")
    f = F.Formula([sympy.exp(fac.stratify(x).mean)]) + F.I
    params = F.getparams(f.mean)
    yield assert_equal, set([str(p) for p in params]), set(["_x0", "_x1", "_b0", "_b1"])
    test1 = set(["1", "exp(_x0*f_a + _x1*f_b)", "_b0*f_a*exp(_x0*f_a + _x1*f_b)", "_b0*f_b*exp(_x0*f_a + _x1*f_b)"])
    test2 = set(["1", "exp(_x0*f_a + _x1*f_b)", "_b1*f_a*exp(_x0*f_a + _x1*f_b)", "_b1*f_b*exp(_x0*f_a + _x1*f_b)"])
    yield assert_true, test1 or test2
    n = F.make_recarray([(2, 3, "a"), (4, 5, "b"), (5, 6, "a")], "xyf", ["d", "d", "S1"])
    p = F.make_recarray([1, 2, 3, 4], ["_x0", "_x1", "_b0", "_b1"])
    A = f.design(n, p)
    print A, A.dtype