Models

The models provide a framework for the implementation of any models.

Overview:

SEIR Model

class seirmo.ForwardModel[source]

Abstract base class for forward models.

Extends pints.ForwardModel.

n_outputs()[source]

Returns the number of model outputs.

n_parameters()[source]

Returns the number of model parameters.

output_names()[source]

Returns the names of the model outputs.

parameter_names()[source]

Returns the names of the model parameters.

set_outputs(outputs)[source]

Sets the outputs of the model.

simulate(parameters, times)[source]

Forward simulation of a model for a given time period with given parameters Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters (list | numpy.ndarray) – An array-like object with parameter values of length n_parameters().

  • times (list | numpy.ndarray) – An array-like object with time points.

class seirmo.ReducedModel(model)[source]

A class that can be used to permanently fix model parameters of a ForwardModel instance.

This may be useful to explore simplified versions of a model without reimplementing the model itself.

Extends ForwardModel.

Parameters:

model (ForwardModel) – An instance of a ForwardModel.

fix_parameters(name_value_dict)[source]

Fixes the value of model parameters, and effectively removes them as a parameter from the model. Fixing the value of a parameter at None, sets the parameter free again.

Parameters:

name_value_dict (dict) – A dictionary with model parameter names as keys, and parameter values as values.

n_fixed_parameters()[source]

Returns the number of fixed model parameters.

n_outputs()[source]

Returns the number of model outputs.

n_parameters()[source]

Returns the number of model parameters.

output_names()[source]

Returns the names of the model outputs.

parameter_names()[source]

Returns the names of the model parameters.

set_outputs(outputs)[source]

Sets the outputs of the model.

simulate(parameters, times)[source]

Forward simulation of a model for a given time period with given parameters Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters (list | numpy.ndarray) – An array-like object with parameter values of length n_parameters().

  • times (list | numpy.ndarray) – An array-like object with time points.

class seirmo.SEIRModel[source]

ODE model: deterministic SEIR The SEIR Model has four compartments: susceptible individuals (\(S\)), exposed but not yet infectious (\(E\)), infectious (\(I\)) and recovered (\(R\)):

\[\frac{dS(t)}{dt} = -\beta S(t)I(t),\]
\[\frac{dE(t)}{dt} = \beta S(t)I(t) - \kappa E(t),\]
\[\frac{dI(t)}{dt} = \kappa E(t) - \gamma I(t),\]
\[\frac{dR(t)}{dt} = \gamma I(t),\]

where \(S(0) = S_0, E(0) = E_0, I(O) = I_0, R(0) = R_0\) are also parameters of the model.

Extends ForwardModel.

n_outputs()[source]

Returns the number of model outputs.

n_parameters()[source]

Returns the number of model parameters.

output_names()[source]

Returns the names of the model outputs.

parameter_names()[source]

Returns the names of the model parameters.

set_outputs(outputs)[source]

Sets the outputs of the model.

simulate(parameters, times)[source]

Forward simulation of a model for a given time period with given parameters Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters (list | numpy.ndarray) – An array-like object with parameter values of length n_parameters().

  • times (list | numpy.ndarray) – An array-like object with time points.

class seirmo.DeterministicSEIRModel[source]

ODE model: deterministic SEIR The SEIR Model has four compartments: susceptible individuals (\(S\)), exposed but not yet infectious (\(E\)), infectious (\(I\)) and recovered (\(R\)):

\[\frac{dS(t)}{dt} = -\beta S(t)I(t),\]
\[\frac{dE(t)}{dt} = \beta S(t)I(t) - \kappa E(t),\]
\[\frac{dI(t)}{dt} = \kappa E(t) - \gamma I(t),\]
\[\frac{dR(t)}{dt} = \gamma I(t),\]

where \(S(0) = S_0, E(0) = E_0, I(O) = I_0, R(0) = R_0\) are also parameters of the model.

Extends SEIRForwardModel.

simulate(parameters, times)[source]

Forward simulation of a model for a given time period with given parameters Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters (list | numpy.ndarray) – An array-like object with parameter values of length n_parameters().

  • times (list | numpy.ndarray) – An array-like object with time points.

class seirmo.StochasticSEIRModel(params_names: list)[source]

ODE model: Stochastic SEIR The SEIR Model has four compartments: susceptible individuals (\(S\)), exposed but not yet infectious (\(E\)), infectious (\(I\)) and recovered (\(R\)):

Possible processes between compartments:

Exposure: S -> E, at rate :math:beta S(t)I(t)`` Infection: E -> I, at rate :math:kappa E(t)`` Recovery: I -> R, at rate :math:gamma I(t)``

Can be used in conjunction with solve_gillespie(), a stochastic ODE solver implemented in this package.

Extends SEIRForwardModel.

simulate(parameters: ndarray, times: list, max_t_step: float = 0.01)[source]

Forward simulation of a model for a given time period with given parameters Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters (list | numpy.ndarray) – An array-like object with parameter values of length n_parameters().

  • times (list | numpy.ndarray) – An array-like object with time points.

update_propensity(current_states: ndarray) ndarray[source]

This function takes the current populations in each of the N compartments and returns a NxN array where the entry (i,j) gives the rate of transfer of the population of compartment i to compartment j.

Each non-zero element here corresponds to one equation in the SEIR model. Non-zero diagonal elements would correspond to no change in the overall population.

Warning - negative elements should be avoided - a negative value at (i,j) corresponds to a positive element at (j,i) and should be implemented as such if required.