Think Complexity
by Allen B. Downey
Copyright 2018 Allen B. Downey. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com/safari). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisitions Editor: Rachel Roumeliotis
- Developmental Editor: Michele Cronin
- Production Editor: Kristen Brown
- Copyeditor: Charles Roumeliotis
- Proofreader: Kim Cofer
- Indexer: Allen B. Downey
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- March 2012: First Edition
- August 2018: Second Edition
Revision History for the Second Edition
- 2018-07-11: First release
See http://oreilly.com/catalog/errata.csp?isbn=9781492040200 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Think Complexity, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
Think Complexity is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. The author maintains an online version at http://greenteapress.com/wp/think-complexity-2e/.
978-1-492-04020-0
[LSI]
Preface
Complexity science is an interdisciplinary fieldat the intersection of mathematics, computer science and natural sciencethat focuses on complex systems, which are systems with many interacting components.
One of the core tools of complexity science is discrete models, including networks and graphs, cellular automatons, and agent-based simulations. These tools are useful in the natural and social sciences, and sometimes in arts and humanities.
For an overview of complexity science, see https://thinkcomplex.com/complex.
Why should you learn about complexity science? Here are a few reasons:
Complexity science is useful, especially for explaining why natural and social systems behave the way they do. Since Newton, math-based physics has focused on systems with small numbers of components and simple interactions. These models are effective for some applications, like celestial mechanics, and less useful for others, like economics. Complexity science provides a diverse and adaptable modeling toolkit.
Many of the central results of complexity science are surprising; a recurring theme of this book is that simple models can produce complicated behavior, with the corollary that we can sometimes explain complicated behavior in the real world using simple models.
As I explain in , complexity science is at the center of a slow shift in the practice of science and a change in what we consider science to be.
Studying complexity science provides an opportunity to learn about diverse physical and social systems, to develop and apply programming skills, and to think about fundamental questions in the philosophy of science.
By reading this book and working on the exercises you will have a chance to explore topics and ideas you might not encounter otherwise, practice programming in Python, and learn more about data structures and algorithms.
Features of this book include:
Technical details
Most books about complexity science are written for a popular audience. They leave out technical details, which is frustrating for people who can handle them. This book presents the code, the math, and the explanations you need to understand how the models work.
Further reading
Throughout the book, I include pointers to further reading, including original papers (most of which are available electronically) and related articles from Wikipedia and other sources.
Jupyter notebooks
For each chapter I provide a Jupyter notebook that includes the code from the chapter, additional examples, and animations that let you see the models in action.
Exercises and solutions
At the end of each chapter I suggest exercises you might want to work on, with solutions.
For most of the links in this book I use URL redirection. This mechanism has the drawback of hiding the link destination, but it makes the URLs shorter and less obtrusive. Also, and more importantly, it allows me to update the links without updating the book. If you find a broken link, please let me know and I will change the redirection.
Who Is This Book For?
The examples and supporting code for this book are in Python. You should know core Python and be familiar with its object-oriented features, specifically using and defining classes.
If you are not already familiar with Python, you might want to start with Think Python, which is appropriate for people who have never programmed before. If you have programming experience in another language, there are many good Python books to choose from, as well as online resources.
I use NumPy, SciPy, and NetworkX throughout the book. If you are familiar with these libraries already, thats great, but I will also explain them when they appear.
I assume that the reader knows some mathematics: I use logarithms in several places, and vectors in one example. But thats about it.
Changes from the First Edition
For the second edition, I added two chapters, one on evolution, the other on the evolution of cooperation.
In the first edition, each chapter presented background on a topic and suggested experiments the reader could run. For the second edition, I have done those experiments. Each chapter presents the implementation and results as a worked example, then suggests additional experiments for the reader.
For the second edition, I replaced some of my own code with standard libraries like NumPy and NetworkX. The result is more concise and more efficient, and it gives readers a chance to learn these libraries.
Also, the Jupyter notebooks are new. For every chapter there are two notebooks: one contains the code from the chapter, explanatory text, and exercises; the other contains solutions to the exercises.
Finally, all supporting software has been updated to Python 3 (but most of it runs unmodified in Python 2).
Using the Code
All code used in this book is available from a Git repository on GitHub: https://thinkcomplex.com/repo. If you are not familiar with Git, it is a version control system that allows you to keep track of the files that make up a project. A collection of files under Gits control is called a repository. GitHub is a hosting service that provides storage for Git repositories and a convenient web interface.
The GitHub home page for my repository provides several ways to work with the code:
You can create a copy of my repository by pressing the Fork button in the upper right. If you dont already have a GitHub account, youll need to create one. After forking, youll have your own repository on GitHub that you can use to keep track of code you write while working on this book. Then you can clone the repo, which means that you copy the files to your computer.