Complexity Science

Allen Downey
This is self-study material: the workshop is not offered live now, but the notebooks are maintained and run on Colab.
This tutorial is a hands-on introduction to complexity science, using Python to build and explore simple models that produce surprisingly complex behavior. We start with agent-based models: Schelling’s model of segregation, and a variation based on Bill Bishop’s The Big Sort. Then we explore cellular automata with Conway’s Game of Life, including still lifes, oscillators, spaceships, Methuselahs, and the glider gun, and see how to implement it efficiently with NumPy and SciPy. Finally, we use NetworkX to analyze the degree distribution of a Facebook social network, look at power laws and the friendship paradox, and compare the data with the Barabási–Albert model. For each part, there is a Jupyter notebook where you can run the code and work on exercises.
The examples in this tutorial are from my book, Think Complexity, 2nd edition, and a class I taught at Olin College.
This is one of my workshops and tutorials.
Level: introductory. You should be familiar with basic Python and Jupyter notebooks; some experience with NumPy helps. You don’t need to know anything about complexity science.
Length: about 3 hours.
Outline
- Agent-based models of segregation: Schelling’s model, implemented with NumPy arrays and 2-D correlation; then the Big Sort, where agents choose neighborhoods with people like themselves.
- Game of Life: still lifes, oscillators, and spaceships; Methuselahs; Conway’s conjecture, the glider gun, and the puffer train; an efficient implementation with correlation and a lookup table; and Highlife, a variation with one more rule.
- Scale-free networks: graphs with NetworkX; the degree distribution of a Facebook network; the friendship paradox; power law distributions; and the Barabási–Albert model.
Each notebook comes in two versions: one with blanks for the exercises, and one with solutions.
Slides for this tutorial are here.
Recordings
I presented this tutorial at PyCon US 2017 (with Jason Woodard), PyCon US 2018, and SciPy 2019. The code in the videos is not the current version; the tag after the SciPy link is the version of the code that goes with it. The PyCon tutorials predate this repository.
Running the notebooks
The easiest way to run the notebooks is on Colab: click one of the links above. You need a Google account, but you don’t have to install anything.
To run them on your own computer, you need Python 3 with Jupyter, NumPy, SciPy, Matplotlib, Seaborn, NetworkX, and empiricaldist. You can download the code in this zip file, or clone the repository:
git clone https://github.com/AllenDowney/ComplexityScience
cd ComplexityScience
Then install the packages with pip:
pip install -r requirements.txt
Or, if you use conda or mamba, create an environment:
mamba env create -f environment.yml
mamba activate ComplexityScience
Then run jupyter lab and open 01_workshop.ipynb.
The Game of Life notebook also mentions two scripts, LifeRabbits.py and LifePuffer.py, that run longer animations in a window; they need a local installation.
Next steps
To go further, read Think Complexity, 2nd edition, which is free online, or see my other workshops.
License
The code is available under the MIT License. The text is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
评论