4 min read
On this page

Agent-Based Modeling

Overview

Agent-based modeling (ABM) simulates a system as a collection of autonomous decision-making entities (agents) interacting within an environment. Unlike top-down approaches that specify aggregate equations, ABM generates macro-level patterns from micro-level rules — a phenomenon called emergence.

Agent Design

Attributes

Each agent carries state: position, health, wealth, preferences, knowledge, memory. Attributes may be heterogeneous across the population.

STRUCTURE Agent
    id: integer
    x: real
    y: real
    energy: real
    infected: boolean
    days_infected: integer
    immunity: boolean

Behaviors

Agents act according to rules executed each time step:

  • Perception — Observe local neighborhood or receive messages
  • Decision — Apply rules, heuristics, or optimization to choose an action
  • Action — Move, consume, trade, communicate, reproduce

Decision models range from simple (threshold rules) to complex (reinforcement learning, utility maximization, bounded rationality).

Communication

  • Direct — Agent-to-agent messaging
  • Indirect (stigmergy) — Through environmental markers (ant pheromone trails)
  • Network-mediated — Messages flow along social or physical network edges

Environment Modeling

Grid (Cellular) Spaces

Discrete cells, each with state. Agents occupy cells and interact with neighbors (von Neumann 4-cell, Moore 8-cell neighborhoods).

┌───┬───┬───┬───┬───┐
│   │ N │   │   │   │
├───┼───┼───┼───┼───┤
│ W │ A │ E │   │   │  von Neumann: N, S, E, W
├───┼───┼───┼───┼───┤
│   │ S │   │   │   │
└───┴───┴───┴───┴───┘

Continuous Spaces

Agents have real-valued coordinates. Spatial queries (nearest neighbors, agents within radius) use spatial indexing structures (k-d trees, grids).

// Find all agents within radius r of position (cx, cy)
PROCEDURE NEIGHBORS_WITHIN(agents, cx, cy, r) → list of indices
    r_sq ← r * r
    result ← empty list
    FOR i ← 0 TO LENGTH(agents) - 1 DO
        dx ← agents[i].x - cx
        dy ← agents[i].y - cy
        IF dx * dx + dy * dy ≤ r_sq THEN
            APPEND i TO result
    RETURN result

Network Spaces

Agents are nodes in a graph. Interactions occur along edges. Network topology profoundly affects dynamics:

  • Random (Erdos-Renyi) — Short average path, no clustering
  • Small-world (Watts-Strogatz) — Short paths + high clustering
  • Scale-free (Barabasi-Albert) — Power-law degree distribution, hubs

Emergent Behavior

Emergence occurs when aggregate patterns are not explicitly coded into agent rules.

Classic examples:

  • Schelling segregation — Mild individual preferences for same-type neighbors produce extreme spatial segregation
  • Flocking (Boids) — Three simple rules (separation, alignment, cohesion) produce realistic flock behavior
  • Traffic jams — Phantom jams emerge from individual braking behavior with no external cause
  • Market crashes — Herding behavior among traders amplifies price movements

SIR Epidemic Model Example

ENUMERATION State ← {SUSCEPTIBLE, INFECTED, RECOVERED}

STRUCTURE EpiAgent
    x: real
    y: real
    state: State
    days_infected: integer

PROCEDURE STEP(agents, infection_radius, infection_prob, recovery_days)
    snapshot ← COPY(agents)

    FOR EACH agent IN agents DO
        IF agent.state = SUSCEPTIBLE THEN
            // Check nearby infected agents
            FOR EACH other IN snapshot DO
                IF other.state ≠ INFECTED THEN CONTINUE
                dx ← agent.x - other.x
                dy ← agent.y - other.y
                IF dx*dx + dy*dy ≤ infection_radius * infection_radius THEN
                    IF RANDOM_UNIFORM(0, 1) < infection_prob THEN
                        agent.state ← INFECTED
                        BREAK

        ELSE IF agent.state = INFECTED THEN
            agent.days_infected ← agent.days_infected + 1
            IF agent.days_infected ≥ recovery_days THEN
                agent.state ← RECOVERED

        // RECOVERED: do nothing

        // Random walk
        agent.x ← agent.x + RANDOM_UNIFORM(-1.0, 1.0)
        agent.y ← agent.y + RANDOM_UNIFORM(-1.0, 1.0)

Calibration and Validation

Calibration

Adjust model parameters so outputs match observed data:

  • Manual tuning — Expert-guided, suitable for few parameters
  • Optimization-based — Minimize distance between model output and data (genetic algorithms, Bayesian optimization)
  • Approximate Bayesian Computation (ABC) — Posterior over parameters without explicit likelihood

Validation Challenges

ABM validation is harder than equation-based models because:

  • Stochastic outputs require many replications
  • Emergent behavior may be sensitive to initial conditions
  • Multiple parameter sets can produce similar macro-level outputs (equifinality)

Approaches:

  • Pattern-oriented modeling — Validate against multiple observed patterns simultaneously, not just a single aggregate statistic
  • Cross-validation — Calibrate on one dataset, validate on another
  • Sensitivity analysis — Identify which parameters matter most

Platforms and Frameworks

| Platform | Language | Strengths | |----------|----------|-----------| | NetLogo | NetLogo | Education, rapid prototyping, visual | | Mesa | Python | Flexible, integrates with data science stack | | Repast | Java/C++ | Large-scale, HPC support | | MASON | Java | Performance-oriented, extensible | | GAMA | GAML | GIS integration, spatial models | | Custom (Rust) | Rust | Maximum performance, full control |

Applications

Epidemiology

Model disease spread with heterogeneous contact patterns, behavioral responses to interventions, and spatial movement. Agents represent individuals with age, location, health status, and compliance behavior.

Economics

Artificial markets with heterogeneous traders, bounded rationality, and learning. Reproduce stylized facts: fat-tailed returns, volatility clustering, bubbles and crashes.

Ecology

Species interactions, predator-prey dynamics, habitat fragmentation effects, invasive species spread. Agents represent organisms with energy budgets and reproduction rules.

Traffic

Vehicle agents with car-following and lane-changing rules. Study congestion formation, evaluate traffic control strategies, model autonomous vehicle interactions.

Urban Systems

Land-use change, residential mobility, infrastructure demand. Agents represent households making location decisions based on price, commute, amenities.

Scalability Considerations

  • Spatial indexing — Avoid O(n²) neighbor searches with spatial hashing or tree structures
  • Parallel execution — Partition space across threads/cores; handle boundary synchronization
  • Batch execution — Run many replications across a cluster for sensitivity analysis
  • Simplified agents — Use agent archetypes instead of fully unique agents when heterogeneity in certain attributes is unimportant

Design Principles

  1. Start simple — Begin with minimal agent rules, add complexity only when needed to reproduce target patterns
  2. Document assumptions — Every behavioral rule embodies an assumption about real behavior
  3. Separate stochasticity from structure — Use controlled random seeds for reproducibility
  4. Multiple replications — Always report distributions, not single runs
  5. ODD protocol — Use the Overview, Design Concepts, Details protocol for standardized model description