In this demo, we simulate a diffusion process where agents can represent the spread of an innovation, virus infection, or social news. Initially, a set of agents are marked as infected while others are non-infected. Each time step:
By changing initial values (grid size, number of infected, infection rate), we can investigate how diffusion dynamics unfold.
Figure: Visualization of the diffusion model in action. The simulation begins with 10 infected and 302 non-infected agents on a 50Ă—50 grid. After approximately 35 steps, infected agents start to outnumber the non-infected, and by around 110 steps, nearly all agents become infected. Red represents infected agents, and green represents non-infected agents. The infection spreads progressively through local interactions among neighboring agents.
This model was built with Mesa, a Python framework for Agent-Based Modeling. Mesa provides tools to build, visualize, and analyze ABMs directly in Python and runs in the browser for easy demonstration.
The version used here is Mesa 2.4, which retains the classic
CanvasGrid and ChartModule visualization components
(later replaced in Mesa 3.x).
The full source code of this demo is available on GitHub: 📥 Download / View Source
One of the earliest and most influential works on agent-based modeling of diffusion is:
Thomas C. Schelling (1971).
“Dynamic Models of Segregation.”
Journal of Mathematical Sociology, 1(2):143–186.
DOI link
Another foundational reference is:
Joshua M. Epstein & Robert Axtell (1996).
Growing Artificial Societies: Social Science from the Bottom Up.
Brookings Institution Press / MIT Press.