Table of Contents
Fetching ...

Automatic Differentiation of Agent-Based Models

Arnau Quera-Bofarull, Nicholas Bishop, Joel Dyer, Daniel Jarne Ornia, Anisoara Calinescu, Doyne Farmer, Michael Wooldridge

TL;DR

This work demonstrates that automatic differentiation can be effectively applied to complex, discrete, and stochastic agent-based models to yield gradients through ABMs. By combining pathwise gradient methods and surrogate-gradient techniques, the authors enable gradient-based calibration via generalized variational inference and perform efficient sensitivity analyses, validated across three canonical ABMs: AMOF, Sugarscape, and a network-based SIR model. The study provides practical guidance on differentiable ABM construction, compares gradient estimators under different connectivity regimes, and shows that pathwise gradients scale better in high-dimensional parameter spaces than score-based methods. The proposed hybrid AD strategy and Julia-based implementation offer a scalable pipeline for gradient-based calibration and analysis of ABMs, with broad implications for policy analysis and complex-system science.

Abstract

Agent-based models (ABMs) simulate complex systems by capturing the bottom-up interactions of individual agents comprising the system. Many complex systems of interest, such as epidemics or financial markets, involve thousands or even millions of agents. Consequently, ABMs often become computationally demanding and rely on the calibration of numerous free parameters, which has significantly hindered their widespread adoption. In this paper, we demonstrate that automatic differentiation (AD) techniques can effectively alleviate these computational burdens. By applying AD to ABMs, the gradients of the simulator become readily available, greatly facilitating essential tasks such as calibration and sensitivity analysis. Specifically, we show how AD enables variational inference (VI) techniques for efficient parameter calibration. Our experiments demonstrate substantial performance improvements and computational savings using VI on three prominent ABMs: Axtell's model of firms; Sugarscape; and the SIR epidemiological model. Our approach thus significantly enhances the practicality and scalability of ABMs for studying complex systems.

Automatic Differentiation of Agent-Based Models

TL;DR

This work demonstrates that automatic differentiation can be effectively applied to complex, discrete, and stochastic agent-based models to yield gradients through ABMs. By combining pathwise gradient methods and surrogate-gradient techniques, the authors enable gradient-based calibration via generalized variational inference and perform efficient sensitivity analyses, validated across three canonical ABMs: AMOF, Sugarscape, and a network-based SIR model. The study provides practical guidance on differentiable ABM construction, compares gradient estimators under different connectivity regimes, and shows that pathwise gradients scale better in high-dimensional parameter spaces than score-based methods. The proposed hybrid AD strategy and Julia-based implementation offer a scalable pipeline for gradient-based calibration and analysis of ABMs, with broad implications for policy analysis and complex-system science.

Abstract

Agent-based models (ABMs) simulate complex systems by capturing the bottom-up interactions of individual agents comprising the system. Many complex systems of interest, such as epidemics or financial markets, involve thousands or even millions of agents. Consequently, ABMs often become computationally demanding and rely on the calibration of numerous free parameters, which has significantly hindered their widespread adoption. In this paper, we demonstrate that automatic differentiation (AD) techniques can effectively alleviate these computational burdens. By applying AD to ABMs, the gradients of the simulator become readily available, greatly facilitating essential tasks such as calibration and sensitivity analysis. Specifically, we show how AD enables variational inference (VI) techniques for efficient parameter calibration. Our experiments demonstrate substantial performance improvements and computational savings using VI on three prominent ABMs: Axtell's model of firms; Sugarscape; and the SIR epidemiological model. Our approach thus significantly enhances the practicality and scalability of ABMs for studying complex systems.

Paper Structure

This paper contains 100 sections, 72 equations, 20 figures, 4 tables.

Figures (20)

  • Figure 1: The first and final time steps of a Sugarscape simulation. Warmer colours indicate grid cells with higher sugar reserves. In this case, the landscape is characterised by two high capacity sugar peaks. Agents, represented by white dots, are initially dispersed, but accumulate at each peak towards the end of the simulation.
  • Figure 2: Two methods for implementing the surrogate gradient method. In the left graph, the tangent pass is edited directly, whilst in the right graph function calls to $h$ are replaced by function calls to $h^{\dagger}$.
  • Figure 3: Computational graphs generated by conventional AD engines for if-else statements. The left graph corresponds to $\pi = 0$ (executing $v_0$) and the right graph corresponds to $\pi = 1$ (executing $v_1$). Only the executed branch appears in the computational graph.
  • Figure 4: The left panel visualises a single simulation of the Bernoulli random walk (\ref{['eq:walk']}) for $p=0.4$. The right panel depicts GS estimates of $d\mathbb{E}[X_{t}]/dp$ for $t=0, \ldots, 50$ under different temperature settings. Faint lines correspond to GS estimates from single simulation runs, whilst solid coloured lines show empirical averages across multiple runs.
  • Figure 5: The vision matrices $\mathbf{M}_{1}, \mathbf{M}_{2}, \mathbf{M}_{3}$ for $V=3$.
  • ...and 15 more figures