Ejemplo n.º 1
0
    def test_correct_caching2(self):
        # setup equation
        eqn = Seir(population=1)

        # setup ode solver
        ti = 0.
        tf = 2.
        n_steps = 3
        rk = RKSolver(ti, tf, n_steps)
        rk.output_frequency = 1
        rk.set_output_storing_flag(True)
        rk.equation = eqn
        u0 = np.array([100., 0., 10., 0.])
        du0_dp = np.zeros((eqn.n_components(), eqn.n_parameters()))
        rk.set_initial_condition(u0, du0_dp)
        rk.set_output_gradient_flag(True)

        # setup cached simulation object
        cached_sim = CachedSEIRSimulation(rk)

        params = np.array([2.3, 0.2, 1. / 3., 1. / 4.])

        (f, df) = cached_sim(params)

        f1 = np.copy(f)
        df1 = np.copy(df)

        f *= 0.
        df += 0.

        (f2, df2) = cached_sim(params)

        assert np.allclose(f1, f2)
        assert np.allclose(df1, df2)
Ejemplo n.º 2
0
    def test_correct_caching3(self):
        # setup equation
        eqn = Seir(population=1)

        # setup ode solver
        ti = 0.
        tf = 2.
        n_steps = 3
        rk = RKSolver(ti, tf, n_steps)
        rk.output_frequency = 1
        rk.set_output_storing_flag(True)
        rk.equation = eqn
        u0 = np.array([100., 0., 10., 0.])
        rk.set_initial_condition(u0)

        # setup cached simulation object
        cached_sim = CachedSEIRSimulation(rk)
        cached_sim.set_gradient_flag(False)

        params = np.array([2.3, 0.2, 1. / 3., 1. / 4.])

        f = cached_sim(params)[0]

        f1 = np.copy(f)

        params2 = np.array([2.32, 0.2, 1. / 3., 1. / 4.])

        f2 = cached_sim(params2)[0]

        assert not np.allclose(f1, f2)
Ejemplo n.º 3
0
    def test_interface(self):
        rk = RKSolver(0, 1)
        rk.initial_time = 0.5
        rk.final_time = 5
        rk.n_steps = 10
        self.assertEqual(rk.initial_time,0.5)
        self.assertEqual(rk.final_time,5)
        self.assertEqual(rk.n_steps,10)

        eqn = Seir()
        rk.equation = eqn
        self.assertEqual(rk.equation, eqn)

        rk.output_frequency = 20
        self.assertEqual(rk.output_frequency, 20)