This repository contains agent-based model (ABM) demos used in a talk on explainability and emergence in ABMs. These examples illustrate how local interaction rules among agents can lead to complex global behavior — in physics, social systems, and macroeconomics.
Dependencies are listed in requirements.txt. To install:
pip install -r requirements.txtMain packages used include:
matplotlibfor animationnumpy,scipyfor numerical routinestqdmfor optional progress indicators
This repo contains standalone, runnable demos for:
A classical model from statistical physics where each site (agent) has a spin (+1 or -1) and interacts with its neighbors. The model exhibits a phase transition: above a critical interaction strength, long-range order emerges spontaneously.
Includes:
- A simulation using the Metropolis algorithm
A simple model of residential dynamics where agents prefer to be surrounded by similar neighbors. Even with mild preferences, large-scale segregation patterns emerge. Demonstrates how individual tolerance does not prevent global clustering.
Implemented with a grid of red, blue, and empty cells. Agents relocate when their neighborhood doesn't match their preference.
Inspired by starlings and fish schools. Each agent aligns its movement with nearby agents, resulting in collective motion. We implement both:
- Topological interaction (fixed number of neighbors)
- Metric interaction (within a distance) We also include a wandering predator that perturbs the flock and reveals the system’s robustness.
Many parts of this codebase (logic, structure, visualization choices, and documentation) were developed in collaboration with large language models (LLMs), including OpenAI’s GPT-4. All code was reviewed, tested, and curated manually.
This project is licensed under the MIT License.