Marginal

Agent-Based Modelling

Simulating societies and ecosystems from the bottom up: what agent-based models are, cellular automata and the Game of Life, Schelling's segregation model, flocking, stochastic epidemics, percolation, the El Farol bar and minority games, zero-intelligence traders, exchange models of wealth inequality, calibration and validation, and emergence.

18 lessons in 2 units

Start your free trial14 days free. No card needed.
What you'll learn

18 lessons, one small step at a time

Each lesson states its goal, then works up to it in short steps with practice after each. A placement test at the start skips what you already know.

Rules & Emergence

8 lessons
  1. Agent-based modelsName the ingredients of an agent-based model, lay out its simulation loop, and tell when an ABM is the right tool.
  2. How many runs?Compute how many runs an ABM needs for a given precision, and report its results with intervals.
  3. Cellular automataRead an elementary cellular automaton's rule from its number, and name a rule from its table.
  4. Evolving a cellular automatonApply an elementary rule to a row of cells, and classify the behavior that rules produce.
  5. The Game of LifeApply the rules of the Game of Life to a cell, count neighbors in a patch, and describe what the rules produce.
  6. Flocking & collective motionCompute the order parameter of a group's headings, explain how local rules give global order, and compute a boid's steering update.
  7. Traffic & phantom jamsApply the Nagel–Schreckenberg rules to a car, compute traffic flow from density, and explain phantom jams.
  8. PercolationCompute percolation thresholds on trees, decide whether a fire crosses a forest, and explain the sharp transition.

Social & Economic Models

10 lessons
  1. Schelling segregationDecide whether a Schelling agent is content, explain how mild preferences produce segregation, and measure segregation.
  2. Opinion dynamicsCompute consensus probabilities in the voter model and updates in a bounded-confidence model, and explain how clusters and polarization form.
  3. Infection probabilitiesCompute one agent's chance of infection from several contacts, in one step and over several steps.
  4. Chance fade-outsCompute the chance that an outbreak fades out, from one introduction and from several, and explain how superspreading changes it.
  5. Minority gamesCompute the spread of random attendance in the El Farol problem, and explain the logic of minority games.
  6. Maximum market surplusFind the maximum total surplus of single-unit buyers and sellers, and the prices that achieve it.
  7. Zero-intelligence tradersCompute the allocative efficiency of a set of trades, and explain what zero-intelligence traders show about rules versus rationality.
  8. Exchange models of inequalityCompute shares, the median and the Gini coefficient of an exponential wealth distribution, and simulate the yard-sale exchange rule.
  9. Simulated momentsCompute the weighted distance between observed and simulated moments, and choose parameters by minimizing it fairly.
  10. Calibration & validationCalibrate a simulator with approximate Bayesian computation, and validate it on facts it was not tuned to.
Sample lesson

Agent-based models

Goal: Name the ingredients of an agent-based model, lay out its simulation loop, and tell when an ABM is the right tool.

In 1996 Joshua Epstein and Robert Axtell's Sugarscape grew trade, migration, inequality and epidemics from simple agents foraging on a grid. Agent-based models (ABMs) build societies and ecosystems from the bottom up: many autonomous agents follow local rules, and aggregate patterns emerge from their interactions rather than being assumed.

We will gather the ingredients, write the simulation loop, and finish with when to use one.

Step 1: Ingredients

Every ABM has four ingredients: agents with states and rules for updating them; an interaction structure, such as a grid, a network or a market, saying who affects whom; a schedule saying when agents update, since the order can change results; and randomness in choices or encounters. Nothing about the aggregate is assumed. In Sugarscape, agents differing in vision and metabolism forage on a landscape with uneven sugar, and a skewed wealth distribution emerges.

Such emergence is the point: a traffic jam can move backward while every car in it moves forward. Unlike a representative-agent model, where one agent stands for everyone, an ABM has many differing agents interacting, and running it many times shows which aggregate patterns the rules produce.

Step 2: The simulation loop

In code, an ABM is a loop. Create the agents and their environment; then at each time step go through the agents in the order the schedule sets, let each observe its neighbors and apply its rule, and record the aggregate statistics of interest. Repeat the steps for the length of the run, and repeat whole runs with different random seeds. Whether agents update one at a time, each seeing the others' latest states, or all at once from the previous step's states is part of the schedule.

Step 3: When to use one

ABMs complement equation-based models when heterogeneity, local interaction, bounded rationality or out-of-equilibrium dynamics matter. How jams form on a ring road, or how an infection moves through a contact network, depends on who meets whom, and suits an ABM; the price response of a single competitive market has a clean equation-based answer. Epstein's generative social science asks of any pattern: can you grow it from plausible rules?

The cost is that results can be hard to generalize and can hinge on choices, such as the update order or the network, that are hard to verify. And since one random run may be unrepresentative, results are reported over many runs.

In the app, each step ends with practice questions, new ones every time, and the lesson comes back later in spaced reviews.

Start Agent-Based Modelling

Lessons that need something you haven't learned yet bring it in first, from any course.

Start your free trial14 days free. No card needed.