Discrete models
💡 Previously on...
We covered philosophy of (scientific) modeling and LHD's recipe for modeling. We distinguished between scale, analogical, idealized, and phenomenological models. Can you remember what is the difference between aristotelian and galilean idealized models? Why phenomenological models not understood as mecanistic models?
We then introduced compartment models by drawing diagrams. How do we distinguish the boxes from one another? What are the assumptions that go into building a models as boxes? What are we missing?
This week, we convert last week's boxes into discrete dynamical equations that we can do maths and compute. We start with the SIR model, and show how we can make it more heterogenous by introducing, for instance, different degrees of susceptibility, distinct removal status (e.g., long lasting sickness, dead, recovered), or infection awareness (e.g., asymptomatic).
In this video, LHD walkthroughs the SIS model and introduces the mean-field approximation:
We are now ready to convert the mathematics into code:
As an example, LHD imagines a cloning factory as idealized through the diagram below:
where
Poisson Processes
Something happens at a given (fixed) rate, regardless of what happens beforehand.Back to example above, every now and then (e.g., everyday if we assume
# Julia code
for t=1:Δt:T
if rand() < a*Δt
N_t += 1 # 'arrivals' (people getting into the building)
end
for n=1:N_t
if rand() < l*Δt
N_t -= 1 # 'departures' (people leaving it)
else
if rand() < c*Δt
N_t += 1 # 'cloning' (people cloning themselves)
end
end
end
end
A couple of observations here. What if a transition rate, say
Also, order matters. We are testing departure first, assuming that people can replicate only if they have not decided to leave the building. One could think of alternative situations where, during the same time step (which, remember, being finite allows for multiple processes to take place within it), people first try to clone themselves and then consider to leave; or, where recently arrived people are not allow to replicate or leave immediately after arrival (which would mean moving the `arrivals' code block to the end). In all cases, two events involving the same individual can never be simultaneous (in the factory, e.g., you can't leave while arriving or cloning yourself while leaving). Time discreteness forces us to hardwire the order of the potential events.
In the clip below, LHD shows how both these issues – transition probabilities larger than one and time ordering of competing events – are solved by considering small enough (eventually infinitesimal) time steps.
...
Key properties of Poisson processes
P1: The rate
P2: Given
Things to do by Thursday at noon
Case study: discrete SIR
We review this week's key concepts by analyzing the discrete-time SIR model. For each contact between a susceptible and an infected individual, an infection event occurs with probability
We already saw in the second clip how to derive the probability that a susceptible individual gets the infection via at least one infectious contact. It reads
We thus get the following system of three equations
In code (taking
function runMAthDiscreteSIR(steps, N, β, γ) {
// Initialize
let I = 1, R = 0
let S = N - I - R;
// Pre-allocated arrays (faster)
let St = new Array(steps);
let It = new Array(steps);
let Rt = new Array(steps);
// Observe
for (let step = 0; step < steps; step++) {
St[step] = S;
It[step] = I;
Rt[step] = R;
// Update
let delta_I = S*(1 - Math.pow(1 - β, I))
let delta_R = γ*I
S -= delta_I;
I += delta_I - delta_R;
R += delta_R;
}
return [St, It, Rt];
}
...
The model above is deterministic as it only tracks the expected values of the number of individuals in each compartment. Such formulation is exact only for a system of infinite size, as fluctuation around the mean becomes negligible. The stochasticity of the contagion process thus never disappears for a system of finite size (aka, real-world systems). We can see this by simulating the process using random variables. In this case, we rely on the Binomial distribution, which helps us determine how many successful events occur – such as how many susceptible individuals become infected – based on the probability of infection derived from the expected rate. The code remains largely the same, but we adjust how we update key quantities.
function runCompDiscreteSIR(steps, N, β, γ) {
[...]
for (let step = 0; step < steps; step++) {
[...]
// We use our previously defined math as probability of infection in the Binomial distribution
let p_inf = 1 - Math.pow(1 - β, I);
let new_I = Binomial(S, p_inf);
let new_R = Binomial(I, γ);
// Update
S -= new_I;
I += new_I - new_R;
R += new_R;
[...]
}
Click the button below to run a simulation and compare with the prediction made by the mathematical model:
Because of stochasticity, there are variation in draws. Notice, in particular, how from time to time the stochastic process goes extinct before an exponential growth can take place. With only the derministic model in our hand, when should we expect the process to be likely to take off? Imposing
Linear stability analysis and criticality
This is the art of nudging a little our system around a fixed point to determine the (local) stability of that point. If following the perturbation the system tends to go back to that point, then the latter is said to be stable. It is unstable if the systems tends to move away from it, or neutrally stable if the perturbation neither grows or shrinks.
For our case study, we want to know the conditions under which the generic fixed point
It follows that
We considered a population of size
We can get a more detailed view of this transition if we look at the distribution of outbreak sizes. That is, we choose a value for
You may have noticed that the plot above has both its axis in logarithmic scale. The reason is that it allows to get a first, visual check of whether the system is or not at a critical point. How? Setting
Bonus content
Lhd introducing Taylor Series and L'Hospital rule
Obligatory reference to 3b1b on L'Hôpital's rule
And Taylor Series