A single technique to model forest fires, pandemics and economies

Exploring interacting agent modelling in Python

Grant Holtes
Towards Data Science

--

Pandemics, bushfires and economic crisis. Not only the menu for the last year but a small subset of the phenomena that can be modelled under the framework of agent based modelling (ABM).

Image from Unsplash

ABM is well suited to understanding how complex behavior emerges in systems based on simple interactions between the system’s individual participants. ABMs have shown particular strength in explaining general observations, referred to as ‘stylized facts’, such as observed neutron scattering patterns or the distribution of asset returns. These agents could be anything from people or companies to animals in an ecosystem or atoms in a gas. This approach to modelling is a bottom up approach, where the system’s behavior is completely driven by assumptions on participants’ individual behavior, rather than a top down approach which assumes on how the participants will behave together.

A simple example of this is wildfire modelling, with each agent representing a small area of land. The rules for each patch of land can be extremely simple: If the land is on fire, set downwind neighbouring patches of land alight until all fuel in the patch is burnt. Despite these simple rules, the behavior of the wildfire system as a whole displays complex behavior. Furthermore, exploring the effects of changing assumptions such as making fire spreading probabilistic or introducing fuel regrowth only requires the rules around interactions between land patches to be altered, leaving the model framework unchanged. This aids in rapid experimentation and testing of assumptions.

A wildfire ABM with two ignition points. Original graphic

Rapid experimentation isn’t the only advantage of ABM over top down approaches. Accounting for variation in the individuals being modelled can introduce significant complexity in a top down model while being a trivial change in an agent based approach, as this heterogeneity can be captured by varying individual agents. This can be used to capture differences such as varying fuel levels in wildfire simulations or create populations of agents that mimic the census data for epidemic models.

The ABMs are not limited to agents interacting in simulated physical space, with the model framework extending to non-physical limitations on agent interaction such as limiting agents to only interacting with others that they ‘know’. This allows for social heterogeneity to be introduced, with many agents belonging to closed social circles while fewer highly social agents bridge these circles.

This is achieved in the simple epidemic model below through expressing the agents social connections as a network with small-world properties.

Simple ABM epidemic model with small world interactions. Original graphic

This also allows us to explore the stylized facts around how limiting social interaction affects the duration and intensity of the epidemic. In the model this is achieved by reducing the average connections in the network, which is akin to individuals reducing the physical contacts to only their closest friends and family.

Same epidemic model as above, but with 40% fewer the social connections. Original graphic

Another key advantage of ABM is the explainability of the underlying assumptions, which can provide confidence in the results and make findings easier to communicate. For example, the top down analysis of income inequality and the impact of taxation is usually highly mathematical and very abstracted from individuals, making communication of policy decisions a consistent challenge.

Income equality under various tax schemes — a higher gini coefficient indicates higher inequality. Original graphic

On the other hand, a bottom up ABM approach allows for the model to be reduced to only three steps, which are repeated by agents each cycle: 1) randomly trade with agents that they have social links to, as in the epidemic model; 2) pay tax on income from trades and receive welfare payments if wealth is below a minimum level; 3) incur a fixed living expense and receive interest on savings. Noting that these assumptions say nothing about the work ethic or productivity of each agent, the stylized facts from the model still emulate those found in top down models, particularly that flat tax results in much higher wealth inequality (measured as the Gini coefficient) than progressive tax, and that welfare payments are required to prevent fixed living costs from bankrupting a large proportion of the agents.

Unfortunately there is often a lack of knowledge around these underlying assumptions and inputs, as relevant data on the systems in question is usually captured at an aggregate level rather than an individual level. Furthermore, the model outputs are often sensitive to the inputs used which can greatly limit use in forecasting and erode confidence.

One solution is to capture the assumptions as a set of parameters, then optimise the parameters to fit historical data, running the model for various parameter combinations until the model outputs match the observed data. The parameters from this tuned model are then used for ongoing forecasting or modelling exercises. This practice increases confidence in the insights generated and provides stronger links between the simulated and real worlds.

While ABM techniques do not replace traditional top down approaches, they do offer an alternative perspective and in some cases provide a method to approach problems that would be too complex to define in a top down manner or where the agents display a great deal of heterogeneity. While there is a level of technical skill required to write and test ABMs, this learning curve flattens due to the reusability of the model framework and the existence of open source libraries such as Mesa for Python which provide the general framework for agents, agent interactions and data capture. Finally, confidence in model results is increased through simple-to-communicate assumptions and methodologies. This is further tested and refined by basing model inputs on known real world data and optimising parameters to fit historical observations.

This story is the first in a series on agent based modelling, and is based on my own research and experimentation with building ABMs. If you want to follow along please consider following my profile or this publication.

Some sources are below:

https://www.sciencedirect.com/science/article/pii/S1755436517300221

https://www.bankofengland.co.uk/-/media/boe/files/quarterly-bulletin/2016/agent-based-models-understanding-the-economy-from-the-bottom-up.pdf

--

--