CMH MATH PATH — LESSON 8: AGENT-BASED MODELING

Simulating Societies from the Ground Up — How Simple Rules Create Complex Worlds


PART 1: THE CORE IDEA — EMERGENCE

The Ant Colony Mystery

Watch a single ant: it wanders randomly, seems confused.
Watch a colony: it builds intricate tunnels, finds shortest paths to food, assigns specialized roles.

No ant is in charge. No blueprint exists. Complexity emerges from simple rules.

The ant’s simple rules:

  1. Wander randomly
  2. If find food, drop pheromone while returning to nest
  3. Prefer to follow stronger pheromone trails
  4. Pheromone evaporates over time

The emergent colony behaviors:

  • Finds shortest path to food (mathematically optimal!)
  • Adapts when path blocked
  • Allocates appropriate number of workers

CMH Insight: Societies may work the same way! No central planner needed for markets, cities, or social norms to form.


PART 2: THE BUILDING BLOCKS OF AGENT-BASED MODELS (ABMs)

1. The Agents

  • What they are: Individuals (people, animals, cells, countries)
  • Properties: Age, wealth, location, beliefs, memories
  • Rules: How they behave, learn, interact

2. The Environment

  • Spatial: Grid, network, continuous space
  • Resources: Food, money, information
  • Institutions: Laws, norms, infrastructure

3. The Rules

  • Local: Agents interact only with neighbors
  • Simple: “If X, then do Y”
  • Adaptive: Agents learn from experience

4. Time Steps

  • Discrete ticks: day 1, day 2, day 3…
  • Each tick: Agents perceive, decide, act

The ABM Process:

Initialize agents & environment
↓
For each time step:
   For each agent:
      Perceive surroundings
      Apply rules
      Act
   Update environment
   Record data
↓
Analyze emergent patterns

PART 3: THE SCHELLING SEGREGATION MODEL — HOW MILD PREFERENCES CREATE EXTREME SEGREGATION

The Most Famous ABM in Social Science

Economist Thomas Schelling (1971) asked: How segregated would neighborhoods become if people only mildly prefer same-group neighbors?

Setup:

  • Checkerboard grid (like chessboard)
  • Two agent types: ○ and ●
  • Each agent wants ≥30% neighbors like themselves
  • If unhappy, agent moves to random empty spot

The rules (per agent):

1. Count neighbors in 8 surrounding cells
2. Calculate % same-type neighbors
3. If % < 30%, move to random empty cell
4. Repeat until happy or max moves reached

Run the simulation…

What Happens?

Initial state (random):

○ ● ○ ● ○ ●
● ○ ● ○ ● ○
○ ● ○ ● ○ ●
● ○ ● ○ ● ○  (Integrated: 50% similar neighbors)

After agents move:

○ ○ ○ ○ ● ●
○ ○ ○ ○ ● ●
○ ○   ● ● ●
● ● ● ● ● ●  (Segregated: >80% similar!)

The shocking result: A mild preference (30% similar neighbors) leads to extreme segregation (80-90% similar)!

Why? Local moves create global patterns. My move makes my old neighbors less happy (they lose a similar neighbor), making them move, creating a cascade.

CMH Application: Explains racial/ethnic segregation without assuming racism! Also explains political polarization, cultural clustering.


PART 4: SUGARSCAPE — HOW INEQUALITY EMERGES NATURALLY

A Simple World with Profound Lessons

Setup:

  • Grid landscape with “sugar” (resource) growing in mountains
  • Agents need sugar to survive, can store it
  • Agents have vision (1-5 cells), metabolism (1-4 sugar/tick)
  • Sugar regrows after harvest

Simple rules:

1. Look within vision range for cell with most sugar
2. Move there
3. Harvest sugar
4. Subtract metabolism (cost of living)
5. If sugar ≤ 0, die
6. If sugar > reproduction threshold, have child (with similar traits)

What emerges?

Four Emergent Phenomena:

1. Inequality: Some agents get rich, most stay poor

  • Why? Good starting position + good vision/metabolism → accumulate advantage
  • Matthew Effect: “To those who have, more will be given”

2. Wealth Distribution: Follows Pareto (80/20) law!

  • Top 20% agents hold ~80% of sugar
  • Matches real-world wealth distributions

3. Migration Waves: Agents move following sugar frontier

  • Like human migration following resources
  • Creates population waves

4. Class Structure:

  • Upper class: Good vision, low metabolism, central location
  • Working class: Poor vision, high metabolism, periphery
  • Classes persist across generations (inheritance!)

CMH Insight: Inequality emerges from simple rules + random variation, not from exploitation or oppression! (Though those can make it worse.)


PART 5: HANDS-ON ABM LAB

Exercise 1: Build Schelling’s Model in Spreadsheet

Grid setup in Google Sheets/Excel:

  • 10×10 grid (cells A1:J10)
  • Fill randomly with: “O”, “X”, or “” (empty)
  • About 40% O, 40% X, 20% empty

Calculate happiness (for one cell, e.g., C3):

Count neighbors (B2:D4, excluding C3 itself)
Count similar neighbors
% similar = similar / total neighbors
Happy if % similar ≥ 0.3

Manual move process:

  1. Find unhappy agent
  2. Find random empty cell
  3. Cut from old location, paste to new
  4. Recalculate happiness for old neighbors

Run 10 iterations. Watch segregation emerge!

Exercise 2: Simulate Rumor Spread with Agents

Simple ABM rules:

  • 100 agents on 20×20 grid
  • Each agent: knows rumor? (True/False)
  • Each time step:
  • If agent knows rumor AND random<0.3, tell one random neighbor
  • If told rumor AND doesn’t know it, learns it with probability = trust level

Add twist: Agents have trust level (0-1):

  • If trust > 0.8, always believe
  • If trust < 0.2, never believe
  • Else, probability = trust

Observe:

  • How many time steps to reach everyone?
  • Do “skeptics” (low trust) slow spread?
  • What if some agents are “super-spreaders” (tell 5 neighbors)?

Exercise 3: The “Tragedy of the Commons” ABM

Setup:

  • 10×10 pasture with grass that regrows slowly
  • 20 shepherd agents
  • Each shepherd: has sheep (1-10), needs grass
  • Rules:
  • Sheep eat grass in current cell
  • Grass regrows 1 unit/tick if not overgrazed
  • Shepherd moves to cell with most grass
  • If grass = 0 in cell, sheep start dying
  • If sheep > 0 and grass > threshold, reproduce

Run simulation. What happens?

  1. Short term: All shepherds prosper
  2. Medium term: Pasture degrades (overgrazing)
  3. Long term: Collapse! Most sheep die

Solution attempts:

  • Add private property (assign cells)
  • Add social norms (don’t overgraze)
  • Add punishment for overgrazers

Which works? Test in simulation!


PART 6: CMH APPLICATIONS — FROM REVOLUTIONS TO MARKET CRASHES

Application 1: Revolution Threshold Models

Granovetter’s Threshold Model (1978):

  • Each person has protest threshold (0-100%)
  • Person protests if % already protesting ≥ their threshold
  • Distribution of thresholds in population determines outcome

Example thresholds:

  • Radicals: threshold = 0% (protest alone!)
  • Early joiners: 10%
  • Followers: 30%
  • Late majority: 60%
  • Never: 100%

Simulation results:

  • Small initial protest (0.1%) → usually fizzles
  • Medium initial (1%) → sometimes cascades, sometimes not
  • Large initial (5%) → usually cascades to revolution

Critical insight: Tipping points exist! Small changes near threshold create huge differences.

Application 2: Financial Market ABMs

The “El Farol” Bar Problem (Brian Arthur):

  • 100 people decide weekly: go to bar or stay home
  • Bar enjoyable if ≤60 people go
  • Everyone uses different prediction strategies
  • No equilibrium emerges — perpetual adaptation

Emergent phenomena:

  • Herding: People follow popular strategies
  • Bubbles & crashes: Self-reinforcing trends then sudden reversals
  • Fat tails: Extreme events more common than normal distribution predicts

CMH insight: Market psychology emerges from interacting agents, not rational individuals!

Application 3: Epidemic ABMs

Beyond simple SIR models:

  • Agents have: location, daily routine, social network
  • Disease spreads through: proximity, touch, air
  • Interventions: quarantine, masks, vaccines

COVID-19 insights from ABMs:

  • Super-spreader events: A few agents infect many
  • Network structure matters: Dense clusters → rapid spread
  • Lockdown timing critical: Early short lockdowns better than late long ones

PART 7: COMBINING ABMS WITH OTHER CMH TOOLS

The Integrated CMH Pipeline

Step 1: ABM for micro-mechanisms

  • Individual decision rules
  • Local interactions
  • Emergent patterns

Step 2: Network analysis of ABM results

  • Who interacts with whom?
  • Information flow paths
  • Community structure

Step 3: Time series of macro-variables

  • Population-level trends
  • Cycles and fluctuations
  • Regime shifts

Step 4: Statistical validation

  • Compare to real data
  • Calibrate parameters
  • Test predictions

Example: Simulating Protest Movements

Micro (ABM):      Individuals decide to protest based on:
                  - Grievance level
                  - Perceived risk
                  - % friends protesting
                  - Police presence
↓
Meso (Network):   Protest clusters form
                  Leaders emerge naturally
                  Information spreads through weak ties
↓
Macro (Time Series): Protest size over time
                  Government response cycles
                  Media attention waves
↓
Validation:       Compare to real protest data
                  Adjust grievance/risk parameters

PART 8: YOUR ABM FIELD KIT

When to Use Agent-Based Modeling

Use ABM when:

  • Individual heterogeneity matters
  • Interactions are local/non-linear
  • Emergence is key (whole ≠ sum of parts)
  • History/path dependence matters
  • You want to explore “what if” scenarios

Don’t use ABM when:

  • System is well-mixed (everyone interacts with everyone)
  • Linear aggregation works
  • Data is only at aggregate level
  • You need fast, analytical solutions

ABM Design Principles

KISS principle: Keep It Simple, Stupid!

  • Start with minimal model
  • Add complexity only when needed
  • Each parameter should have real-world meaning

Validation steps:

  1. Face validity: Does output look plausible?
  2. Sensitivity analysis: Which parameters matter most?
  3. Historical validation: Match known patterns
  4. Predictive validation: Predict unseen data

Communication challenges:

  • How explain complexity from simplicity?
  • How show emergence visually?
  • How present probabilistic results?

PART 9: ETHICAL CONSIDERATIONS — THE “SOCIETY SIMULATOR” DILEMMA

The God Complex

ABMs let us “play God” with simulated societies. Dangers include:

1. Uncritical acceptance:

  • “The computer says it will happen!”
  • Forgetting: Models are simplifications

2. Self-fulfilling prophecies:

  • Publish ABM showing revolution likely
  • People believe it → prepare for conflict → conflict happens

3. Manipulation potential:

  • Use ABM to find optimal repression strategies
  • Or optimal manipulation of public opinion

4. Reductionism:

  • Reducing human complexity to simple rules
  • “We’ve modeled love/fear/justice with 3 parameters!”

The “Veil of Ignorance” Test

Before using ABM results for policy:

  • Would you accept the policy if you didn’t know which agent you’d be?
  • Are some agents systematically disadvantaged?
  • Can agents in the model learn and adapt?

CMH Ethical Rule: ABMs should illuminate human complexity, not reduce human dignity.


PART 10: BUILDING YOUR FIRST CMH ABM

A Simple “Society Simulator”

Let’s build a minimal CMH model combining:

  1. Economy: Resources, production, trade
  2. Politics: Power, rebellion, governance
  3. Society: Culture, learning, norms

Agents have:

  • Wealth (0-100)
  • Power (0-10)
  • Happiness (0-10)
  • Memory of past interactions

Environment:

  • Grid world with resource patches
  • Central “government” agent

Rules (per time step):

1. Economic phase:
   - Harvest resources if on rich cell
   - Trade with neighbors if beneficial
   - Update wealth

2. Social phase:
   - Compare wealth to neighbors
   - If much poorer AND neighbor is richer → resentment++
   - If similar wealth → happiness++

3. Political phase:
   - If resentment > threshold AND local power > government power → rebel
   - If rebel, try to take neighbor's wealth
   - Government agents: suppress rebels, collect taxes

4. Learning phase:
   - Remember who helped/harmed you
   - Adjust future behavior

What emerges?

  • Boom/bust cycles
  • Revolutions when inequality high
  • Corruption if government unconstrained
  • Trade networks
  • Cultural regions (agents copy successful neighbors)

YOUR MATH HOMEWORK

Exercise 1: Extend Schelling’s Model

Add three new features to basic Schelling:

  1. Wealth: Agents have wealth (1-10). Rich agents can move farther.
  2. Multiple groups: Add third group (△) with different preferences.
  3. External shock: At time=20, change preferences (now want 50% similar).

Observe:

  • Does wealth inequality affect segregation patterns?
  • Do three groups mix more or less than two?
  • How does system adapt to preference change?

Exercise 2: Simulate a Market Bubble

Create simple stock market ABM:

  • 100 investor agents
  • 1 stock with fundamental value = 100
  • Each agent: cash + stocks, trading strategy
  • Strategies:
  • Fundamentalists: Buy if price < 100, sell if > 100
  • Chartists: Buy if price rising, sell if falling
  • Noise traders: Random

Rules:

  • Each period: Some agents trade based on strategy
  • Price adjusts based on buy/sell imbalance
  • Agents can switch strategies if underperforming

Run simulation. Do you see:

  • Bubbles and crashes?
  • Herd behavior?
  • Periods of stability then volatility?

Exercise 3: Design a “Cultural Evolution” ABM

Agents have cultural traits (continuous 0-1):

  • Directness in communication
  • Individualism vs collectivism
  • Time orientation (present vs future)

Interaction rules:

  • Meet random neighbor
  • With probability = similarity, interact successfully
  • If successful, slightly adjust traits toward each other (learning)
  • If unsuccessful, adjust away from each other (reactance)

Add selection pressure:

  • Certain trait values more successful in environment
  • Successful agents have more “offspring” (new agents copy traits)

Observe:

  • Does culture converge or diversify?
  • Do subcultures form?
  • How does migration (new random agents) affect culture?

Exercise 4: The “Policy Test” Challenge

You’re advisor to a city with:

  • High unemployment in one neighborhood
  • Rising crime
  • Racial tension
  • Budget for one intervention

Policy options to test in ABM:
A. Job training program (increase employability)
B. Community policing (reduce crime fear)
C. Mixed-income housing (reduce segregation)
D. Youth centers (provide alternatives)

Build minimal ABM with:

  • Agents: employed/unemployed, different groups, criminal/non
  • Environment: neighborhoods with different resources
  • Rules: job finding, crime decisions, group interactions

Test each policy: Which reduces crime most? Which increases integration? Any unintended consequences?


KEY TAKEAWAYS:

  1. ABMs simulate individuals following simple rules
  2. Emergence: Complex patterns from simple interactions
  3. Schelling model: Mild preferences → extreme segregation
  4. SugarScape: Inequality emerges naturally
  5. Threshold models: Tipping points in social behavior
  6. Combination power: ABMs + networks + time series
  7. Validation crucial: Match real-world patterns
  8. Ethical care needed: Don’t reduce humanity to rules

The CMH Mantra:

“Statistical models ask: What patterns exist in the data?
ABMs ask: What rules would generate those patterns?
We move from observing the dance to understanding the dance steps.
From seeing segregation to understanding how a mild preference for similar neighbors creates it.
From measuring inequality to seeing how random advantages compound.
From predicting revolutions to simulating how individual decisions cascade.
ABMs don’t just describe society — they let us grow artificial societies in silicon,
to test which seeds of policy might grow into forests of consequence.”


NEXT LESSON PREVIEW:

Lesson 9: System Dynamics — The Stocks and Flows of History

Where we’ll learn:

  • How to model accumulations (population, wealth, knowledge)
  • Feedback loops (reinforcing and balancing)
  • Delays between cause and effect
  • The World3 model that predicted limits to growth
  • Why systems often behave counterintuitively

Thought to Ponder: ABMs give us bottom-up emergence. System dynamics gives us top-down structure. Together they form a complete picture: the micro-rules of individuals AND the macro-flows of populations, resources, and ideas. When a revolution happens, it’s both: individuals deciding to protest (ABM) AND the accumulating grievances, decaying legitimacy, and draining resources (system dynamics). The full CMH toolkit is becoming complete…


Remember: With ABMs, we hold a mirror to society — but it’s a funhouse mirror that simplifies and distorts. The art is in knowing which distortions are helpful (illuminating essential mechanisms) and which are harmful (erasing important complexities). A good ABM is like a good map: not the territory, but useful for navigation. And like a map, it can be used to find peaceful paths or plan invasions. The tool is neutral; the purpose is our choice.

Similar Posts