This is an introduction to Agent-Based Modeling (ABM). ABM is a type of computer programming with applications to physics, chemistry, biology, epidemiology, weather forecasting, forestry, sociology, economics, business, and even film making. But to understand what makes it different from other modeling, we need a little background.
The first successes of mathematical modeling of reality were in describing simple orders. A classic expression of a simple order is Newton's second law of motion, F = ma: it relates one quantity to only two others, in a very straightforward manner. Similar examples are models for springs, and pendulums, and heat diffusion. Models of simple orders usually take the form of differential equations. These types of models were developed extensively in the 18th and 19th centuries, and are still very important today.
The second class of phenomena to be successfully modeled were random systems:
"Whereas ordinary mechanics only considers the behaviour of a single state, statistical mechanics introduces the statistical ensemble, which is a large collection of virtual, independent copies of the system in various states. The statistical ensemble is a probability distribution over all possible states of the system." -- Wikipedia
The study of such systems was conducted by the use of statistical models. Examples of phenomena successfully modeled in this way includes thermodynamical systems, gas diffusion, Brownian motion, the evolution of a quantum wave function, height and weight distributions in a population, and games of chance.
In the mid-twentieth century, many scientists believed that these two types of models were all that were needed to capture all of reality: if some phenomenon could not be captured exactly by a simple model, then it must be random, and could be described by statistical analysis. But this view was soon to collapse, as, from multiple fields, researchers discovered...
The discovery of complex orders had been hinted at in work on the three-body problem: Newton had "solved" the problem of the planet's orbits by assuming that only the sun influenced their orbits, which is a good approximation. But once another planet was allowed to sneak into the system, the possible behavior became far more complex:
Well, at least for our solar system, these complexities could (mostly) be ignored. But for other systems this was not the case: as researchers looked into "far-from-equilibrium" systems like our weather, or chaotic fluid dynamics, or the behavior of asset markets, they found that these exhibited patterns that could not be captured by models of simple orders, nor models of pure randomness. They were discovering the existence of complex orders.
The behavior of these orders could not be captured by analysis of a differential equation, nor by statistical procedures. Instead, in general, one creates a model based on some (seemingly) simple rules, and then runs the model, and only by doing so does one discover what the system does.
A milestone along this path was the discovery, by the mathematician Benoit Mandelbrot, of the Mandelbrot set. Mandelbrot took the "simple" equation, f*c*(z) = z2 + c, where z and c are complex numbers, and iterated it (feeding the result of one iteration into the next), with z at the start equal to 0, for c near the origin, and found that this seemingly simple equation produced fantastically complex results. In a simple order, small differences in the initial value of c ought to produce small differences in the final outcome. But Mandelbrot discovered that extremely small differences in the initial value of c could produce wildly divergent outcomes: this is a characteristic of complex systems: small differences in initial values can produce very big differences in the development of the system. If we color each point c by how fast the above equation moves away from the origin, we get a result like:
In [5]:
from IPython.display import HTML
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/pCpLWbHVNhk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
Out[5]:
Similar phenomena were discovered in many fields... see the list of applications of ABMs above!... and a new field was opened to science: the study of complex orders. In general, we cannot either "solve" a problem in such an order by solving a differential equation, as we can for simple orders, or by purely statistical analysis, as we can for random phenomena. Instead, we must specify the rules the parts of the system must follow, and then we must run the system, most often on a computer, and see what emerges. (Another name for this field of study is emergent phenomena.)
One of the important tools in exploring this (relatively) new field of complex orders has been agent-based models. In such models, instead of trying to find a "top-down" equation that we can solve, and therefore say exactly what the model predicts at time t, we instead create a number of agents, which we program to follow some rules of behavior, and then set those agents "loose" in an "environment" (our model), and allow them to interact. Such models are also sometimes called cellular automata.
An early example of such a model was John Conway's game of life, where each "cell" on a grid evolved according to a simple rule, based on the state of its neighbors. Although the rules were simple, the "game" could produce very complex patterns:
The pattern produced is clearly not "random," but it also could not be predicted by any "top-down" equation attempting to model the system. The system needs to be run in order to see what patterns emerge.
An early area in which ABMs were successfully applied was that of flocking or schooling. Birds form "flocks," and fish "schools," and these groups exhibit behavior that clearly is not random, but also cannot be described by any simple equation. For instance, check out this school of fish:
In [3]:
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/15B8qN9dre4" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
Out[3]:
Note that there is no fish "choreographer": the school must emerge "bottom-up" from the behavior of inidividual fish.
Using ABMs, researchers discovered that they could create agents that followed simple rules, and yet produced this sort of complex phenomena, like "boids":
In [4]:
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/QbUPfMXXQIY" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
Out[4]:
ABM models have also been useful in many other fields, as noted above. Perhaps of particular interest is their application, over the past two decades, in film making. A common difficulty faced by film makers trying to shoot such scenes was whether to employ large numbers of real humans, all of whom would need to be directed, fed, and so on, or to try to animate these scenes with top-down control.
Massive realized that ABM could cut this Gordian knot: instead of trying to control all of the animation top down, film makers could instead create "agents" who would follow simple rules, and then instantiate a whole host of such agents, and create the movie episode by simple allowing all of those agents to follow their own rules.
This technique was so successful in the Lord of the Rings movies that since then most film makers desiring huge crowd scenes have used ABM.
In [6]:
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/EmTz7EAYLrs" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
Out[6]:
Let's look at a few agent based models we've made here at Tandon.
The first one is of the spread of a forestfire.
In [ ]:
%matplotlib inline
from models.forestfire import main as ffmain
ffmain()
Another model we've built is of bacteria avoiding toxins and moving towards nutrients:
In [ ]:
%matplotlib inline
from models.bacteria import main as bamain
bamain()
Finally, let's look at a model of trends in fashion.
In this model, there are trendsetters and followers. The trendsetters want to wear something that only other trendsetters wear. Meanwhile, the followers want to be just like the trendsetters.
This leads to waves of fashion.
In [ ]:
%matplotlib inline
from models.fashion import main as famain
famain()
In [ ]:
0