benmaier / epipack

Fast prototyping of epidemiological models based on reaction equations. Analyze the ODEs analytically or numerically, or run stochastic simulations on networks/well-mixed systems.
MIT License
33 stars 3 forks source link

Refactor `DeterministicEpiModel` to `NumericEpiModel` #5

Closed benmaier closed 4 years ago

benmaier commented 4 years ago

In this case it's clear that both SymbolicEpiModel as well as DeterministicEpiModel are mean-field models. It should be possible to integrate both as well as to simulate both using Gillespie's algorithm. The only difference should be that one is more comfortable regarding checks and analytical treatment while the other is faster numerically.

benmaier commented 4 years ago

for both classes, construct events from processes that look like this:

( acting_compartments, rate_expression, dy)

where acting_compartments is a list of compartment indices that will cause this reaction, dy is an N_compartments-long vector that contains the compartment-count changes for this process and rate_expression is either a constant or a function of t and y.

The rate_expressions will be converted to functions of t and y if any of them is a function. In this case, set a flag that tells the object that it has functional rates. In this case, the numerical dydt will be constructed in a different way, i.e. by iterating through events and adding all dys as multiplied by the rate.

If the model has no functional rates, the simulation algorithm becomes the classical Gillespie algorithm. Otherwise, the integral to obtain the time leap tau has to be solved numerically.

benmaier commented 4 years ago

This would fix #3, as well.

benmaier commented 4 years ago

On second thought, leave DeterministicEpiModel as it is. Instead, construct the new NumericEpiModel from scratch. Also, think about basing SymbolicEpiModel on NumericEpiModel. Or think about doing both models as two separate ways.

benmaier commented 4 years ago

fixed in 7e6e13a and previous by the introduction of NumericEpiModel