Hey guys! I was discussing a possible trapezoidal ODE solver implementation in Stan with @wds15, @Bob_Carpenter, @bbbales2 and @charlesm93 and the discussion took a detour to “what are you doing that you need a trapezoidal solver?”.
I was explaining Liverpool’s CoDatMo model that, according to them, takes between 10-17h to finish sampling (4 parallel chains 2k iterations) with CmdStan. The model is a dual-time-series data using daily deaths and daily NHS 111 COVID calls. The UNINOVE CoDatMo model will consist of two models that uses the same transmission model as Liverpool and also relies on Brazil’s data. The first one (which is the one I am currently working on) is a “stepped-down” version of the model with only one time-series data using daily deaths. This one takes 1h30 to sample on a high-end notebook running Linux and using CmdStan with the trapezoidal solver. I am running a RK45 ODE solver and it is still warming up (I think it 'll sample in 12 days). The second model would be the same as Liverpool’s but using twitter daily symptom mentions.
As the discussion progressed, we decided to move to the forums so that everybody could probably benefit from this discussion as well. As @wds15 noted regarding trapezoidal solvers: “To the point of trapezoidal solvers: Avoiding the use of dedicated ODE solvers and going so simple is tempting, I know. The issue is error control”. With trapezoidal solvers we have very little error control.
Okay, so let me explain the model. The transmission model assumes a single geographical region with a large population of identical (for instance, in terms of age and sex) individuals who come into contact with one another uniformly at random, but do not come into contact with individuals from other areas. It also assumes a closed population, that is no individuals migrate into or out of the population, for example as a result of births, non-COVID related deaths, or changes in permanent residence. The model divides the population into six disease states: (S) susceptible, (E) exposed, (I) infectious, (R) recovered, (T) terminally ill, and (D) dead. The exposed, infectious, and terminally ill disease states are each further partitioned into two substates, making the expected times spent by people in these states follow Erlang distributions. Below is a graphical illustration of the transmission model.
The Erlang distributions arises when we implement the sub-states using the Generalized Linear Trick (Hurtado references below). “The LCT is a technique used to construct mean field ODE models from continuous-time stochastic state transition models where the time an individual spends in a given state (i.e., the dwell time) is Erlang distributed (i.e., gamma distributed with integer shape parameter).”
Through the random mixing of the population, infectious individuals come into contact with and are allowed to transmit the virus to susceptible individuals. A susceptible individual who has become exposed through one of these contacts is not initially infectious. A period of time elapses, while the virus replicates in their body before they become infectious and can transmit the virus onto members of the remaining susceptible population. After being infectious for some time, the individual may recover and become indefinitely immune to reinfection. Should the individual fail to recover, however, they will become terminally ill for a while before, unfortunately, dying of the disease.
The number of individuals in each disease state varies with time according to the following system of ordinary differential equations:
The models can be found here: UNINOVE_Sao_Paulo/SEIR-model/stan at main · codatmo/UNINOVE_Sao_Paulo · GitHub. The deaths.stan
is the deaths-only with the trapezoidal custom solver and the deaths_rk45.stan
is the same model using the old interface RK45 solver. And the deaths_new_rk45.stan
is an implementation to the new interface RK45 solver (thank you @bbbales2).
The point is: the model is slow to sample and we can possibly remove the custom trapezoidal solver if we could somehow improve it. @wds15 suggested “maybe work out a semi-analytic solution which takes advantage of different time-scales”, while also pointing that "the problem will benefit massively from the adjoint method is my prediction. You have 9 states, but about 130 parameters!!! This would qualify the adjoint ODE method to perform a lot faster. "
EDIT: tagging @s.maskell since he is the Lead Researcher of CoDatMo’s Liverpool and will benefit from this discussion.
References
Hurtado, P. J., & Kirosingh, A. S. (2019). Generalizations of the “Linear Chain Trick”: Incorporating more flexible dwell time distributions into mean field ODE models. Journal of Mathematical Biology , 79 (5), 1831–1883. https://doi.org/10.1007/s00285-019-01412-w
Hurtado, P., & Richards, C. (2020). A procedure for deriving new ODE models: Using the generalized linear chain trick to incorporate phase-type distributed delay and dwell time assumptions. Mathematics in Applied Sciences and Engineering , 1 (4), 410–422. https://doi.org/10.5206/mase/10857