19  Advanced Dynamics: Regimes, Networks, and Resilience

Status: Draft

v0.3

19.1 Learning Objectives

After reading this chapter, you will be able to:

  • Model systems with regime switching and tipping points
  • Understand network models and their causal commitments
  • Model dynamics on networks with heterogeneous nodes
  • Model multiagent networks with autonomous agents and strategic interactions
  • Understand higher-order interactions (hypergraphs) in multiagent systems
  • Implement interventions in multiagent networks (agent-level, policy, network, hypergraph)
  • Define and compute resilience and robustness as causal functionals
  • Apply advanced dynamics to ecological and biological systems

19.2 Introduction

This chapter extends basic deterministic and stochastic dynamics (Chapters 5-6) to advanced topics: regime switching, network dynamics, and system resilience. All these concepts operate in the Dynamical world—abstract temporal processes that are still not yet fully material. These advanced dynamics show how complex systems exhibit multiple attractors, spatial structure, and varying degrees of stability.

19.3 Regime Switching and Tipping Points

19.3.1 What Are Regimes?

Regimes are distinct modes of system behaviour (Hamilton 1994; Scheffer et al. 2009):

  • Ecological: Healthy vs degraded ecosystems
  • Biological: Active vs dormant states
  • Clinical: Responder vs non-responder trajectories
  • Economic: Boom vs bust periods

Key feature: Transitions between regimes are often abrupt or threshold-driven (tipping points).

19.3.2 Switching State-Space Models

A switching SSM includes:

  1. Discrete regime variable: \(S_t \in \{1, \ldots, K\}\)
  2. Regime-specific dynamics: \(f_k(X_t, A_t, \theta_k)\)
  3. Transition probabilities: \(P(S_{t+1} \mid S_t, X_t, A_t)\)

19.3.3 State Process

\[ X_{t+1} = f_{S_t}(X_t, A_t, \theta_{S_t}, U_{t+1}) \]

Dynamics depend on current regime \(S_t\). The system can switch between regimes based on state, interventions, or stochastic transitions.

19.3.4 Tipping Points

Tipping points are critical thresholds where small changes trigger regime shifts (Scheffer et al. 2009):

  • Bifurcations: Qualitative changes in system behaviour
  • Critical transitions: Sudden shifts between attractors
  • Hysteresis: Path-dependent transitions

Understanding tipping points is crucial for intervention design—small interventions near tipping points can have large effects.

19.4 Network Models: Interaction Structure

19.4.1 Types of Networks

19.4.1.1 Interaction Networks

Definition: Direct causal or mechanistic interactions between entities.

Example: Predator-prey interactions, gene regulatory networks, neural connections.

Causal commitment: Edges represent direct causal influence (a modelling assumption).

19.4.1.2 Co-Occurrence Networks

Definition: Statistical associations (correlations) between entities.

Example: Species co-occurrence, symptom co-occurrence.

Causal commitment: None—edges are associations, not necessarily causal.

19.4.1.3 Effective Networks

Definition: Inferred networks from data (e.g., Granger causality, partial correlations).

Example: Functional connectivity in neuroscience, inferred ecological interactions.

Causal commitment: Depends on inference method—may or may not represent causal structure.

19.4.2 Network Structure and Causal Assumptions

Network structure provides a compact representation of interaction structure. The graph \(G = (V, E)\) where:

  • \(V\) is the set of vertices (nodes / variables / agents)
  • \(E\) is the set of edges (directed or undirected interactions, depending on the model)

Different network structures (chains, forks, colliders, modules) correspond to different dependency patterns, all captured by the same graph-theoretic framework established in the Structural layer.

19.4.3 Sign Constraints and Modularity

  • Sign constraints: Edges can be positive (facilitation) or negative (inhibition)
  • Modularity: Clusters of densely connected nodes (communities/modules)
  • Trophic structure: Hierarchical structure (e.g., food webs)

19.5 Dynamics on Networks: Collective Behaviour

19.5.1 Node Dynamics

Each node \(i\) has a state \(X^i_t\) that evolves according to:

\[ X^i_{t+1} = f_i(X^i_t, \{X^j_t : j \in \text{Pa}(i)\}, A_t, U^i_{t+1}) \]

where \(\text{Pa}(i)\) are the parents of node \(i\) in the network (its direct inputs).

19.5.2 Homogeneous vs Heterogeneous

  • Homogeneous: All nodes have the same dynamics \(f_i = f\) for all \(i\)
  • Heterogeneous: Different node types have different dynamics (e.g., producers vs consumers)

19.5.3 Edge Dynamics

  • Static edges: Fixed interactions with constant strength
  • Dynamic edges: Interactions change over time based on node states or external factors

19.5.4 System-Level Behaviour

Network dynamics compose into system-level behaviour:

  • Synchronisation: Nodes converge to common dynamics
  • Cascades: Local perturbations propagate through network
  • Collective attractors: System-level equilibria emerging from node interactions

The graph structure (which nodes influence which others) constrains the possible dynamics, while the dynamics determine how the system evolves given that structure.

19.6 Multiagent Networks: Autonomous Agents and Strategic Interactions

19.6.1 From Nodes to Agents

The network models we’ve discussed so far treat nodes as passive entities whose states evolve according to fixed dynamics. Multiagent networks extend this framework by treating nodes as autonomous agents—entities that make decisions, respond to their environment, and interact strategically with other agents (Gilbert 2008; Bonabeau 2002; Wooldridge 2009).

In an agent-based model, each agent is a decision-making unit with internal state and update rules. Agents interact through the network structure, which determines who can affect whom.

This reframing enables us to model systems where:

  • Individual decisions compose into collective behaviour
  • Agent-level interventions (targeting specific agents) have system-level effects
  • Strategic interactions (agents respond to others’ behaviours) create complex dynamics

19.6.2 Agent Decision-Making

Each agent \(i\) makes decisions based on:

  • Local state: Their own state \(X^i_t\)
  • Neighbor states: States of connected agents \(\{X^j_t : j \in \text{Pa}(i)\}\)
  • Higher-order interactions: Multi-way interactions with groups of agents (requires hypergraphs)
  • Context: Global context \(C\) (e.g., environment, policy)
  • Uncertainty: Agent-specific noise \(U^i_t\)

Agent policy (decision rule): \[ A^i_t = \pi^i(X^i_t, \{X^j_t : j \in \text{Pa}(i)\}, \{X^G_t : G \in \text{HyperPa}(i)\}, C, U^{i,a}_t) \]

where:

  • \(\pi^i\) is agent \(i\)’s policy (decision rule)
  • \(\text{Pa}(i)\) are parents in the network (pairwise interactions)
  • \(\text{HyperPa}(i)\) are hyperedges containing agent \(i\) (higher-order interactions)
  • \(U^{i,a}_t\) is randomness in agent \(i\)’s decision-making

Agent state dynamics: \[ X^i_{t+1} = f_i(X^i_t, A^i_t, \{X^j_t : j \in \text{Pa}(i)\}, \{X^G_t : G \in \text{HyperPa}(i)\}, C, U^{i,x}_{t+1}) \]

Agent states evolve based on their decisions, neighbors’ states, and higher-order group interactions.

19.6.3 Higher-Order Interactions: Beyond Pairwise Graphs

Standard graphs (Graphs.jl) represent pairwise interactions—edges connect two nodes. However, many multiagent systems involve higher-order interactions where multiple agents interact simultaneously (Battiston et al. 2020; Benson et al. 2018):

  • Group meetings: Multiple individuals interact together (not just pairwise)
  • Coalition formation: Groups of agents form alliances
  • Multi-agent coordination: More than two agents coordinate actions
  • Collective decision-making: Groups make decisions together

For representing and manipulating higher-order relational structures, we provide a pure Julia hypergraph implementation (scripts/hypergraph.jl) that offers:

  • Hypergraphs: Edges can connect multiple nodes (perfect for multi-way agent interactions)
  • Simplicial complexes: Higher-dimensional structures for complex relationships
  • Petri Nets: Useful for modeling agent state transitions and interactions

Example: In epidemiology, a hyperedge could represent a group meeting where multiple individuals interact simultaneously, not just pairwise contacts. This is essential for modeling superspreading events and group transmission.

19.6.4 Strategic Interactions

Agents may respond to other agents’ actions strategically:

  • Best response: Agent \(i\) chooses action to maximise utility given others’ actions
  • Nash equilibrium: No agent wants to deviate unilaterally
  • Learning: Agents adapt strategies based on outcomes

This creates game-theoretic dynamics where agent decisions depend on what other agents do, leading to complex emergent behaviour (Fudenberg and Tirole 1991; Nowak 2006).

19.6.5 Interventions in Multiagent Systems

Multiagent networks support multiple intervention types, all with clear \(do(\cdot)\) semantics:

Agent-level interventions: \(do(A^i_t = a)\)

  • Force agent \(i\) to take specific action
  • Example: Vaccinate individual \(i\) (epidemiology)
  • Example: Subsidise firm \(i\) (economics)

Policy interventions: \(do(\pi^i \leftarrow \pi^*)\)

  • Change agent \(i\)’s decision rule
  • Example: Change individual’s contact behaviour (epidemiology)
  • Example: Change firm’s pricing strategy (economics)

Network interventions: \(do(G \leftarrow G^*)\)

  • Modify network structure
  • Example: Isolate individual \(i\) (remove edges) (epidemiology)
  • Example: Create/destroy connections between agents

Hypergraph interventions: \(do(H \leftarrow H^*)\)

  • Modify higher-order structure (using hypergraph implementation)
  • Example: Ban group meetings (remove hyperedges) (epidemiology)
  • Example: Create/destroy multi-agent coalitions

19.6.6 Multiagent Networks as CDMs

Multiagent networks are a natural instantiation of Causal Dynamical Models (CDMs) (see Chapter 28):

CDM components:

  1. Graph structure: Agent network \(G\) (and hypergraph \(H\) for higher-order interactions)
  2. Latent process: Agent states \(X^i_t\) with dynamics \(f_i(\cdot)\)
  3. Observation model: Observed agent behaviours \(Y^i_t\)
  4. Explicit noise: \(U^{i,x}_t\), \(U^{i,y}_t\), \(U^{i,a}_t\) for each agent
  5. Intervention operators: Agent-level, policy, network, hypergraph interventions
  6. Counterfactual semantics: Agent-level counterfactuals with shared noise

CDM capabilities:

  • Inference: Use StateSpaceDynamics.jl to infer latent agent states from observed behaviours
  • Forecasting: Predict future agent behaviours and system-level outcomes
  • Interventions: Simulate effects of agent-level, policy, or network interventions
  • Counterfactuals: “What would agent \(i\)’s outcome have been if they had behaved differently?”

Each agent is a unit with internal state and update rules. The network structure determines who can influence whom, the dynamics specify how states update through time, and interventions modify either behaviour rules or the interaction structure.

19.6.7 Implementation: Multiagent Networks in Julia

19.6.7.1 Agents.jl: Agent-Based Modelling Framework

Agents.jl (Datseris et al. 2022) is a comprehensive Julia package for agent-based modeling that provides:

  • Agent definitions: Define agents with properties and behaviours
  • Spatial structures: Grids, graphs, continuous space
  • Network support: Agents can interact via networks (using Graphs.jl)
  • Scheduling: Flexible agent activation and interaction
  • Data collection: Built-in tools for collecting agent and system-level data
  • Visualisation: Tools for visualising agent-based models
# Find project root and include ensure_packages.jl
project_root = let
    current = pwd()
    while !isfile(joinpath(current, "Project.toml")) && !isfile(joinpath(current, "_quarto.yml"))
        parent = dirname(current)
        parent == current && break
        current = parent
    end
    current
end
include(joinpath(project_root, "scripts", "ensure_packages.jl"))
# Load Agents.jl first to ensure @agent macro is available
# Agents.jl 6.3.1 provides improved performance and new utilities
using Agents
using Agents: run!, dummystep  # Import run! for automatic data collection
using Agents.Schedulers  # Import schedulers module
@auto_using Graphs CairoMakie StableRNGs DataFrames

# Activate SVG output for responsive figures

# Set seed for reproducibility
rng = StableRNG(1234)

# Define agent type
# Agents.jl uses struct definitions that subtype AbstractAgent
mutable struct Person <: AbstractAgent
    id::Int
    pos::Int  # Position in graph (node ID)
    state::Int  # e.g., 0=susceptible, 1=infected, 2=recovered
    behavior::Symbol  # e.g., :normal, :distancing
end

# Create network (using Graphs.jl)
g = erdos_renyi(50, 0.1, seed = 42)  # Random network with 50 agents, 10% connection probability

# Create model with network space
# GraphSpace requires graph and positions (one position per node)
# Use Graphs.nv to avoid namespace conflict with Agents.nv
node_positions = [[i] for i in 1:Graphs.nv(g)]  # Each node has its own position
space = Agents.GraphSpace(g, node_positions)

# Agent step function: agent makes decision based on neighbors
# This function will be passed to the model constructor (Agents 6.3.1)
function agent_step!(agent, model)
    # Get RNG from model (Agents 6.3.1)
    rng = model.rng

    # Get neighbors (agents connected in network)
    node_id = agent.pos  # Agent's position in network (node ID)
    # Access graph from model space using getfield (bypasses getproperty override)
    graph = getfield(model, :space).graph
    neighbor_nodes = Graphs.neighbors(graph, node_id)  # Neighbor nodes in graph (use Graphs.neighbors)
    # Access agents dict using getfield (bypasses getproperty override)
    agents_dict = getfield(model, :agents)
    # Use model[id] syntax (more efficient in Agents 6.3.1)
    neighbors_agents = [model[id] for id in neighbor_nodes if haskey(agents_dict, id)]

    # Simple decision rule: if any neighbor is infected, agent may change behaviour
    infected_neighbors = [n for n in neighbors_agents if n.state == 1]
    if length(infected_neighbors) > 0 && agent.behavior == :normal
        # Agent responds to infection risk
        if rand(rng) < 0.3  # 30% chance of adopting distancing
            agent.behavior = :distancing
        end
    end

    # State dynamics: infection spreads through network
    if agent.state == 0  # Susceptible
        for neighbor in neighbors_agents
            if neighbor.state == 1 && agent.behavior == :normal  # Infected neighbor, normal behaviour
                if rand(rng) < 0.1  # 10% transmission probability
                    agent.state = 1  # Become infected
                    break
                end
            end
        end
    elseif agent.state == 1  # Infected
        if rand(rng) < 0.05  # 5% recovery probability per step
            agent.state = 2  # Recover
        end
    end
end

# Model step function: system-level updates
# This function will be passed to the model constructor (Agents 6.3.1)
function model_step!(model)
    # Could add system-level dynamics here
    # For this example, no model-level updates needed
end

# ABM takes space as positional argument, scheduler and properties as keywords
# In Agents 6.3.1, we pass step functions when creating the model
model = ABM(Person, space;
            scheduler = Schedulers.Randomly(),
            properties = Dict(:rng => rng),
            agent_step! = agent_step!,
            model_step! = model_step!)

# Add agents to network nodes
# Each agent is placed on a node in the network
for i in 1:50
    add_agent!(Person(i, i, 0, :normal), i, model)  # Agent with ID i, position i, initial state 0, behavior :normal, on node i
end

# Run simulation
# Initialize: infect a few agents to start epidemic
for i in 1:5
    model[i].state = 1  # Infect first 5 agents (more efficient in Agents 6.3.1)
end

# Run simulation and collect data
# Agents.jl 6.3.1 provides run! with automatic data collection and progress meter
# This is more efficient than manual loops and provides better performance
using Agents: run!, dummystep

# run! automatically collects agent and model data
# In Agents 6.3.1, step functions are stored in the model, so we don't pass them to run!
# adata: agent-level data to collect (state, behavior)
# Returns DataFrame with step, id, and requested agent properties
# Benefits: Automatic data collection, progress meter, optimized performance
data, _ = run!(model, 100;
               adata = [:state, :behavior],
               showprogress = false)  # Set to true to show progress meter for long simulations

# Aggregate by time step for visualization
# Note: run! returns DataFrame with "time" column (not "step")
data_agg = combine(groupby(data, :time),
    :state => (x -> sum(x .== 0)) => :susceptible,
    :state => (x -> sum(x .== 1)) => :infected,
    :state => (x -> sum(x .== 2)) => :recovered,
    :behavior => (x -> sum(x .== :normal)) => :normal,
    :behavior => (x -> sum(x .== :distancing)) => :distancing
)
101×6 DataFrame
76 rows omitted
Row time susceptible infected recovered normal distancing
Int64 Int64 Int64 Int64 Int64 Int64
1 0 45 5 0 50 0
2 1 41 9 0 41 9
3 2 38 11 1 34 16
4 3 37 10 3 27 23
5 4 37 10 3 24 26
6 5 37 10 3 22 28
7 6 37 9 4 20 30
8 7 36 10 4 19 31
9 8 35 10 5 18 32
10 9 35 10 5 14 36
11 10 35 9 6 13 37
12 11 35 8 7 13 37
13 12 35 8 7 12 38
90 89 35 0 15 12 38
91 90 35 0 15 12 38
92 91 35 0 15 12 38
93 92 35 0 15 12 38
94 93 35 0 15 12 38
95 94 35 0 15 12 38
96 95 35 0 15 12 38
97 96 35 0 15 12 38
98 97 35 0 15 12 38
99 98 35 0 15 12 38
100 99 35 0 15 12 38
101 100 35 0 15 12 38

Basic multiagent network: agents interacting on a network structure

Visualization of epidemic dynamics and behavior adoption from multiagent network simulation

This example shows how agents make decisions based on their neighbors’ states (network structure), and how these individual decisions compose into system-level epidemic dynamics.

Note on Agents.jl 6.3.1 improvements: The code uses run! for automatic data collection, which is more efficient than manual loops and provides progress meters for long simulations. The model[id] syntax for accessing agents is also more efficient than id2agent() in Agents 6.3.1.

19.6.7.2 Higher-Order Interactions with Hypergraphs

For multi-way agent interactions, we use the Hypergraph type from CausalDynamics.jl that provides a clean API for higher-order causal interactions. This implementation supports:

  • Vertices: Agents in the system
  • Edges: Pairwise interactions between agents
  • Hyperedges: True multi-way interactions (groups of agents interacting simultaneously)

Unlike the pairwise representation (where a group meeting is decomposed into multiple edges), our hypergraph implementation represents group meetings as single hyperedges that connect all participants directly. This is essential for modeling many real-world multiagent systems where group dynamics cannot be reduced to pairwise interactions.

# Find project root and include ensure_packages.jl
project_root = let
    current = pwd()
    while !isfile(joinpath(current, "Project.toml")) && !isfile(joinpath(current, "_quarto.yml"))
        parent = dirname(current)
        parent == current && break
        current = parent
    end
    current
end
include(joinpath(project_root, "scripts", "ensure_packages.jl"))

@auto_using DAGMakie CairoMakie Graphs CausalDynamics

# Import hypergraph functions from CausalDynamics.jl
# This provides a clean API for higher-order causal interactions
using CausalDynamics: Hypergraph, add_hyperedge!, rem_hyperedge!, hyperedge_vertices
using CausalDynamics: incident_hyperedges, num_hyperedges, num_vertices, hyperedges

# Example: Multiagent network with group meetings
# Agents: A, B, C, D, E (vertices)
# Pairwise contacts: A-B, B-C, C-D (standard graph edges)
# Group meetings: Meeting1 = {A, B, C}, Meeting2 = {B, C, D} (hyperedges)

# Create hypergraph for multiagent system
hg = Hypergraph(5)  # 5 agents: A=1, B=2, C=3, D=4, E=5

# Add pairwise contacts (standard graph edges)
# Hypergraph forwards Graphs.jl functions to its underlying graph
Graphs.add_edge!(hg, 1, 2)  # A-B contact
Graphs.add_edge!(hg, 2, 3)  # B-C contact
Graphs.add_edge!(hg, 3, 4)  # C-D contact

# Add group meetings (hyperedges)
# Unlike edges (pairwise), hyperedges can connect any number of vertices
# This properly represents group interactions where all members interact simultaneously

# Meeting 1: Agents A, B, C interact together
meeting1 = add_hyperedge!(hg, [1, 2, 3])  # {A, B, C}

# Meeting 2: Agents B, C, D interact together
meeting2 = add_hyperedge!(hg, [2, 3, 4])  # {B, C, D}

# Query hypergraph structure
println("Number of agents (vertices): ", num_vertices(hg))
println("Number of pairwise contacts (edges): ", Graphs.ne(hg))
println("Number of group meetings (hyperedges): ", num_hyperedges(hg))
println()
println("Meeting 1 participants: ", hyperedge_vertices(hg, meeting1))
println("Meeting 2 participants: ", hyperedge_vertices(hg, meeting2))
println()
println("Hyperedges containing agent B (vertex 2): ", incident_hyperedges(hg, 2))

# Prepare the hypergraph structure for DAGMakie visualisation
# Convert the hypergraph to Graphs.jl format for visualisation
g_viz = SimpleDiGraph(num_vertices(hg))
# Add pairwise edges to the graph
for e in Graphs.edges(hg)
    if !Graphs.has_edge(g_viz, Graphs.src(e), Graphs.dst(e))
        Graphs.add_edge!(g_viz, Graphs.src(e), Graphs.dst(e))
    end
end
Number of agents (vertices): 5
Number of pairwise contacts (edges): 3
Number of group meetings (hyperedges): 2

Meeting 1 participants: Set([2, 3, 1])
Meeting 2 participants: Set([4, 2, 3])

Hyperedges containing agent B (vertex 2): Set([2, 1])

Visualization of multiagent network with pairwise contacts and group meetings

Key insight: Higher-order interactions (hypergraphs) are essential for modeling many real-world multiagent systems where group interactions cannot be reduced to pairwise interactions. The Hypergraph type in CausalDynamics.jl provides a simple yet powerful framework for representing and manipulating these structures, enabling interventions like \(do(H \leftarrow H^*)\) to modify group-level interactions (e.g., banning group meetings in epidemiology). For more advanced use cases, ACSets.jl provides additional categorical machinery for composing and transforming hypergraph structures.

19.6.8 Network Structure and Attractor Dynamics

The structure of agent networks (both pairwise graphs and higher-order hypergraphs) fundamentally shapes how systems evolve towards attractor states. This connection between network topology and attractor dynamics is central to understanding complex systems:

Pairwise networks (Graphs.jl): - Network topology constrains possible dynamics - Collective attractors emerge from node interactions - Basin of attraction depends on network connectivity - Resilience depends on network structure (e.g., hub removal affects recovery)

Higher-order networks (hypergraphs): - Hypergraph structure creates different attractor landscapes - Group interactions can stabilize or destabilize attractors - Multi-way interactions affect basin boundaries - Hypergraph interventions can shift systems between attractor states

Example: In epidemiology, the contact network structure determines: - Disease-free attractor: Stable when network is sparse or vaccination coverage is high - Endemic attractor: Stable when network is dense and transmission is high - Basin of attraction: Region of state space (initial conditions) that converge to each attractor - Tipping point: Critical network structure or vaccination threshold that triggers attractor transition

The hypergraph structure (group meetings) can create additional attractor states: - Group transmission attractor: Stable when hyperedges (group meetings) are frequent - Isolated group attractor: Stable when hyperedges are removed (social distancing)

Connection to FEP: The Free Energy Principle (see From Structure to Time: FEP and Attractors) explains why systems evolve towards attractor states. Network structure (graph/hypergraph) determines the free energy landscape, and systems minimize free energy by evolving towards attractor states. Interventions that modify network structure (e.g., \(do(G \leftarrow G^*)\) or \(do(H \leftarrow H^*)\)) change the free energy landscape, potentially shifting attractors or changing basin boundaries.

19.6.8.1 Interventions in Multiagent Networks

Interventions can target specific agents, policies, or network structure:

101×2 DataFrame
76 rows omitted
Row time infected
Int64 Int64
1 0 4
2 1 4
3 2 4
4 3 3
5 4 3
6 5 3
7 6 2
8 7 2
9 8 2
10 9 2
11 10 2
12 11 2
13 12 2
90 89 0
91 90 0
92 91 0
93 92 0
94 93 0
95 94 0
96 95 0
97 96 0
98 97 0
99 98 0
100 99 0
101 100 0

Intervention in multiagent network: vaccinating specific agents

Comparison of baseline vs vaccination intervention on epidemic dynamics

Key insight: Agent-level interventions (\(do(A^i_t = a)\)) have system-level effects through network propagation. This connects to Chapter 13-14 (interventions in dynamical systems) and Chapter 22-23 (interventional forecasting and policy evaluation).

19.6.8.2 Spatial Models with Distance Calculations

For spatial agent-based models (using GridSpace or ContinuousSpace), Agents.jl 6.3.1 provides utility functions for distance calculations. The following example demonstrates how to use these utilities:

Spatial model with distance calculations:
  Agents: 20
  Grid size: (10, 10)
  Simulation steps: 50
  Final healthy: 1
  Final infected: 19

Note on Agents.jl 6.3.1 utilities: The getid() function provides efficient agent ID retrieval. For spatial models, distance calculations can be implemented based on the space type: - GridSpace: Manhattan distance = |x₁ - x₂| + |y₁ - y₂| - ContinuousSpace: Euclidean distance = √((x₁ - x₂)² + (y₁ - y₂)²) - GraphSpace: Path distance via graph algorithms

This example demonstrates how distance-based interactions enable more realistic spatial agent models, where interactions depend on physical proximity rather than just network connections. The getid() utility (Agents 6.3.1) provides efficient access to agent IDs for comparisons.

19.6.8.3 Integration with StateSpaceDynamics.jl for Inference

For inference in multiagent networks, we can combine Agents.jl (simulation) with StateSpaceDynamics.jl (inference):

Fitting LDS via EM...  10%|█████                                             |  ETA: 0:00:14 ( 0.78  s/it)
Fitting LDS via EM... 100%|██████████████████████████████████████████████████| Time: 0:00:01 (80.49 ms/it)
([4.658130202490122 1.2778774639572252 … 12.079154514095315 13.584698399635643;;;], [5.485513846991888 3.5282175177394137 … 14.680476042146147 15.63693484217135;;;])

Inferring latent agent states from observed behaviors using state-space models

Observed infections vs state-space model fit and inferred latent state trajectory

This connects Observable (observed behaviours) → Dynamical (inferred latent states) → Structural (agent mechanisms), using state-space models to summarise complex multiagent dynamics in a lower-dimensional latent process.

Key insight: State-space inference enables us to infer latent agent states (e.g., infection status) from observed behaviors (e.g., contacts, symptoms), connecting to Chapter 12 (state-space models) and Chapter 19 (observational methods).

19.6.9 Example Applications

19.6.9.1 Epidemiological Multiagent Networks

Agents: Individuals in a population Network: Contact network (who interacts with whom) Higher-order: Group meetings (hyperedges) Agent decisions: Contact behaviour (who to meet, when) Interventions:

  • Vaccinate specific individuals: \(do(A^i_t = \text{vaccinated})\)
  • Change contact behaviour: \(do(\pi^i \leftarrow \pi^*)\) (e.g., social distancing)
  • Isolate individuals: \(do(G \leftarrow G^*)\) (remove edges)
  • Ban group meetings: \(do(H \leftarrow H^*)\) (remove hyperedges)

State-space model:

  • Latent: Individual infection status, immunity
  • Observed: Contacts, symptoms, test results
  • Inference: Infer who is infected from observed contacts/symptoms

19.6.9.2 Economic Multiagent Networks

Agents: Firms, consumers Network: Supply chains, market connections Higher-order: Cartels, coalitions (hyperedges) Agent decisions: Pricing, purchasing, production Interventions:

  • Subsidise specific firms: \(do(A^i_t = \text{subsidised})\)
  • Change pricing strategy: \(do(\pi^i \leftarrow \pi^*)\)
  • Create new market connections: \(do(G \leftarrow G^*)\)
  • Break up cartels: \(do(H \leftarrow H^*)\) (remove hyperedges)

19.6.9.3 Ecological Multiagent Networks

Agents: Individual organisms Network: Interaction network (predation, competition, mutualism) Higher-order: Group behaviours (flocking, herding) Agent decisions: Foraging, movement, reproduction Interventions:

  • Remove specific individuals: \(do(A^i_t = \text{removed})\)
  • Change behaviour: \(do(\pi^i \leftarrow \pi^*)\) (e.g., migration patterns)
  • Modify interactions: \(do(G \leftarrow G^*)\)

19.6.10 Connection to CDM Framework

Multiagent networks are a natural instantiation of CDMs (see Chapter 28):

  • Graph structure: Agent network \(G\) (and hypergraph \(H\) for higher-order interactions)
  • Latent process: Agent states \(X^i_t\) with dynamics \(f_i(\cdot)\)
  • Observation model: Agent behaviours \(Y^i_t\) (what is measured/recorded)
  • Interventions: Agent-level, policy, network, and hypergraph interventions
  • Counterfactuals: Agent-level counterfactuals with shared exogenous noise (unit identity)

This provides a concrete, implementable example of CDMs that readers can run and experiment with, bridging theory (CDM framework) and practice (multiagent systems).

19.7 Resilience and Robustness: System Stability

19.7.1 Stability

19.7.1.1 Local Stability

Local stability measures response to small perturbations near equilibrium (Strogatz 2014):

  • Eigenvalues: Linear stability analysis
  • Lyapunov exponents: Rate of divergence/convergence
  • Jacobian: Local linearisation

19.7.1.2 Global Stability

Global stability measures response to large perturbations:

  • Basin of attraction: Region of state space that converges to equilibrium
  • Global Lyapunov function: Energy-like function that decreases

19.7.2 Resilience

Resilience is the ability to recover from perturbations (Holling 1973):

  • Engineering resilience: Speed of return to equilibrium
  • Ecological resilience: Ability to maintain function despite perturbations
  • Recovery time: Time to return to equilibrium after perturbation

19.7.3 Robustness

Robustness is the ability to maintain function under variation (Kitano 2004):

  • Local robustness: Robustness to small parameter changes
  • Nonlocal robustness: Robustness to large parameter changes
  • Structural robustness: Robustness to structural perturbations (edge/node removal)

19.7.4 Resilience and Robustness as Causal Functionals

Resilience and robustness can be defined as model-based causal functionals—quantities computed from fitted generative models:

  • Resilience metrics: Computed from model dynamics (e.g., recovery time, basin size)
  • Robustness metrics: Computed from model structure (e.g., sensitivity to parameter changes)
  • Causal questions: “How does intervention \(A\) affect system resilience?” requires causal modelling

19.7.5 Intervention Effects on Resilience

Causal questions about resilience:

  • “How does removing a keystone species affect ecosystem resilience?”
  • “How does early intervention affect recovery from later shocks?”
  • “What interventions maximize system robustness?”

These require understanding how interventions modify system dynamics and structure, affecting attractor stability and recovery properties.

19.7.6 Network Structure, Attractors, and Resilience

The connection between network structure, attractor dynamics, and resilience is fundamental to understanding complex systems:

Network topology → Attractor structure → Resilience: - Graph structure (pairwise interactions) determines possible attractor states - Hypergraph structure (higher-order interactions) creates additional attractor states - Attractor stability depends on network connectivity and structure - Basin of attraction determines which perturbations lead to which attractors - Resilience depends on attractor stability and basin size

Example: Multiagent epidemic network: - Sparse network: Small basin for disease-free attractor, system easily transitions to endemic - Dense network: Large basin for endemic attractor, system resists transition to disease-free - Hypergraph structure: Group meetings (hyperedges) can create additional attractor states - Intervention: Removing hyperedges (banning group meetings) can shift attractor landscape, changing basin boundaries and resilience

Tools for analysis: - Graphs.jl: Analyze pairwise network structure and its effect on attractor dynamics - Hypergraphs (CausalDynamics.Hypergraph): Analyze hypergraph structure and higher-order interactions affecting attractors - Decapodes.jl: Compose subsystems and analyze how composition affects attractor landscape - Lux.jl + OrdinaryDiffEq.jl: Learn dynamics from data via UDEs and identify attractor structure

Connection to CDMs: In a CDM framework, network structure (graph/hypergraph) is part of the graph structure component, attractor dynamics are part of the latent process component, and resilience is a causal functional computed from the model. Interventions that modify network structure (\(do(G \leftarrow G^*)\) or \(do(H \leftarrow H^*)\)) affect attractor dynamics and resilience, enabling causal reasoning about system stability.

19.8 World Context

This chapter addresses advanced topics in the Dynamical layer: temporal processes that extend basic ODEs and SDEs:

  • Regime switching: Multiple dynamic attractors, tipping points
  • Network dynamics: Interaction structure and collective behaviour
  • Resilience and robustness: System stability as causal functionals

All these concepts operate in the Dynamical layer: time has entered, but we are still describing latent dynamics rather than measurement and data.

19.9 Key Takeaways

  1. Regime switching: Systems can have multiple dynamic attractors with threshold-driven transitions
  2. Network models: Interaction structure creates complex system behaviour
  3. Dynamics on networks: Node and edge dynamics compose into system-level behaviour
  4. Multiagent networks: Nodes as autonomous agents enable modeling of individual decisions composing into collective behaviour
  5. Higher-order interactions: Hypergraphs enable modeling of multi-way agent interactions beyond pairwise (see CausalDynamics.Hypergraph)
  6. Interventions in multiagent systems: Agent-level, policy, network, and hypergraph interventions with clear \(do(\cdot)\) semantics
  7. Multiagent networks as CDMs: Natural instantiation of Causal Dynamical Models where agents are stateful decision-making units
  8. Network structure and attractors: Graph and hypergraph structure determines attractor landscape, basin boundaries, and system resilience
  9. Resilience: Ability to recover from perturbations—a causal functional that depends on attractor stability and basin size
  10. Robustness: Ability to maintain function under variation—a causal functional that depends on network structure and attractor dynamics
  11. Still dynamical: These advanced topics focus on dynamics; measurement and estimation live in the Observable layer

19.10 Package Updates and Improvements

This chapter benefits from updated package versions:

  • Agents.jl 6.3.1: Improved performance, automatic data collection via run!, progress meters, and new utility functions
  • GraphMakie.jl (fork with Graphs 1.x): Enhanced graph layouts, better styling options, support for larger graphs
  • Decapodes.jl (fork with CombinatorialSpaces 0.9): Better composition capabilities and stability
  • DiagrammaticEquations.jl (fork): Updated compatibilities enable better integration

Key improvements in code examples: - Automatic data collection using run! instead of manual loops - Enhanced graph visualizations with better layouts - More efficient agent access using model[id] syntax - Progress meters for long simulations (set showprogress = true)

19.11 Further Reading

  • Hamilton (1994): Time Series Analysis — Regime switching models
  • Scheffer et al. (2009): “Early-warning signals for critical transitions”
  • Newman (2018): Networks — Network theory
  • Barrat et al. (2008): Dynamical Processes on Complex Networks
  • Datseris et al. (2022): Agents.jl package for agent-based modeling in Julia
  • Battiston et al. (2020): “Networks beyond pairwise interactions” — Higher-order networks and hypergraphs
  • Fairbanks (2025): ACSets.jl framework for higher-order relational structures (JuliaCon 2025)
  • Gilbert (2008): Agent-Based Models — Introduction to agent-based modeling
  • Wooldridge (2009): An Introduction to MultiAgent Systems — Multiagent systems theory
  • Fudenberg and Tirole (1991): Game Theory — Strategic interactions
  • Holling (1973): “Resilience and stability of ecological systems”
  • State-Space Models: Inferring Structure from Observations: How to infer these dynamics from observations
  • CDMs: The Unified Framework: How multiagent networks instantiate Causal Dynamical Models