Preface

This course provides an introduction to agent-based modeling and simulation. A core goal is to allow the reader to quickly get up and running: experimenting with, modifying, and creating simulation models. The models in this course have a social-scientific emphasis, but the tools are generalizable to many other fields.

Manipulation and and modification of existing models is the best way to become famililar with the current scope of agent-based social science. This requires a few basic programming skills, which this course introduces gently and systematically. No prior programming experience is needed.

Agent-based research requires careful analysis of simulation results, This course focuses on illustrative analyses of simple pedagogical models. Investigation of these models draws on a small number of data-science concepts and tools. No prior statistics background is assumed; some basic statistical tools are introduced as needed. This provides readers with the background needed to create and analyze new simulations in support of original research.

  • get the reader “up and running”

  • provide illustrative applications that demonstrate the scope of social science simulation

  • introduce tools to support social science computing

  • provide adequate programming background to allow original research

  • introduce the analysis of simulation results

  • explore the real-world relevance of simulation results

Overview

Approach

The approach of this course is impatient, incomplete, incremental, and pragmatic. The structure assumes the reader is eager to explore social-science simulations, and it introduces useful and illustrative programming projects as soon as possible. A quickstart approach requires a simple and approachable programming language. Code examples in this course therefore use the NetLogo programming language, which prides itself on being easy-to-learn. Additionally, NetLogo is powerful and flexible, with many academic and business applications.

While this course introduces many core features of NetLogo, the treatment of NetLogo intentionally remains incomplete. We do not attempt to document the NetLogo programming language. Excellent documentation exists online, and this course freely references this documentation. There are also many excellent books that focus on advanced details of the NetLogo language. ([Railsback.Grimm-2019-PrincetonUP] is an excellent example.) This course is intentionally incomplete in another way as well. The scope of agent-based modeling is enormous, including physical sciences, biological sciences, operations research, and computer science. This course emphasizes topics that are likely to be useful to social-science projects.

Model development in this course is incremental. Early chapters introduce concepts without treating them in exhaustive detail, and later chapters return to concepts and develop them more fully. Each lecture introduces details and advanced features on an as needed basis. This is core to a pragmatic and project-oriented approach to simulation modeling. Most discussions of computer-science niceties remain in appendices or refer to external resources.

Target Audience

This impatient, incomplete, incremental, and pragmatic approach reflects this course’s target audience: students, teachers, and researchers in the social sciences who seek an introduction to agent-based modeling and simulation (ABMS). This course largely ignores the multi-agent modeling in other domains—including the physical sciences, biological sciences, medicine, and business. There is a strong social-science emphasis, with particular weight on economics and sociology.

This course is suitable for use as a primary textbook in undergraduate courses or as a supplementary textbook in graduate courses. It intentionally limits the prerequisite knowledge, so motivated individuals will find the course useful even without a supporting course. The only mathematics needed is basic algebra. Some lectures make limited use of basic statistics, but the relevant statistical concepts will be introduced as needed. More advanced material appears on occasion, but it is always isolated from the core topic developments.

This course loosely considers a model to be “agent-based” to the extent that it explicitly characterizes the attributes and behavior of individual actors (the agents). (A refined defintion is developed within.) Agent-based modeling thereby contrasts with aggregative models, which characterize only the average behavior of large groups of individuals. Modern agent-based modeling requires the use of computers, since keeping track of many individuals by hand quickly becomes tiresome and error prone. Correspondingly, some programming is required.

However, this course assumes no prior knowledge of programming. Of course, reading this course will require reading computer code, and project completion requires the reader to write some code as well. An unprepared reader who peers ahead at the later chapters may find that they appear somewhat intimidating. However, early chapters teach the requisite programming skills. The material in this course has been used successfully in the classroom with students who have had no prior programming experience.

Discrete-Time Models

This course emphasizes discrete-time dynamical systems. Time progresses in discrete increments, called the timestep, period, or tick. By using a small time step, we can make time as close to continuous as needed. In computational social science, and especially in agent-based models, it is unusual to use a time-step of less than a day. The discussion of securities trading in the lecture on zero-intelligence traders is an exception to this rule.

The simplest models in computational social science, including many of the models in this course, often leave the time scale rather vaguely defined. However, time still evolves in discrete steps. This course does not cover continuous time modeling, nor does it pay more than cursory attention to discrete-event simulation.

Programming Language

There is no simple rule when choosing a programming language for agent-based simulation. Practitioners take many different approaches. Some rely on general purpose programming languages, such as Python or Java. Others rely on languages specially designed to facilitate agent-based simulation, known as domain-specific languages. Domain-specific languages for ABMS address many of the common needs of agent-based simulation. This class of languages includes NetLogo. In contrast with most treatments of agent-based modeling, this course strives to provide language-agnostic descriptions of agent-based models. However, illustrative code is always provided in NetLogo.

Among the domain specific languages, NetLogo offers a unique combination of popularity, ease of use, and power. Ease of use is particularly important for new modelers, and reflects NetLogo’s long history as a teaching language. In particular, the NetLogo language emphasizes readability and intuitive syntax. ([Wilensky.Rand-2015-MIT] suggest that NetLogo is as readable as psuedocode.) For more background, see the Introduction to NetLogo supplement.

Power becomes more important as a modeler advances and places new demands on the language. Despite its ease of use, NetLogo powerful enough to support serious research projects. (And should its limits ever become important in a particular project, NetLogo is also readily extensible.)

NetLogo's popularity derives in large part from its combination of ease of use and power. But the popularity of the language adds other advantages: there many existing models, and there is an active and responsive community of NetLogo modelers. (For a sense of this, visit http://stackoverflow.com/questions/tagged/netlogo.) The latter advantage serves as an example of a network effect, which is a key social-science concept. The existing NetLogo community increases the value of NetLogo for community members and for new users.

Among the domain-specific languages for multi-agent simulation, NetLogo yet another advantage. The NetLogo tookit ships with curated code examples and pedagogical models. The NetLogo Models Library is an enormously important feature for the use of NetLogo in the classroom. Some of the models simply illustrate NetLogo coding strategies. Many offer simple examples of models with real-word importance, including applications in mathematics, the physical sciences, and the social sciences. This course will draw on the social-sciences models in the NetLogo Models Library, sometimes directly and often in exercises. The value of these resources for students cannot be overstated.

Features

This course is designed for “hands on” learning. It is best read near a computer, where one can try the code examples and explore the models.

Our primary model selection criteria were simplicity and their pedagogical utility. Some models primarily illustrate computational tools useful for social-science. Other models introduce no new tools but foster useful insight into the nature of agent-based social-science.

All models include code examples in the NetLogo programming language. Additionally, the code for the models presented in this course is available online, at the associated website. Nevertheless, a key feature of the course is a reliance on relatively language-agnositc model descriptions. This means that the course is also useful for readers who wish to use a different language for the exercises.

In support of these language-agnositc descriptions, variable names follow somewhat different conventions than is typical in NetLogo models. For example, although NetLogo is case insensitive, we use capitalization to enhance readability. We also avoid punctuation in variable names. It most languages, in contrast to NetLogo, question marks and hyphens are not valid characters in variable identifiers. Where a NetLogo programmer might use names like n-fish and n-casts, we instead use nFish and nCasts. Similary, we do not include a question mark when naming a boolean attribute. NetLogo programmers are more likely to name a variable hungry? than isHungry, but we choose the latter convention. We adopt these conventions so that our variable names can be reused in many other languages.

From the perspective of the course, the use of NetLogo carries with in one primary disadvantage. NetLogo encourages a conflation between model-focused considerations and graphical user interface (GUI) considerations. The NetLogo designers, and many users, consider this an intentional design feature. In fact, many of the models in the NetLogo Models Library deliberately use (even at the level of code) colors to represent important agent attributes in the conceptual model. This course shies away from that practice. In contrast to many NetLogo-focused discussion of agent-based modeling, this course attempts to keep model-based considerations distinct from GUI considerations. This distinction is not forced in the very small number of places where NetLogo renders it a bit awkward.

Who Uses Agent-based Modeling?

ABMS has found wide application in natural science, social science, public policy, and education.

  • Natural systems (science, engineering etc.)

    • Many existing simulation techniques, question is purpose, strengths, weaknesses

  • Social systems (humanities, social science, business/marketing etc.)

    • Often the best or only laboratory available

  • Applications

    • Real-world simulation, optimization

    • Research

    • Classroom

Agent-Based Modeling and Simulation (ABMS)

In Economics, ABMS is sometimes known as agent-based computational economics (ACE).

Autonomous agents represent economic actors who make their own decisions (perhaps constrained).

ABMS is suitable for interactions which are bottom- up, not top-down. Interactions are decentralised.

E.g., social and market interactions, rather than engineering or internal organizational interactions.

Choice of Modeling Language

Substantial research in agent-based modeling and simulation (ABMS) has been conducted in a variety of general purpose programming languages, including procedural languages such as Fortran, C, or Pascal; object oriented languages such as Objective-C, Smalltalk, C++, Python, or Java; very-high level matrix languages such as MATLAB or GAUSS; and even symbolic algebra languages such as Maple or Mathematica. There are also a variety of special purpose toolkits for ABMS, including SWARM and MAML (built in Objective-C); Ascape, NetLogo, and Repast (built in Java or Scala); and many others [gilbert.bankes-2002-pnas]. [1] In addition, there are a few efforts at general environments in which a variety of ABMS experiments can be run. (Bremer’s GLOBUS model, Hughes’s IFs model, and Tesfatsion’s Trade Network Game model are salient examples.) Researchers occasionally express the hope that one of these might emerge as a lingua franca for ABMS research [luna.stefansson-2000-swarm]. Working against this, as others note, are the interfaces of capable toolkits and environments, which are often as difficult to master as a full-blown programming language [gilbert.bankes-2002-pnas]. A variety of languages and toolkits remain in use, and this seems likely to persist, along with efforts to assess their relative utility [railsback.lytinen.jackson-2006-simulation].

Although this course focuses on implementing models in NetLogo, it also provides relatively language-agnostic model descriptions. These will be useful for readers who wish to attempt an implementation in another language. Some of the slighly idiosyncratic vocabulary in this course is meant to support language agnosticism. For examples, agents in this course have attributes and behaviors. The term behavior translates to procedure (for implementations in procedural languages such as NetLogo) or to procedure method (for implementations in object-oriented languages). This translation is left to the reader.

This course uses the term function to refer to any subroutine that explicitly returns a value. Functions may be associated with agents, especially when agent state is an implicit argument of the function. The agent is considered to be the execution context (or just context) of such a function. To clarify this when discussing the function, the agent type becomes a modifier. For example, a Voter function is a function that runs in Voter context. In an object-oriented language, this would be a function method of the Voter type. In a functional language, this would be a function that takes a Voter type as its first argument. Again, this translation is left to the reader.

At times, language agnostic descriptions become awkward, so efforts in this direction are circumscribed. In particular, although this course presents some functional-programming concepts and techniques, it makes no serious attempt to accommodate readers who choose to model in a functional programming language. For example, the typical purpose of a procedure is to mutate values, and algorithm presentations generally assume the language in use provides definite and indefinite procedural loops. That said, readers who have chosen a functional programming language will often be sophisticated enough to work around the limited accommodation of their programming paradigm in this course.

Conformance to NetLogo Idioms

This course encourages separating display concerns from modeling concerns. For better or worse, many NetLogo programmers prefer to mix these together. For example, it is common to use the pcolor attribute of patches to encode patch state (not just its GUI representation). Patch colors display in the model View provided by NetLogo’s GUI, and this offers a natural representation of agent state.

Other aspects of the NetLogo language encourage this mixing of display concerns with modeling concerns. This is particularly true of NetLogo’s handling of its iteration counter, ticks. This counter must be initialized with the reset-ticks command, but this command also runs any setup code and update code contained in plot widgets. (Additionally, buttons may be disabled until ticks is initialized, but no other conditional disabling is allowed.)

Similarly, the tick command does not just increment ticks, it also runs any update code contained in plot widgets. Furthermore, the tick command updates the View in the Interface tab whenver the model is set to use tick-based updates. (This is the only alternative to continuous updates, which by default happen \(30\) times per second.)

In order to better separate display concerns from modeling concerns, this course therefore often deviates from a small number common NetLogo idioms. For example, GUI coloration and agent state are usually separated. As another example, a separate steps counter is often introduced as a global variable in models, rather than relying on ticks. Editing a model to better match the idioms in NetLogo’s Models Library generally requires small changes in no more than three or four lines of code.

In one additional deviation from a common NetLogo idiom, this course often includes plotting code in the NetLogo Code tab rather than within the plot widget. The reason for this is purely pedagogical: it is often easier to examine the code for multiple plots if it is all grouped together rather than hidden in separate plot widgets. This advantage comes at a fairly small cost: plot widgets must be specified with the set-current-plot command.

One payoff to this course’s attempts to better separate modeling concerns from presentation concerns is a more language-agnostic presentation. Most model descriptions in this course should be readily implemented in a variety of programming languages, without requiring use of a GUI toolkit.

Typographic Conventions

This book uses the following typographical conventions.

new terms

Potentially unfamiliar terms may receive emphasis, especially near an initial definition.

code

Code snippets are monospaced.

<substitutions>

Angle brackets indicate a needed substition by the reader (e.g., of a local file path). The substitution replaces the brackets as well as the enclosed term.

Agent-Based Social Science

Emergence

Agent-based social science uses agent-based simulations for social-scientific investigations. In particular: we are interested in using computer simulation to show how macro-level social and economic outcomes emerge from the micro-level interactions of heterogeneous autonomous agents.

Emergence is a concept we will encounter repeatedly in the student of agent-based social science. A macro-level pattern is considered to be emergent to the extent that it is not imposed by central direction but rather results from the interactions of autonomous agents. The classic example of emergence is the surprising order found in production and distribution in market ecnoomies. Apparently no central planner is need for surprising and extensive order to emerge even with millions of individual agents. Interest in emergence helped to draw social-science researchers to agent-based methods.

A Third Way

Agent-based simulation of social and economic interactions has been gaining adherents since the 1990s. Contemporary researchers often promote simulation methods as a “third way” of doing social science, distinct from both pure theory and from statistical exploration [axelrod-1997-pup]_. Many methodological questions remain areas of active inquiry, especially in the realms of model robustness and model/data confrontations. Yet researcher has already found that new computational methods can sometimes shed light on intractable theoretical puzzles. Some researchers have gone so far as to argue that pure theory has little left to offer---that for social science to progress, we need simulations rather than theorems [hahn-1991-ej]. It seems more likely, however, that both simulations and theorems will continue to be important in social science.

Agent-Based compared to Traditional Math Tools

“[T]he reason for the dominance of the rational choice approach is not that scholars think it is realistic. ... The real advantage of the rational choice assumption is that it often allows deduction.”

—[axelrod-1997-iccsss]_

Mathematical theory, computational modeling, and statistical methods will all have a continuing role in social science. We should choose the best tool for the task at hand, where the best tool may be influenced both by the researcher’s skill set and the substantive area of investigation. Nevertheless, one may crudely contrast typical mathematical models in social science with their agent-based counterparts on a number of methodological aspects. The following table proposes some aspects as typical to each modeling approach.

Model Aspect

Mathematical Models

Agent-Based Models

Agent Behavior

Optimizing

Rule-Governed

Agent Choices

Continuous

Discrete

Learning (if any)

Bayesian

Adaptive

Number of Agents

Few

Many

Agent Heterogeneity

Little or None

Lots

Agent Computation

Unbounded

Bounded

Agent Interactions

Implicit

Explicit

Spatial Relation

Implicit

Explicit

Disequilibrium Adjustment

Ignored

Embraced

Macro Structure

Imposed

Emergent

Robustness

Proved

Explored

When to use Agent-Based Models

This rough table of comparisons suggests that we may incline towards agent-based methods when we need to attend to any of the following.

  • agent interactions

  • agent heterogeneity

  • discrete decisions

  • limited information processing ability

  • adaptive learning

  • dynamic relationships (that form and dissolve)

  • spatial behaviours and interactions

  • disequilibrium adjustments

  • endogenous structural change

Patterns Emerge

Patterns in this macrostructure may then be (Axtell, 2005):

  • compared with empirical data,

  • used to revise agent internal states and rules, and

  • the process repeated until an empirically plausible model obtains.

e.g. ACE stock markets have been used to model heterogeneous agents: will the stylised features of such markets emerge? Yes.

The Study of Social Systems

Despite their high level of abstraction, the simulation models presented in this course are intended to help us think about real social systems. Recall that a system is a collection of interrelated parts—the components of the system—along with the structure of these interrelations. This structure includes the rules governing their interactions. In a social system, the components may be individuals or organizations, and some of the rules of interaction may evolve over time. These interactions can be complicated, and even when the interactions are simple, the behavior of the system can still be complex. This course pays special attention to models where very simple individual-level interactions produce complex patterns at the system level. The population growth model in this lecture is elaborated in the Logistic Growth lecture to provide a first example of complex dynamics in a simple system.

A Problem and Possible Response

Predicting the behavior of systems can be easier than predicting the behavior of components.

Popular culture: Hari Seldon’s psychohistory (Foundation, Asimov)

The study of social systems may appear quixotic. Individual behaviour often exceeds our understanding, so how can we hope to entire systems that comprise many individuals?

One possible hope is that the behavior of aggregates will prove easier to understand and even to predict than the behavior of individual components. We may hope for this by analogy to certain physical examples. For example, the ideal gas law is a simple statement about aggregate outcomes that does not require any predictions about the speed or location of individual molecules. We might analogously hope to have much more to say about market demand than about any individual’s demand, more about the distribution of wealth than about any individual’s wealth outcomes, and more about average fertility than about any couple’s fertility.

This course focuses on models that shed light not on the behaviors and outcomes of specific individuals but rather on system behavior and aggregate outcomes. For example, a traffic simulation is not used to predict the speed and location of each individual driver but rather to predict how the interactions of many drivers affects the aggregate transportation outcomes. Of particular interest are models that produce strong predictions about aggregate patterns that emerge from uncoordinated and unpredictable individual interactions.

References

[bremer-1987-globus]

Bremer, Stuart A. (1987) The GLOBUS Model: Computer Simulation of Worldwide Political and Economic Developments. Boulder, CO: Westview Press.

[gilbert.bankes-2002-pnas]

Gilbert, Nigel, and Steven Bankes. (2002) Platforms and Methods for Agent-Based Modeling. Proceedings of the National Academy of Sciences 99, 7197--7198.

[gulyas.kozsik.corliss-1999-jasss]

Gulyas, Laszlo, Tamas Kozsik, and John B. Corliss. (1999) The Multi-Agent Modelling Language and the Model Design Interface. Journal of Artificial Societies and Social Simulation 2, 8. http://jasss.soc.surrey.ac.uk/2/3/8.html

[hahn-1991-ej]

Hahn, Frank. (1991) The Next Hundred Years. Economic Journal 101, 47--50.

[hughes-1999-sg]

Hughes, Barry B. (1999) The International Futures (IFs) Modeling Project. Simulation and Gaming 30, 304--326.

[luna.stefansson-2000-swarm]

Luna, Francesco, and Benedikt Stefansson. (2000) Economic Simulations in Swarm: Agent-Based Modelling and Object Oriented Programming. Norwell, MA: Kluwer Academic Publishers.

[mcfadzean.stewart.tesfatsion-2001-ieee]

McFadzean, David, Deron Stewart, and Leigh Tesfatsion. (2001) A Computational Laboratory for Evolutionary Trade Networks. IEEE Transasctions on Evolutionary Computation 5, 546--560.

[minar.burkhart.langton.askenazi-1996-wp]

Minar, N., et al. (1996) "The Swarm simulation system: a toolkit for building multi-agent simulations". Santa Fe Institute Working Paper 96-06-042. http://www.swarm.org/archive/overview.ps

[north.howe.collier.vos-2005-macal]

North, M.J., et al. (2005) "Repast Simphony Development Environment". In Macal, C.M. and North, M.J. and Sallach, D. (Eds.) Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, Argonne, IL and Chicago, IL: Argonne National Laboratory and The University of Chicago.

[parker-2001-jasss]

Parker, Miles T. (2001) What is Ascape and Why Should You Care?. Journal of Artificial Societies and Social Simulation 4, 5. http://jasss.soc.surrey.ac.uk/4/1/5.html

[Railsback.Grimm-2019-PrincetonUP]

Railsback, Steven F., and Volker Grimm. (2019) Agent-Based and Individual-Based Modeling: A Practical Introduction. Princeton, NJ: Princeton University Press.

[railsback.lytinen.jackson-2006-simulation]

Railsback, Steven F., Steven L. Lytinen, and Stephen K. Jackson. (2006) Agent-Based Simulation Platforms: Review and Development Recommendations. Simulation 82, 609--623.

[Wilensky.Rand-2015-MIT]

Wilensky, Uri, and William Rand. (2015) An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. Cambridge, MA: MIT Press.

version:

2023-07-06