# Dynamics for compartmented models¶

The SynchronousDynamics and StochasticDynamics classes define the basic mechanisms for the two main process simulation approaches. In both cases, there is a common way to run processes specified with compartmented models that massively simplify the creation of simulations.

In practice, these classes typically require no sub-classing, as all the variant behaviour can be more effectively provided in the code for the compartmented model of disease in a CompartmentedModel sub-class.

## CompartmentedStochasticDynamics¶

class epydemic.CompartmentedStochasticDynamics(m, g=None)

Bases: epydemic.stochasticdynamics.StochasticDynamics

A stochastic dynamics running a compartmented model. The behaviour of the simulation is completely described within the model rather than here.

Creating the dynamics involves providing the necessary model.

CompartmentedStochasticDynamics.__init__(m, g=None)

Create a dynamics over the given process model, optionally initialised to run on the given network.

Parameters: m – the compartmented model for the disease process g – prototype network to run the dynamics over (optional)

To set up the experiment we provide the parameters for the experiment as usual.

CompartmentedStochasticDynamics.setUp(params)

Set up the experiment for a run. This performs the default action of copying the prototype network and then builds the model and uses it to initialise the nodes into the various compartments according to the parameters.

Params params: the experimental parameters

Running the model requires that we convert the event probability distribution into an event rate distribution.

CompartmentedStochasticDynamics.eventRateDistribution(t)

Convert the model’s event distribution into the rate-based distribution required by Gillespie simulation.

Parameters: t – the current time the event rate distribution

Finally, we defer the experimental results collection to the model.

CompartmentedStochasticDynamics.experimentalResults()

Report the model’s experimental results.

Returns: the results as seen by the model

## CompartmentedSynchronousDynamics¶

class epydemic.CompartmentedSynchronousDynamics(m, g=None)

Bases: epydemic.synchronousdynamics.SynchronousDynamics

A synchronous dynamics running a compartmented model. The behaviour of the simulation is completely described within the model rather than here.

Creating the dynamics involves providing the necessary model.

CompartmentedSynchronousDynamics.__init__(m, g=None)

Create a dynamicsover the given disease model, optionally initialised to run on the given prototype network.

Parameters: m – the model g – prototype network to run over (optional)

To set up the experiment we provide the parameters for the experiment as usual.

CompartmentedSynchronousDynamics.setUp(params)

Set up the experiment for a run. This performs the default action of copying the prototype network and then builds the model and uses it to initialise the nodes into the various compartments according to the parameters.

Params params: the experimental parameters

Under synchronous dynamics we use the model-provided event probabilities to test whether an event occurred at each possible locus in each discrete timestep.

CompartmentedSynchronousDynamics.eventDistribution(t)

Return the model’s event distribution.

Parameters: t – current time the event distribution

Finally, we defer the experimental results collection to the model.

CompartmentedSynchronousDynamics.experimentalResults()

Report the model’s experimental results.

Returns: the results as seen by the model