Пример #1
0
 def test_scalar_basic1(self):
     # f(x) = x**2; x0=1.05; fixed point should be x=1
     def func(x):
         return x**2
     x0 = 1.05
     x = fixed_point(func, x0)
     assert_almost_equal(x, 1.0)
Пример #2
0
 def test_scalar_basic1(self):
     # f(x) = x**2; x0=1.05; fixed point should be x=1
     def func(x):
         return x**2
     x0 = 1.05
     x = fixed_point(func, x0)
     assert_almost_equal(x, 1.0)
Пример #3
0
 def test_scalar_basic2(self):
     """f(x) = x**0.5; x0=1.05; fixed point should be x=1"""
     def func(x):
         return x**0.5
     x0 = 1.05
     x = fixed_point(func, x0)
     assert_almost_equal(x, 1.0)
Пример #4
0
 def test_array_trivial(self):
     def func(x):
         return 2.0*x
     x0 = [0.3, 0.15]
     with np.errstate(all='ignore'):
         x = fixed_point(func, x0)
     assert_almost_equal(x, [0.0, 0.0])
Пример #5
0
 def test_scalar_trivial(self):
     """f(x) = 2x; fixed point should be x=0"""
     def func(x):
         return 2.0*x
     x0 = 1.0
     x = fixed_point(func, x0)
     assert_almost_equal(x, 0.0)
Пример #6
0
 def steffe_fn(s, t):
     with RedirectStdout(_logfile):
         res = minpack.fixed_point(f,
                                   x0,
                                   args=(t, ) + extrafargs,
                                   xtol=xtolval,
                                   maxiter=maxnumiter)
         return res
Пример #7
0
 def steffe_fn(s, t):
     rout.start()
     ##                rerr.start()
     res = minpack.fixed_point(f, x0, args=(t,) + extrafargs, xtol=xtolval, maxiter=maxnumiter)
     rout.stop()
     ##                warns = rout.stop()
     ##                rerr.stop()
     return res
Пример #8
0
 def test_array_basic1(self):
     """f(x) = c * x**2; fixed point should be x=1/c"""
     def func(x, c):
         return c * x**2
     c = array([0.75, 1.0, 1.25])
     x0 = [1.1, 1.15, 0.9]
     x = fixed_point(func, x0, args=(c,))
     assert_almost_equal(x, 1.0/c)
Пример #9
0
 def test_array_basic2(self):
     """f(x) = c * x**0.5; fixed point should be x=c**2"""
     def func(x, c):
         return c * x**0.5
     c = array([0.75, 1.0, 1.25])
     x0 = [0.8, 1.1, 1.1]
     x = fixed_point(func, x0, args=(c,))
     assert_almost_equal(x, c**2)
Пример #10
0
 def test_array_basic1(self):
     # f(x) = c * x**2; fixed point should be x=1/c
     def func(x, c):
         return c * x**2
     c = array([0.75, 1.0, 1.25])
     x0 = [1.1, 1.15, 0.9]
     with np.errstate(all='ignore'):
         x = fixed_point(func, x0, args=(c,))
     assert_almost_equal(x, 1.0/c)
Пример #11
0
 def test_lambertw(self):
     # python-list/2010-December/594592.html
     xxroot = fixed_point(lambda xx: np.exp(-2.0 * xx) / 2.0,
                          1.0,
                          args=(),
                          xtol=1e-12,
                          maxiter=500)
     assert_allclose(xxroot, np.exp(-2.0 * xxroot) / 2.0)
     assert_allclose(xxroot, lambertw(1) / 2)
Пример #12
0
 def test_array_trivial(self):
     def func(x):
         return 2.0*x
     x0 = [0.3, 0.15]
     olderr = np.seterr(all='ignore')
     try:
         x = fixed_point(func, x0)
     finally:
         np.seterr(**olderr)
     assert_almost_equal(x, [0.0, 0.0])
Пример #13
0
 def steffe_fn(s, t):
     rout.start()
     ##                rerr.start()
     res = minpack.fixed_point(f,
                               x0,
                               args=(t, ) + extrafargs,
                               xtol=xtolval,
                               maxiter=maxnumiter)
     rout.stop()
     ##                warns = rout.stop()
     ##                rerr.stop()
     return res
Пример #14
0
 def test_array_basic1(self):
     """f(x) = c * x**2; fixed point should be x=1/c"""
     def func(x, c):
         return c * x**2
     c = array([0.75, 1.0, 1.25])
     x0 = [1.1, 1.15, 0.9]
     olderr = np.seterr(all='ignore')
     try:
         x = fixed_point(func, x0, args=(c,))
     finally:
         np.seterr(**olderr)
     assert_almost_equal(x, 1.0/c)
Пример #15
0
    def test_no_acceleration(self):
        # github issue 5460
        ks = 2
        kl = 6
        m = 1.3
        n0 = 1.001
        i0 = ((m-1)/m)*(kl/ks/m)**(1/(m-1))

        def func(n):
            return np.log(kl/ks/n) / np.log((i0*n/(n - 1))) + 1

        n = fixed_point(func, n0, method='iteration')
        assert_allclose(n, m)
Пример #16
0
    def test_no_acceleration(self):
        # github issue 5460
        ks = 2
        kl = 6
        m = 1.3
        n0 = 1.001
        i0 = ((m-1)/m)*(kl/ks/m)**(1/(m-1))

        def func(n):
            return np.log(kl/ks/n) / np.log((i0*n/(n - 1))) + 1

        n = fixed_point(func, n0, method='iteration')
        assert_allclose(n, m)
Пример #17
0
 def steffe_fn(s, t):
     with RedirectStdout(_logfile):
         res = minpack.fixed_point(f, x0, args=(t,)+extrafargs,
                                 xtol=xtolval, maxiter=maxnumiter)
         return res
Пример #18
0
 def test_array_trivial(self):
     def func(x):
         return 2.0*x
     x0 = [0.3, 0.15]
     x = fixed_point(func, x0)
     assert_almost_equal(x, [0.0, 0.0])
Пример #19
0
 def test_lambertw(self):
     # python-list/2010-December/594592.html
     xxroot = fixed_point(lambda xx: np.exp(-2.0*xx)/2.0, 1.0,
             args=(), xtol=1e-12, maxiter=500)
     assert_allclose(xxroot, np.exp(-2.0*xxroot)/2.0)
     assert_allclose(xxroot, lambertw(1)/2)