コード例 #1
0
    def test__init__(self):

        start = 0
        end = 10
        with self.assertRaises(TypeError):
            se.SimulationController(se.SimulationController, start, end)
            se.SimulationController('1', start, end)
コード例 #2
0
    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)
コード例 #3
0
    def add_model(self, model, parameters_name):
        """
        Plot subplots of simulation for the given model.

        Parameters
        ----------
        model
            A subclass of seirmo.ForwardModel class, which specifies
            the model of simulation.
        parameters_name
            Name of parameters of model in list of strings.
        """

        parameters_name = list(parameters_name)

        init_parameters = []

        for model_parameter in parameters_name:
            model_parameter = str(model_parameter)
            self._slider_component.add_slider(slider_id=model_parameter,
                                              min_value=0,
                                              max_value=1,
                                              initial_value=0.5)
            init_parameters.append(
                self._slider_component._sliders[model_parameter].children[1].
                value)  # noqa

        self._slider_component.group_sliders(parameters_name,
                                             'Sliders of parameters')

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

        data = self.simulate.run(init_parameters)
        data = pd.DataFrame({
            'Time': list(self.simulate._simulation_times),
            'Incidence Number': data[:, -1],
            'Susceptible': data[:, 0],
            'Exposed': data[:, 1],
            'Infectious': data[:, 2],
            'Recovered': data[:, 3],
        })

        self._subplot_fig.add_simulation(data)
コード例 #4
0
    def test_run(self):

        start = 0
        end = 10
        model = se.SEIRModel
        simulation = se.SimulationController(model, start, end)

        initial_values = [0.9, 0, 0.1, 0]
        constants = [1, 1, 1]
        test_parameters = initial_values + constants
        output = simulation.run(test_parameters, ['S', 'E', 'I', 'R'])

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

        # Check that sum of states is one at all times
        output = simulation.run(test_parameters)
        total = np.sum(output, axis=1)
        expected = np.ones(shape=10)
        np.testing.assert_almost_equal(total, expected)