Yet another virus sim, but this time combing Actors.jl and agents

I have implemented a toy agent based model using Actors.jl. Somehow I missed the existence of Agents.jl, but it is probably good to have a few different options.

At any rate it is possible to implement the agent model within the actor model. This also shows how to incrementally build up a model within a notebook. Actors.jl is naturally multi-threaded, so the simulation is to and new behaviours can be added to agents using message passing in the same way for any actor.

I’m not sure where I am going with this or how far I am goint to take it, so I thought I would just share it now.

https://palethorpe.gitlab.io/viral-agent-actor-sim/

6 Likes

How do you plan to fit it with observed data?
That’s usually the tricky part of agent based models: calibration and prediction/falsification.

3 Likes

I don’t; the underlying process is fundamentally chaotic and unpredictable. The slightest change in starting parameters of any model with multiplicative dynamics will result in wildly different results.

Furthermore the observed data is as much a function of testing and bureaucracy as the underlying process. It is not just missing some samples, there are systematic errors in testing which are obfuscated.

Agent based models are useful for exploring dynamical behaviors which you may be able to abstract and define mathematically and reason about logically, but you can’t falsify them with data in the typical sense. This doesn’t mean they are not useful though and actually the same applies to a model based on ODEs.

For example if you model the world as a fully connected graph and you remove all the edges to one vertex as soon the virus is detected in any other vertex. Your sim will show nobody being infected in that vertex most of the time (assuming the virus is easily detected) and you would expect to see the same in the real world. However if in the real world you consistently saw people getting infected, this would appear to invalidate the model, but more likely it shows that the data is unreliable or the virus is traveling in some undetected way.

This is a rather simple example which can be derived from pure graph/network theory or even just common sense, but a model can help discover less intuitive behaviors which may be difficult to figure out from first principles.

I am not sure falsifiability is the relevant metric; a data generating process that has support over the whole range of data is not falsifiable in the Popperian sense, but one can still relate it to the data (eg using likelihood-based methods; think of a normal-linear model as an example).

If your model is really chaotic, then I am not sure is much more useful for “exploring” the data than a random number generator. In contrast, a model based on ODEs combined with some observation noise can be taken to the data, critiqued, and improved. So I don’t think your comparison is fair, ODE-based models (and discrete versions) have been the staple of epidemiology.

There are methods to handle systematic measurement errors and survey biases — they just complicate the analysis, but do not necessarily make it impossible.

1 Like

Out of curiosity, what methods are used to correct for biases introduced by testing protocol?

A simple correction could condition the probability of being tested on the individual state (infected or not, or varying levels of disease progression), resulting in a data generating process that takes this into account.

1 Like

Sure, but the error is huge. You will get similar results running an agent based sim 100k times and taking the average, upper and lower bounds as taking the results of an ODE with appropriate margins of error.

Then it is more similar to the real phenomenon than fitting lines to past data. My point was that models based on ODEs, that are remotely realistic, are also extremely sensitive to slight variations in the starting parameters. The worst and best case figures are bounded by the total population size and whether the virus is airborn (for example), but you have huge variance within that because of the error in the initial parameters.

This doesn’t mean they are not useful, but they are also ‘chaotic’ because the underlying phenomenon is fundamentally chaotic, non-linear, multiplicative, complex, etc.

Discrete versions? I don’t know why people would restrict themselves to ODEs. Especially when the underlying phenomena lends itself to graph theoretic interpretations. Contagion is fundamentally discontinuous and spreads from one discrete body to the next via a distinct intermediary.

Stochastic models are also useful if you are interested in identifying emergent behaviors, the same patterns form across multiple systems and can be isolated and abstracted. This is my point about disconnecting vertices, you don’t see that in a pure ODE, but in cellular automata and agent based sims you can experiment with it and then mathematically formalise it. Create policy based on it (i.e. automatically restrict travel between ‘vertices’, like airports, based on some rules) because you logically know it will be effective within reasonable bounds.

Depends on the error, you can’t account for unknown unknowns other than to set large error bounds based on limiting factors (like population size). There is also the risk that people massage the data until it shows what they want., although don’t take this to mean that I’m saying you shouldn’t try to work with the data. I’m just saying the error is much larger than people think.

This is something else you can experiment with using agent based models by sampling the model and comparing it with the underlying results. Because in a simulation, you have perfect information, unlike real life where you are looking through a tiny pin prick at reality.

To be clear, I only created this to explore emergent behaviors common to ‘complex systems’ and see whether I could implement an agent based model with Actors. In the second line of the notebook I have written “Of course this is not a remotely realistic model, it is just supposed to show some general effects observable in any complex system which resembles viral spread.”

It so happens that I don’t think any of the existing models floating around are that realistic (outside of a lab) either, but that is getting off-topic.