Simulations¶
The models provide a framework for the implementation of any models.
Overview:
- class seirmo.SimulationController(model, start, end)[source]¶
SimulationController Class:
Runs the simulation of any model and controls outputs
- Parameters:
model (seirmo.ForwardModel class)
start (simulation start time)
end (simulation end time)
Home-Brew Simulation Methods:¶
- seirmo.solve_gillespie(propensities: Callable[[ndarray], ndarray], initial_cond: ndarray, t_span: List[float], max_t_step: float = 0.01)[source]¶
Solve an initial_cond value problem using gillespie algorithm
This function numerically integrates a system of ordinary differential equations given initial_cond conditions. We use the Gillespie algorithm with tau-leaping, so that the time step is not uniform but sampled randomly
N.B If all propensities are zero, this would give an infinite timestep. We allow the simulation to continue at a large time_step, to allow for time dependant rates that may be non-zero at later times This time step is drawn from an exp dist based on ((t_stop-t_start)/100)
- Parameters:
propensities (callable of form propensities(state)) – State is array of length (N+1) of time and count per compartment (for N compartments) Will return an NxN array as a transition matrix for propensities
t_span (2-list of floats) – Internal of integration (t_start, t_end). The solver starts at t_start and will finish once the first random time_step exceeds t_end (Note that the final value may be greater than t_end)
initial_cond (array_like, shape (N,)) – Initial state, gives counts in each of N compartments
max_t_step (float (default value 0.01)) – This is the maximum allowed timestep, as a fraction of the total t_span Default value is 0.01, so (t_span[1] - t_span[0])/100 Note that the exact time_steps are sampled from an exponential distribution, and so may be smaller than this
- Yields:
Numpy array of form [Time, Compartment_1, …], ie [time, S, E, I, R] – Note that time steps are random (not uniform), and final timestep lie after the end of the time_span given