Example #1
0
def test_func_not_callable():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = []

    lm_func = _LMFunction(func, args=(x,))
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n)
Example #2
0
def test_func_returns_invalid_size():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x : p[0]*np.exp(-p[1]*x) + p[2]

    lm_func = _LMFunction(func, args=(x,))
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n+1)
Example #3
0
def test_func_returns_invalid_size():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x: p[0] * np.exp(-p[1] * x) + p[2]

    lm_func = _LMFunction(func, args=(x, ))
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n + 1)
Example #4
0
def test_valid_func1():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x : p[0]*np.exp(-p[1]*x) + p[2]

    lm_func = _LMFunction(func, args=(x,))
    assert_(__py_verify_funcs(lm_func, p, m, n))
Example #5
0
def test_func_not_callable():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = []

    lm_func = _LMFunction(func, args=(x, ))
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n)
Example #6
0
def test_valid_func1():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x: p[0] * np.exp(-p[1] * x) + p[2]

    lm_func = _LMFunction(func, args=(x, ))
    assert_(__py_verify_funcs(lm_func, p, m, n))
Example #7
0
def test_valid_method():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)

    class Foo(object):
        def func(self, p, x):
            return p[0]*np.exp(-p[1]*x) + p[2]

    lm_func = _LMFunction(Foo().func, args=(x,))
    assert_(__py_verify_funcs(lm_func, p, m, n))
Example #8
0
def test_valid_method():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)

    class Foo(object):
        def func(self, p, x):
            return p[0] * np.exp(-p[1] * x) + p[2]

    lm_func = _LMFunction(Foo().func, args=(x, ))
    assert_(__py_verify_funcs(lm_func, p, m, n))
Example #9
0
def test_jacf_returns_invalid_size():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x : p[0]*np.exp(-p[1]*x) + p[2]
    def jacf(p, x):
        y = np.empty((n,m-1))
        y[:,0] = np.exp(-p[1]*x)
        y[:,1] = -p[0] * x * np.exp(-p[1]*x)
        return y

    lm_func = _LMFunction(func, args=(x,),  jacf=jacf)
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n)
Example #10
0
def test_valid_func2():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x : p[0]*np.exp(-p[1]*x) + p[2]
    def jacf(p, x):
        y = np.empty((n,m))
        y[:,0] = np.exp(-p[1]*x)
        y[:,1] = -p[0] * x * np.exp(-p[1]*x)
        y[:,2] = np.ones(x.size)
        return y

    lm_func = _LMFunction(func, args=(x,),  jacf=jacf)
    assert_(__py_verify_funcs(lm_func, p, m, n))
Example #11
0
def test_jacf_returns_invalid_size():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x: p[0] * np.exp(-p[1] * x) + p[2]

    def jacf(p, x):
        y = np.empty((n, m - 1))
        y[:, 0] = np.exp(-p[1] * x)
        y[:, 1] = -p[0] * x * np.exp(-p[1] * x)
        return y

    lm_func = _LMFunction(func, args=(x, ), jacf=jacf)
    assert_raises(LMUserFuncError, __py_verify_funcs, lm_func, p, m, n)
Example #12
0
def test_valid_func2():
    m, n = 3, 50
    p = np.array([1, 2, 3])
    x = np.linspace(-5, 5, n)
    func = lambda p, x: p[0] * np.exp(-p[1] * x) + p[2]

    def jacf(p, x):
        y = np.empty((n, m))
        y[:, 0] = np.exp(-p[1] * x)
        y[:, 1] = -p[0] * x * np.exp(-p[1] * x)
        y[:, 2] = np.ones(x.size)
        return y

    lm_func = _LMFunction(func, args=(x, ), jacf=jacf)
    assert_(__py_verify_funcs(lm_func, p, m, n))