What

With particle simulations we can simulate the behaviour of particles in an environment. Such simulations can be used across many fields of science and engineering. The following demonstrates how a basic particle simulations can be used for disease spread simulations.

Technically it’s C-Code, compiled to WebAssembly, that draws onto a pixel buffer that is displayed in an HTML canvas. This is more about demonstrating very basic particle simulation than about an accurate disease model.

Note: For this to work your browser needs to support WebAssembly. The simulation works on the mobile phones I’ve tested, but it’s built for desktop, so it may be difficult to hit the buttons.

Downloading...

When

I’ve been using such simulations in the past for location estimations of objects. There are many applications of particle simulations such as locaiton estimation for robots, congestion simulation, water flow simulation, etc.

As an intermediate to test the framework I’m building we can run a simulation of disease spread.

Why

Particle Simulations can also be used for position estimation. For this the particles are thought of as positional estimates with a probability weighting assigned to each of them. Over time, with a model of the robots motion and sensory input from distance sensors, we can adjust the probability weighting assigned to each particle to improve our “guess” of where the robot is.

For a disease spread model we can use the probability weighting of each particle as the probability that it carries an infectious disease. A simulated coughing person infects the particles around him with every time he coughs and the motion model corresponds to the wind/air movements in the room. Other people in the room get infected when they come in contact to a high enough quantity of infected particles.

Background

With the current pandemic came a number of measures to contain the disease. We currently have masks, minimal distances, vaccinations, but also requirements for ventilation in public buildings such as schools. The health ministry has set a certain amount of time - x minutes - in which a not infected person can be in close proximity to an infected person before being categorized as a “contact person” that is then mandated to enter quarantine.

The question arises how this x amount of minutes was derived.

Two options that come to mind are:

How

As with the Smartphone Apps for infection tracing where Bluetooth beacons are considered to propagate similarly to infectious particles in the air, the particle simulations are also just a highly inaccurate estimation - yet they are something.

The inaccuracies in particles simulations for disease spread stem from the high number of required parameters.

For a very basic simulation and to only demo particle simulations I’ve come up with three basic variables:

I’ll be simulating only a single contagious person at a specific position, with a specific floor plan and a number of people at fixed locations around the floor plan.

For the simulation we need equations on how the particles behave. For this I’m using the following basic equations:

spreadFactor

The spreadFactor controls how much infectious particles are emitted by the infected person. For this, in each iteration, we want to increase the probability that a particle carries the infectious disease. For this I’m using the normalized distance times the spread factor times an arbitrary 10 to increase the impact.

  for(uint16_t i = 0; i < PARTICLES_COUNT; i++) {
    float dist = distance(particles[i].rect, infectiousPerson);
    float factor = cfgSpreadFactor * 10 * (1/sqrt(dist));
    particles[i].probability += factor;
  }

reductionFactor

The reductionFactor controls how much infectious particles loose their “infectiousness”. So in each iteration we reduce the probability of all factors by a a factor. The factor controls how harsh the environment is to the infected particles. It is reduced by 1000 to reduce it’s effect and give the simulation a somewhat realistic feel.

  for(uint16_t i = 0; i < PARTICLES_COUNT; i++) {
    particles[i].probability -= cfgReductionFactor / 10;
    if(particles[i].probability < 0) particles[i].probability = 0;
  }

contagionFactor

How fast a not infected person becomes infected upon contact with infected particles is controlled by the contagionFactor. Here I’m computing the distance between a particle and the a person. If it is below 1.3, then the particle is considered close enough to have an impact. In that case the particles probability to be infected times the contagionFactor is added to the probability of infection. Afterwards I’m dividing by five to give use a controllable range of 0 and 1 for the factor.

for(int personId = 0; personId < 6; personId++) {
  float probability = 0;
  for(uint16_t particleId = 0; particleId < PARTICLES_COUNT; particleId++) {
    float dist = 1/sqrt(1/distance(particles[particleId].rect, m_modelPeople[personId].rect));
    if(dist < 1.3) {
      probability += particles[particleId].probability * cfgContagiousFactor;
    }
  }
  m_modelPeople[personId].probability += probability / 5;
}

Limitations

Of course this is a very limited simulation with arbitrary factors. In a more scientific approach one would justify each of the factors by empirical experimentation. One would likely simulate hundreds of common floor plans, use more factors and derive those factors from empirical studies. But this here is just basic experimentation to demonstrate the basics of particle simulation.

Progress

The particle simulation framework I’ve written for my robot localization experiments was adapted for this basic disease spread simulation. I’m using my C-Code UI-Library to draw the floor plan and user interface. The code was then dropped in WebAssembly to get the interactive demo application that you can see above.

We can play with the three factors and see how it effects the simulation.