コード例 #1
0
    def test_lokta_volterra(self):
        """Test that LV is calculating correctly.
        WARNING: lokta_volterra function is being tested less rigorously than 
        other functions because hand calculating the answers for many steps 
        would be prohibitively time consuming. The function is being tested 
        by seeing if it agrees with the downloaded code from the scipy tutorial
        and by testing if it correctly evaluates fixed or stable points.
        scipy tutorial available at:
        http://www.scipy.org/Cookbook/LoktaVolterraTutorial."""
        # from the scipy tutorial
        a = 1.0
        b = 0.1
        c = 1.5
        d = 0.75

        def dX_dt(X, t=0):
            """ Return the growth rate of fox and rabbit populations. """
            return array([a * X[0] - b * X[0] * X[1], -c * X[1] + d * b * X[0] * X[1]])

        t = linspace(0, 15, 1000)
        X0 = array([10, 5])
        exp = integrate.odeint(dX_dt, X0, t)
        # calculate with our function
        C = array([[1.0, 0, -0.1], [-1.5, 0.075, 0]])
        f = dX_dt_template(C)
        Y = lokta_volterra(f, array([10, 5]), 0, 15, 1000)
        assert_array_almost_equal(exp, Y.T)
コード例 #2
0
 def test_lokta_volterra(self):
     '''Test that LV is calculating correctly.
     WARNING: lokta_volterra function is being tested less rigorously than 
     other functions because hand calculating the answers for many steps 
     would be prohibitively time consuming. The function is being tested 
     by seeing if it agrees with the downloaded code from the scipy tutorial
     and by testing if it correctly evaluates fixed or stable points.
     scipy tutorial available at:
     http://www.scipy.org/Cookbook/LoktaVolterraTutorial.'''
     # from the scipy tutorial
     a = 1.
     b = 0.1
     c = 1.5
     d = 0.75
     def dX_dt(X, t=0):
         """ Return the growth rate of fox and rabbit populations. """
         return array([ a*X[0] -   b*X[0]*X[1] ,
                       -c*X[1] + d*b*X[0]*X[1] ])
     t = linspace(0, 15,  1000)
     X0 = array([10, 5])
     exp = integrate.odeint(dX_dt, X0, t)
     # calculate with our function
     C = array([[1., 0, -.1],
                [-1.5, 0.075, 0]])
     f = dX_dt_template(C)
     Y = lokta_volterra(f, array([10,5]), 0, 15, 1000)
     assert_array_almost_equal(exp, Y.T)
コード例 #3
0
 def test_dX_dt_template(self):
     """Test that the function returned by dX_dt_template evals correctly."""
     C = array([[0.5, 0.6, 0.7], [0.1, 0.2, 1.5]])
     X = array([10, 20])
     exp = array([205, 642])
     obs = dX_dt_template(C)(X)
     assert_array_almost_equal(obs, exp)
コード例 #4
0
 def test_dX_dt_template(self):
     '''Test that the function returned by dX_dt_template evals correctly.'''
     C = array([[.5, .6, .7],
                [.1, .2, 1.5]])
     X = array([10,20])
     exp = array([205,642])
     obs = dX_dt_template(C)(X)
     assert_array_almost_equal(obs, exp)