def test_simulate(self):
        model = se.SEIRModel()

        initial_values = [0.9, 0, 0.1, 0]
        constants = [1, 1, 1]
        test_parameters = initial_values + constants

        n_times = 10
        test_times = np.linspace(0, 10, num=n_times)

        model.set_outputs(['S', 'I', 'Incidence'])
        output = model.simulate(test_parameters, test_times)

        # Check output shape
        self.assertEqual(output.shape, (n_times, 3))

        # Check that sum of states is one at all times
        model.set_outputs(['S', 'E', 'I', 'R'])
        output = model.simulate(test_parameters, test_times)
        total = np.sum(output, axis=1)
        expected = np.ones(shape=n_times)
        np.testing.assert_almost_equal(total, expected)

        # Check output shape
        self.assertEqual(output.shape, (n_times, 4))
    def add_problem(self, data, model):
        # Check model is ForwardModel
        if not issubclass(model, se.ForwardModel):
            raise TypeError(
                'Model has to be a subclass of seirmo.ForwardModel.')

        time_key = 'Time'
        inc_key = 'Incidence Number'
        # Visualise data
        self.data = data
        self._subplot_fig.add_data(self.data, time_key, inc_key)

        self.simulate = se.SimulationController(model, self.simulation_start,
                                                self.simulation_end)

        initialise_data = pd.DataFrame({
            'Time': [0],
            'Incidence Number': [0],
            'Susceptible': [0],
            'Exposed': [0],
            'Infectious': [0],
            'Recovered': [0],
        })

        self._subplot_fig.add_simulation(initialise_data)

        # Create model
        model = model()
        model = se.SEIRModel()
        model.set_outputs(['Incidence'])
        self.model = se.ReducedModel(model)
    def test_output_names(self):
        model = se.SEIRModel()
        self.assertEqual(model.output_names(),
                         ['S', 'E', 'I', 'R', 'Incidence'])

        model.set_outputs(['I', 'Incidence'])
        self.assertEqual(model.output_names(), ['I', 'Incidence'])
 def test__init__(self):
     model = se.SEIRModel()
     self.assertEqual(model._output_names,
                      ['S', 'E', 'I', 'R', 'Incidence'])
     self.assertEqual(model._parameter_names,
                      ['S0', 'E0', 'I0', 'R0', 'alpha', 'beta', 'gamma'])
     self.assertEqual(model._n_outputs, 5)
     self.assertEqual(model._n_parameters, 7)
     np.testing.assert_array_equal(model._output_indices, np.arange(5))
    def test_set_outputs(self):
        model = se.SEIRModel()

        # Check ValueError will be raised when some output names
        # are not as required
        with self.assertRaises(ValueError):
            model.set_outputs(['incidence number'])

        model.set_outputs(['I', 'Incidence'])
        # Check the outputs names and number are as expected
        self.assertEqual(model._output_indices, [2, 4])
        self.assertEqual(model._n_outputs, 2)
    def test_simulate(self):
        initial_values = [0, 0.1, 0]
        constants = [1, 1]
        test_parameters = initial_values + constants

        n_times = 10
        test_times = np.linspace(0, 10, num=n_times)

        self.reduced_model.set_outputs(['S', 'I', 'Incidence'])
        self.reduced_model.fix_parameters({'S0': 0.9, 'alpha': 1})
        output = self.reduced_model.simulate(test_parameters, test_times)

        # Check output shape
        self.assertEqual(output.shape, (n_times, 3))

        # Check that sum of states is one at all times
        self.reduced_model.set_outputs(['S', 'E', 'I', 'R'])
        output = self.reduced_model.simulate(test_parameters, test_times)
        total = np.sum(output, axis=1)
        expected = np.ones(shape=n_times)
        np.testing.assert_almost_equal(total, expected)

        # Check output shape
        self.assertEqual(output.shape, (n_times, 4))

        # Check that the results are the same for the reduced model
        # and the normal model with the same parameters

        # Run the reduced model for all the outputs
        self.reduced_model.set_outputs(['S', 'E', 'I', 'R', 'Incidence'])
        output_reduced = self.reduced_model.simulate(test_parameters,
                                                     test_times)

        # Run the normal model for all the outputs
        model = se.SEIRModel()

        initial_values = [0.9, 0, 0.1, 0]
        constants = [1, 1, 1]
        test_parameters = initial_values + constants

        np.testing.assert_almost_equal(total, expected)

        model.set_outputs(['S', 'E', 'I', 'R', 'Incidence'])
        output_normal = model.simulate(test_parameters, test_times)

        np.testing.assert_almost_equal(output_reduced, output_normal)

        # Set the outputs to the default
        self.reduced_model.set_outputs(['S', 'E', 'I', 'R', 'Incidence'])

        # Unfix the parameters
        name_value_dict = {'S0': None, 'alpha': None}
        self.reduced_model.fix_parameters(name_value_dict)
 def test_parameter_names(self):
     model = se.SEIRModel()
     self.assertEqual(model.parameter_names(),
                      ['S0', 'E0', 'I0', 'R0', 'alpha', 'beta', 'gamma'])
 def test_n_parameters(self):
     model = se.SEIRModel()
     self.assertEqual(model.n_parameters(), 7)
 def test_n_outputs(self):
     model = se.SEIRModel()
     self.assertEqual(model.n_outputs(), 5)
 def setUpClass(cls):
     cls.reduced_model = se.ReducedModel(se.SEIRModel())