What is this?

This is a simulation of how a virus spread over the population. The simulation is heavily inspired by the SIR model. SIR is a technique used to simplify the mathematical modelling of infectious disase.

In the SIR model, we have three different states of each agent (a person). The first state isSUSCEPTIBLE, second one is SICK, and the last one is RECOVERED. We have also a DEAD state in this simulation.

How does it work?

Every agent starts with the `SUSCEPTIBLE` state in the simulation, except a few of them. Some of the agents are on the `SICK` state at the very beginning. Over the time, sick agents spread the virus to rest of the population and the other agents get sick as well. After the infection, they switch into a recovered or a dead state based on some probabilistic values.

The probabilistic values are defined in a markov-chain concept. Markov chain is a stochastic model to describe a sequence of possible events that can occur in the future.

How does a probabilistic model look like?

We're using a markov graph to define a probabilistic transition. We can simply say that markov chain is a graph of all the possible state transitions of an individual node.

In a infectious disaese case, we can use markov chains to define the probabilistic chain of an person to be inftected, to be recovered, or to be dead. Furthermore, we can also define the possible travel route of an agent by using the same technique.

How can we define a probabilistic model of an infecitious disease?

As I previously mentioned, we can use the SIR model to set up the simulation, and we can use markov chains to define probabilistic model of an infectious disaese.

I would like to give a disclaimer that, I'm just an open-source developer who loves building data visualizations and simulations, I don't have a background of Epidemiology or other related stuff. Please don't take my assumptions seriously.

Here's the state transition map of an agent over the time.

const SIR_TRANSITION_STATE = { [SUSPECTIBLE]: [ [1, SUSPECTIBLE], ], [RECOVERED]: [ [1, RECOVERED], ], [SICK]: [ [0.995, SICK], [0.004, RECOVERED], [0.001, DEAD], ], [DEAD]: [ [1, DEAD], ], };

Simulation's clock ticks on each second. On each tick, all the agents are subject to that transition map. As you can see on that object, we have defined states as keys, and possible values of that specific state. For example, a susceptible person will be always suspectible, there's no any state change for that state, yet. But for a sick agent, there are two more possible states different than it's actual state. So the options are; staying as sick until the next state transition, being recovered, or being dead. The values defined before the next state is the probabilistic value.

const DISEASE_SPREAD_TRANSITION = { [SUSPECTIBLE]: [ [0.3, SICK], [0.7, SUSPECTIBLE], ], [RECOVERED]: [ [1, RECOVERED], ], [SICK]: [ [1, SICK], ], [DEAD]: [ [1, DEAD], ], };

The previous transition map was for a person who has no any interaction with a sick person. When an agent meets with a sick person, the possibility of getting sick is different. As you can see on this map, a susceptible person will get sick by the possibility of %30.

Question: In that map, people who already recovered from the virus develop an immunity and don't get sick again. How could we define the probabilistic map if the disease was super infectious and people who recovered don't gain any immunity?

Other simulations

If you liked that stuff, you can explore other simulations that I created in the past.

I would like to discover more

This is an MIT-licensed open-source project, you can find the source code on github. Feel free to copy, use or modify it for your own simulations.

https://github.com/fatiherikli/coronavirus-simulation

Thanks for reading this article, and stay safe!

@fthrkl