Fun with agent-based modeling


I was recently asked to give a presentation on agent-based models (ABMs, also known as individual-based models or IBMs) for students in Mary Power’s lab at UC Berkeley. Now, let me be clear: I’m not an expert by any stretch of the term. My experience with agent-based modeling has solely been through my work with Steve Railsback on an early iteration of ternCOLONY, an ABM funded by the American Bird Conservancy. Thankfully, the Power lab was just looking for introductory material, so I didn’t feel like a hack when giving the presentation.

Just to warn you, this is a pretty long post; it’s basically the text form of my presentation, minus the examples and case study stuff. I drafted the post as a way to organize my thoughts and get an idea of what I wanted to cover in the presentation. I suggest reading the first section and then jumping straight to the NetLogo examples (also linked at the bottom of post). In particular, I think the wolf-sheep predation and flocking examples do a good job illustrating the ecological applications of agent-based models. Then, if you’re still interested, go ahead and read the remaining sections.

I should start by mentioning the literature that my presentation was based on. Steve Railsback (Humboldt State University, California) and Volker Grimm (University of Potsdam, Germany) literally wrote the book (actually, two books) on individual-based modeling and ecology. Steve was also kind enough to share one of his earlier presentations on the subject with me, which heavily inspired the content of my own presentation. I also stole some of his jokes.

Why use agent-based models?

Let’s start with the basics. Broadly speaking, models are tools we use to explore systems of interest. A model is always a simplification of the system being investigated, and is usually designed with a specific question in mind. A clearly defined purpose for a model helps us differentiate between which details are important, and which ones can be ignored when investigating the question at hand. Agent-based models are a special class of model that we use to investigate patterns arising from interactions between individuals. Although ABMs are often considered an alternative to classical equation-based models, the two approaches are complementary. Classical models are predicated on equations expressing relationships between observable components of a system, and the model is typically used to predict the state of these observables over time and/or space. Agent-based models, in contrast, start with a set of behaviors that define how individuals interact, and system-level patterns emerge from these interactions. When people speak about ABMs, they often use terms like “pattern oriented” and “behavior oriented”, as well as referring to them as “simulation” models. Another thing to bear in mind when considering ABMs is that they are typically very programming-intensive and require significant computational resources. They also often require theoretical development to model interactions, which we’ll talk more about in a bit.

Agent-based models are applicable to problems where individuals, and individual variation, is important. For instance, if we are interested in the adaptations that influence the fitness of a population, we should consider how these population-level properties emerge from the adaptations of individuals to maximize their own fitness, as individuals do not adapt their behavior to directly optimize the fitness of the population as a whole. Emergent properties of populations arise from interactions of adaptive individuals with other individuals and their environment. Since these adaptive individuals make up part of the biotic environment of other individuals, a kind of circular causality is created through which system-level properties emerge. Agent-based models are also useful when competition between individuals matters, and when we are trying to determine how individual behavior regulate population dynamics as whole. In simpler terms, agent-based models are useful when we are forced to recognize that a system is more than the sum of its parts, and responds in complex ways to change.

Agent-based models also help us avoid the ‘complexity-uncertainty’ trap that can plague classical models. In hydrology, we refer to this as equifinality–the idea that multiple models may provide equally-feasible descriptions of reality. Given some dataset for calibration, multiple modeling approaches may provide equally-accurate (or inaccurate) predictions, and increasing model complexity may only exacerbate the issue. While ABMs can be big and complicated in their own way, they are still, at heart, based on relatively simple models of individuals. Since each individual is represented explicitly, we can log choices and characteristics of the local environment for each individual, giving us a plethora of data to work with when calibrating and validating the model. Furthermore, simple models of adaptive interaction between individuals can give rise to highly-complex systems, meaning that we don’t have to ‘hard code’ such complexity into our model (which again, simplifies the calibration and validation process).

I’ve been throwing the terms “agent” and “individual” around, but haven’t given a proper definition yet. The term “individual” in an IBM is a bit more abstract than colloquial definitions, as it doesn’t always mean a specific organism, e.g. a particular tree or fish. An “individual” is simply a distinct character of a system that interacts with other elements of the model based on defined behaviors. So yes, an “agent” could certainly be a particular tree or fish, but it could also be a family of beavers, a flock of birds or even an entire species. Collectives are often modeled explicitly in ABMs, as a kind of intermediate between individuals and populations. The reasoning for this is that the properties and behaviors of a collective, and therefore their influence on the environment and other individuals and collectives, can differ dramatically from those of a single member of said collective.

What makes an ecological model an “agent-based” model?

A more formal definition of an ABM is helpful when trying to differentiate agent-based models from other model classes. Note that the following definitions were designed specifically with respect to ecological models, so this probably won’t translate well if you are are working in another field that employs ABMs. An ecological model can be considered “individual-based” or “agent-based” if it conforms to four requirements: first, an ABM must explicitly represent the life history of individuals to some degree of complexity. As an individual grows it typically requires more, and sometimes different, resources. Additionally, an individual may interact with different components of their environment depending on their life stage. An obvious example of this is anadromous fish, whose diet, habitat choices and predation risks differ significantly based on their size and whether they are residing in freshwater or ocean habitats. Furthermore, since individuals may adapt their life history characteristics based on competition and resource availability, ABMs must consider growth and development in some way lest they neglect essential aspects of the “ecology of individuals”.

Second, an ABM must explicitly represent the dynamics of resource use by individuals. This goes back to adaptive behavior, and how adaptive individuals make up part of the biota of other adaptive individuals. Classical population models often utilize concepts such as the carrying-capacity of an environment, which is then related to the density of a population. However, this concept doesn’t have any meaning at the individual level, as agents are affected by their local environment and do not possess information on the overall state of the population.

Third, populations must be represented as discrete values. This seems like a no-brainer, but it’s very significant! Many classical models express populations using growth rates, which are typically real-valued. This provides the modeller with some leeway to fine-tune the dynamics of population growth. Modelling populations from the individual perspective, however, doesn’t provide any fine-tuning capabilities; you can’t have half an individual grow or die, and an agent-based framework for population modelling must rely on the mathematics of discrete events. You can’t say your model is “individual-based” just because you round populations to whole numbers!

Fourth, an ABM must consider variation among individuals within the same class. Again, this goes back to the concept of adaptive behavior; since individuals will respond in different ways depending on the state of their environment and the individuals they share it with, and since they can adapt life history characteristics in response to their environment, individuals of the same age may still exhibit significant differences. In fact, variation among individuals within a class can be comparable with the variation among class averages. We can look at fish as a simple example of this: since size is directly related to food availability, two fish of the same age but experiencing different levels of food competition may be drastically different sizes, and therefore experience different predation risks.

If a model does not meet all four criteria, it is not “agent-based”. Models that incorporate some of these criteria are referred to as “agent-oriented” and still hold scientific value, as they can inform how classical, aggregated models could be improved by incorporating elements of the discreteness and localized interactions of individuals. However, they are not sufficiently different from classical models if you are trying to investigate whether IBMs can lead to a fundamentally new view of ecological systems and processes. Only a true ABM will let you fully trace system-level properties back to individual behavior.

How do we build an agent-based model?

There are a few factors that make agent-based modelling difficult. The first issue is that ABMs lack a unified conceptual framework. While classical models are firmly rooted in the mathematics of ordinary and partial differential equations, we have no such language for communicating the essential characteristics of ABMs. This means that modellers often have no choice but to make ad-hoc assumptions during development, making it difficult to compare ABMs to each other or to classical models. Furthermore, ABMs are often too large to be completely described in scientific publications, which limits their accessibility to the scientific community and therefore threatens their credibility.

Another potential difficulty is that finding the right level of complexity for an IBM is not trivial. Designing the model structure and resolution requires more time and effort than classical models, and we have to think across scales when identifying which behaviors and factors should be included in the model, and which ones shouldn’t. ABMs also typically require the development of new theory, and while this is the fun and exciting part, it takes a lot of work! We have to think about how individuals make decisions and which individual traits affect the system, and then formulate and test models of individual interaction. Finally, coding an ABM requires a lot of effort compared to most classical models. We often need to optimize our code (since ABMs can get big fast), and the stochastic nature of most ABMs (and the huge amount of data that can be generated from a single model run) means that we need to be clever about how we test and validate our models.

ABMs can blow up fast, and there is a dichotomous nature to the scale of ABMs. Individual-based models tend to be either “simple” or “big”; simple ABMs are closer in nature to “general” ecological models, in that they are typically used to explore a simple idea and are not necessarily tied to reality. Simple ABMs are appropriate for graduate-level work, and the development and analysis of an ABM is an appropriate target for, say, a Master’s thesis. The big ABMs, in contrast, typically require an interdisciplinary team of specialists to develop over the course of a few years, but such a model can be used for a long time once it is completed.

So now that I’ve sufficiently scared you away from working with ABMs, how do we go about building these things? Steve suggests following seven steps, which we’ll go through in order.

  1. Formulate the model. Steve suggests that you “be general by being specific”. ABMs should be designed to investigate a particular problem, and preferably a real-world one. Since ABMs are so complex and the theory behind them is still developing, tackling a real-world problem helps constrain the models. Furthermore, by investigating several real-world problems we can better understand what kinds of agent-based frameworks work for what sorts of scenarios, and develop theory and techniques that work in at least some real situations.

  2. Identify characteristic patterns. An agent-based model should be designed around the patterns it is expected to reproduce. The model should be driven by, and operate at the same spatial and temporal resolutions as, the processes that drive the patterns observed in the system of interest. Make sure the model captures the essence of the system and includes the structures and variables that are essential to the patterns, and toss the rest out!

  3. Design a draft model. Now that you know the basic constraints of the model, it’s time to start thinking about how you want to model individuals. This is the part where you decide things like what sorts of agents are represented in your model, how you want to model collectives, and what kinds of interactions can occur. This is an area where we start feeling the lack of an established conceptual framework, as we have to make some judgment calls. A good place to start is by thinking about how things like emergence, adaptation, and individual objectives and sensing abilities should be represented. For instance, we will need to decide what kinds of decisions individuals can make, and what sorts of environmental and internal factors contribute to choices. We also need to consider whether individuals seek direct objectives (and decisions are therefore made to maximize an explicit estimate of the agent’s future objectives) or indirect objectives (individuals follow a set of rules that mimic observed behavior, which we assume contribute in some way to an individual’s objectives). We will also make decisions about how individuals interact, such as whether competition occurs through events (explicit predation events or dominance contests) or happens indirectly through competition for resources. Finally, we need to establish some rules regarding how individuals obtain information about themselves and their environment, and the range and accuracy of this information.

  4. Develop theory for individual traits. This step often has an iterative component, as we need to formulate and test models of individual behavior that will reproduce the characteristic patterns identified in step 2. As in step 3, we suffer from a lack of an established conceptual framework, but there is some hope; State- and Prediction-based Theory (STP) holds some promise as a mathematical framework for individual decision-making. STP is similar to dynamic state variable modeling, in that we can model individual decisions as maximizing a direct estimate of future fitness over some time horizon (such maximizing the probability of survival over the next 10 days). These decisions are state-dependent, meaning that an agent that is e.g. well-fed will make different decisions from one that is starving. However, whereas dynamic state variable modeling requires fixed boundary conditions and ignores the impacts of decisions over the time horizon, STP allows individuals to repeat the objective estimate many times over the full time horizon, meaning that we can incorporate feedbacks between individuals into the decision-making process.

  5. Calibrate and validate the model. This step really isn’t too different from calibrating and validating classical models, so I won’t dwell on this subject. It is important to note, however, that the complexity of ABMs can make it difficult to adequately test them, and they often produce a much higher volume of data compared to a classical model of the same system. Additionally, since ABMs often have stochastic elements, we often need to aggregate multiple replicates of a given run in order to ensure that our stochastic components are behaving the way they are supposed to. However, since individuals are explicitly represented, we can also leverage some of the statistical tools we use when observing real populations.

  6. Analyze the model. Finally, the fun part! This is where we can finally start using the model to investigate the question you asked in step 1. ABMs are usually designed as simulation models, which means we can use them as a “virtual laboratory” to test management decisions or the impacts of changes to the environment. We can formulate and test hypotheses as we would when observing a real population, but with an added twist: we can play God if we want to, forcing completely unrealistic scenarios and tossing our agency’s animal care and use policy in the trash. Running ridiculous scenarios is a great idea though–it’s always important to push the limits of your model, and sometimes we learn something that surprises us. Now that’s science!

  7. Communicate the model. Again, this is similar to working with classical models, except that the size and complexity of an ABM may make it difficult to fully describe in a single publication. Furthermore, reviewers are less familiar with agent-based frameworks, and some of the assumptions you make when designing your model may prove more contentious than expected. You may want to take a look at Steve and Volker’s (and 26 others) protocol for describing ABMs for guidance on how to communicate the model. Basically, the protocol suggests dividing a publication into three parts: An “overview” section, where you describe the purpose of the model, what entities, state variables and scales are modeled, and how processes and scheduling are handled; a “design concepts” section, where you detail how you handled steps 3 and 4 and the choices you made regarding emergence, adaptation, objective seeking, etc.; and finally, a “details” section, where you describe how the model is initialized, how input data is passed to the model, and how the different components of the model are structured.

Whew! Did you get all that? If you want to learn more about agent-based modeling, I suggest you check out the links below:

And some example models to play with:


Comments