Agent-based modelling

Building Your First Agent-Based Model

Most agent-based models fail for the same reason: they are built to be realistic rather than to answer a question. Realism is unbounded, so the model grows until nobody can say what it shows.

· about 11 minutes

An agent-based model has four components, and they should be written down before any code exists: the agents and their attributes, the rules governing their behaviour, the environment or interaction structure, and the schedule that determines what happens in what order. Everything else is implementation.

Start with the question

The single best predictor of whether a model will be useful is whether it began from a question or from a system. "Model the housing market" produces a model that never ends. "Under what conditions does a mild preference for similar neighbours produce sharply segregated neighbourhoods?" produces Schelling's model, which fits on one page and has been productive for fifty years.

The question determines what the model must contain. Anything that does not affect the answer is a liability: it adds parameters, and each parameter is a dimension you must eventually justify.

Agents: as simple as the question allows

Agent rules should be the simplest thing that could produce the mechanism you are investigating. Optimising agents are rarely the right choice for social models - not because people never optimise, but because full optimisation requires knowledge that real agents do not have, and it makes the model's behaviour a consequence of that assumption rather than of the interaction you wanted to study.

Useful default rules, roughly in order of how often they turn out to be enough: copy the most successful neighbour; do what the majority of contacts did; keep doing what you did unless a threshold is crossed; choose randomly among options that clear an acceptability bar. These are behaviourally defensible and computationally cheap.

Interaction structure is a modelling choice, not a detail

Who can influence whom is often the most consequential decision in the whole model. The common options produce systematically different results:

  • Well-mixed. Every agent can meet every other. Convenient, and equivalent to assuming no structure at all. Fine as a baseline, misleading as a representation.
  • Spatial grid. Neighbours only. Produces local clustering and slow global diffusion.
  • Explicit network. Either empirical or generated. This is usually the honest choice for social systems; see network structure and measures for which generated structures are worth using.

Running the same behavioural rules on all three is one of the cheapest robustness checks available, and it frequently reveals that a headline result was a property of the interaction structure rather than of the behaviour.

Scheduling: the bug that hides

Whether agents update simultaneously or one at a time changes outcomes, sometimes qualitatively. Synchronous updating can produce artificial oscillations where the whole population flips back and forth. Asynchronous updating in a fixed order gives the agents at the start of the list a systematic advantage. Random asynchronous updating is usually right, and if your result depends on which you chose, that is a finding about the model rather than about the world.

Randomness and the meaning of one run

A single run of a stochastic model is an anecdote. Results are distributions over runs, which means fixing the seed for reproducibility, running enough replications to characterise the spread, and reporting that spread rather than a mean alone. Where the distribution is bimodal - the system settles into one of two regimes - the mean describes an outcome that never occurs.

Sweep before you conclude

A result at one parameter setting is not a result. Sweep each parameter across a defensible range and look for the boundaries where behaviour changes qualitatively. Those transitions are usually the real finding: not "segregation occurs" but "segregation occurs above a tolerance threshold of roughly one third, and the transition is sharp".

Then comes the part that decides whether any of it means anything: validation and calibration. For the practical side of what to build it in, see software and tools.

Keep reading

More under Agent-based modelling

Elsewhere on the site

Related notes