Agent-Based Modeling for Archaeology: Simulating the Complexity of Societies 1947864254, 9781947864252

To fully understand not only the past, but also the trajectories, of human societies, we need a more dynamic view of hum

294 105 13MB

English Pages 442 [444] Year 2021

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Agent-Based Modeling for Archaeology: Simulating the Complexity of Societies
 1947864254, 9781947864252

Table of contents :
0: The Art & Science of Building Societies in Silico
The Foundational Steps of Building an Agent-Based Model
Trading up to Complex Models of Economic Interactions
Reaping the Rewards: Addressing Archaeological Questions
Mobility Algorithms: How Does Movement Leave Its Mark?
Exchange Algorithms: How Do People Trade in Goods, Ideas, and Pathogens?
Subsistence Algorithms: Why Do Some Societies Thrive while Others Fade?
Modeling with Spatial Data: Bringing the GIS World to ABM
Modeling with Relational Data: Relationships and Exchange using Network Science
Data Analysis: Leveraging Data Science to Explore ABM Results
Conclusion
Glossary
Model Zoo
Making Colorblind-Friendly ABMs
Index

Citation preview

the loose earth, and you scrape here and there with a knife until finally

[ A G E N T- B A S E D M O D E L I N G F O R A R C H A E O L O G Y ]

Simulating the Complexity of Societies , which can create fine-scale models of behavior over time is the first humanities, and other social sciences, this book offers novices and more experienced and using it effectively. Readers will find the necessary background, discussion of modeling techniques also find engaging examples of how other scholars have applied

complexity of past human societies, offering researchers a richer understanding of I Z A ROM A N OWS K A COLI N D. W R EN S T E FA N I A . C R A B T R E E

PR SS

o X I TY f E v o l

vi ng Worlds · S e

or i n g f OR D E

LE

h rc

P

t h e C OM IN

R

a

ACKNOWLEDGMENTS The SFI Press would not exist without the support of William H. Miller and the Miller Omega Program.

[ A G E N T- B A S E D M O D E L I N G F O R A R C H A EO L O G Y] Simulating the Complexity of Societies

I Z A ROM A NOWSK A COLIN D. W REN S T E FA N I A . CR A BT R E E

SFI

© 2021 Santa Fe Institute All rights reserved.

PRESS

T H E S A N TA F E I N S T I T U T E P R E S S

1399 Hyde Park Road Santa Fe, New Mexico 87501 Agent-Based Modeling for Archaeology: Simulating the Complexity of Societies isbn (ebook): 978-1-947864-38-2 Library of Congress Control Number: 2021940330 The SFI Press is supported by the Miller Omega Program.

T I N Y D E TA I L S

imperceptible to us decide everything! W. G . S E B A L D

Vertigo (1990)

T C O N T E N T S 0: The Art & Science of Building Societies in Silico . . . . . . . . . . . . . . . 3 PA R T I : L E A R N I N G T O W A L K 1: The Foundational Steps of Building an Agent-Based Model Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Model: Young & Bettinger’s Simulation of Dispersal . . . NetLogo Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setup Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Go Procedure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introducing the If Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . Theory of Simulation & Modeling . . . . . . . . . . . . . . . . . . . . . . Modeling a Landscape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. 19 . 20 . 23 . 24 . 28 . 28 . 32 . 35 . 39

2: Trading up to Complex Models of Economic Interaction Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Model: Simple Roman Trade . . . . . . . . . . . . . . . . . . Setting up the Trade Model . . . . . . . . . . . . . . . . . . . . . . Manipulating Different Types of Variables . . . . . . . . . . . . . Running the Trade Model . . . . . . . . . . . . . . . . . . . . . . . . Looping Code Segments . . . . . . . . . . . . . . . . . . . . . . . . . . . Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plotting Model Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. 45 . 46 . 49 . 56 . 57 . 60 . 61 . 64 . 65 . 70

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

3: Reaping the Rewards: Addressing Archaeological Questions Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 The Model: SugarScape & Artificial Anasazi . . . . . . . . . . . . . . . . . . 76

ix

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. 78 . 86 . 88 . 90 . 92 . 98 . 99

4: Mobility Algorithms: How Does Movement Leave Its Mark? Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modeling Human Movement . . . . . . . . . . . . . . . . . . . . . . . . . . An Introduction to Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . Pedestrian Movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Random Walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Correlated Random Walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lévy Flights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Targeted Walk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Weighted Random Walk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Restricted Walks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Remembered Landscapes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Flocking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Group/Household Movement . . . . . . . . . . . . . . . . . . . . . . . . . . Multilevel Mobility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Population Dispersal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Basic Model: Fisher–Skellam . . . . . . . . . . . . . . . . . . . . . . . . Probabilistic Cellular Automata, ABM-style . . . . . . . . . . . . . . . . . Leap-Frogging and Despots . . . . . . . . . . . . . . . . . . . . . . . . . . . . Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Data Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stylized Facts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Model Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . .

107 108 .110 . 111 . 111 .114 . 115 .116 .119 .121 122 127 127 130 134 134 .135 .141 142 143 145 146 146

First Steps in Subsistence & Model Accounting . . . . . A Toy Landscape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Validation: Is my Model “Right”? . . . . . . . . . . . . . . . . . Simulating the Creation of an Archaeological Record . Dynamic Lists and their Manipulation . . . . . . . . . . . . . . . Building Artificial Anasazi . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

PA R T I I : L E A R N I N G T O R U N

x

5: Exchange Algorithms: How Do People Trade in Goods, Ideas, and Pathogens? Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modeling Commercial Exchange . . . . . . . . . . . . . . . . . . . Basic Exchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Supply & Demand. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Price-Setting Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . Models of Information Transmission . . . . . . . . . . . . . . . . Vertical & Horizontal Transmission . . . . . . . . . . . . . . . . . . Biased Social Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . Content Bias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frequency Bias: Conformist Bias, Anti-Conformist Bias . . . . . Payoff or Model-Based Bias . . . . . . . . . . . . . . . . . . . . . . . . Mutation, Innovation & Error . . . . . . . . . . . . . . . . . . . . . Cumulative Cultural Evolution . . . . . . . . . . . . . . . . . . . . . Putting Together a Model of Cultural Transmission . . . . . . . . The SIR Family of Models . . . . . . . . . . . . . . . . . . . . . . . . Ontology Building & Parsimony . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. 155 .156 156 159 166 .171 .171 173 173 176 177 178 179 .181 .183 187 189

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

6: Subsistence Algorithms: Why Do Some Societies Thrive while Others Fade? Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Modeling Resource Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . Population Resilience in the Face of Environmental Perturbation Putting Energy to Use: Ways to Increase Resilience . . . . . . . . Foraging Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Patch-Choice Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Prey-Choice Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Household-Level Production & Population Dynamics . . . . . . . . Population Stability & Growth . . . . . . . . . . . . . . . . . . . . . . . . . . . Agent Fitness & Evolutionary Dynamics . . . . . . . . . . . . . . . . . . . . . Tragedy of the Commons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Game Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Parameterization, Realism, Abstraction & Heterogeneity . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. 193 . 195 . 199 . 203 . 208 . 208 . 212 . 214 . 221 . 223 . 228 . 233 . 235 . 237

xi

PA R T I I I : L E A R N I N G T O F LY 7: Modeling with Spatial Data: Bringing the GIS World to ABM Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bringing GIS Data into NetLogo . . . . . . . . . . . . . . . . . . . . . . . . Raster Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Importing Patch Landscapes from Raster Data. . . . . . . . . . . . . . . . Importing Places with Vector Data . . . . . . . . . . . . . . . . . . . . . . . . Perceiving Raster & Vector Data . . . . . . . . . . . . . . . . . . . . . . . . . Agent–Patch Interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Agent–Agent & Patch–Patch Interactions . . . . . . . . . . . . . . . . . . . GIS Data Sources & Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using Artificial Landscapes to Control Spatial Variables . . . . Profiling your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. 247 . 249 . 250 . 252 . 254 . 257 . 260 . 264 . 267 . 269 . 270 . 277

8: Modeling with Relational Data: Relationships and Exchange using Network Science Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Theories on Exchange . . . . . . . . . . . . . . . . . . . . . . Sahlins’s Model of Exchange . . . . . . . . . . . . . . . . . Network Models . . . . . . . . . . . . . . . . . . . . . . . . . . . Code Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Print Statements & Manual Tests . . . . . . . . . . . . . . . Extreme Scenario Testing . . . . . . . . . . . . . . . . . . . . . Assertive Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. 281 . 285 . 287 . 290 . 302 . 303 . 303 . 305 . 306 . 308

9: Data Analysis: Leveraging Data Science to Introduction . . . . . . . . . . . . . . . . . . . . . . . . . Running Models . . . . . . . . . . . . . . . . . . . . . What Data to Collect? . . . . . . . . . . . . . . . . . How Long Should You Run the Model? . . . . . . How & When to Export the Data? . . . . . . . . . Running Experiments with BehaviorSpace How Many Times Should You Run a Scenario? . Model Calibration & Selection . . . . . . . . . . . . xii

. . . . . . . . . .

Explore ....... ....... ....... ....... ....... ....... ....... .......

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

. . . . . . . . . .

ABM Results . . . . . . . . . . . .313 . . . . . . . . . . . 316 . . . . . . . . . . . 316 . . . . . . . . . . . .317 . . . . . . . . . . . 318 . . . . . . . . . . . 321 . . . . . . . . . . . 325 . . . . . . . . . . . 325

Working with BehaviorSpace Output Data Microsoft Excel . . . . . . . . . . . . . . . . . . . . . . R & Python . . . . . . . . . . . . . . . . . . . . . . . . Interpreting ABM Data . . . . . . . . . . . . . . . . Detecting Causality, Sensitivity & Uncertainty . Emergence . . . . . . . . . . . . . . . . . . . . . . . . . . How & What to Publish . . . . . . . . . . . . . . . Publishing Code . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. 326 . 327 . 329 . 333 . 334 . 337 . 338 . 340 . 341

10: Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

A P P E N D I X & B A C K M AT T E R Appendix Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 The ABMA Model Zoo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 Making Colorblind-Friendly ABMs . . . . . . . . . . . . . . . . . . . . . . . . . 379 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417

xiii

I C H A P T E R 01 : THE ART & SCIENCE OF BUILDING SOCIETIES IN SILICO

The archaeological record is the accumulation of past peoples’ detritus, from which we piece together the vast, and exceedingly complex, histories of ancient societies. As archaeologists and historians we want to understand interaction, hierarchies, relationships between social and natural environments, and social processes, yet all we have are proxies of these processes: stone tools dispersed across the landscape, traces of agricultural activity, or a few brief mentions in written sources. Can we, as scientists observing the end product and the few snapshots preserved in the archaeological record, understand the actions and interactions of individuals? How can we best get to the root of the processes that produced the world as we know it today? Can we piece together these clues in a principled manner, and could we understand how history’s contingencies led to the record we observe through archaeological or historical sources? Examining these kinds of hypotheses with traditional methods is difficult; for example, the classic scientific method—that is, running experiments—is not possible when one investigates the distant past. Therefore, we must find other ways to study the processes that governed past societies. Annie Forgeau, professor of Egyptology at the Sorbonne, was famous for starting each semester of lectures by saying that archaeologists needed to read mystery novels to learn how to piece clues together to see how a fragmented record can tell us about events in the past. Like Sherlock Holmes, archaeologists must discover fragments of past activity from which they derive the evidence for what happened. Once we piece these clues together we can examine how the trajectory of history has led to the world we see today, using archaeology as a calibration dataset for approaching modern challenges. In a famous quote 1

OVERVIEW ▷ Why simulation? Why agent-based modeling? ▷ What is complexity science? ▷ Brief history of ABM and ABM applications in archaeology ▷ The modeling framework: NetLogo ▷ Structure of the book

Since NetLogo’s numbering system begins with the number 0, we do that here too! 3

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Simulation is the connection between empirical, data-based research and theory.

4

Stephen J. Gould summarizes the challenge that faces researchers working with datasets from the distant past: “Wind back the tape of life to the early days of the Burgess Shale; let it play again from an identical starting point and the chance becomes vanishingly small that anything like human intelligence will grace the replay” (Gould 1990). This quote describes how the contingencies of history—such as the individual actions and interactions of organisms as they competed with and consumed each other—led to the evolution of complex intelligence through one of the many possible trajectories, most of which would culminate in a world very different than the one we are familiar with. While Cambrian fossil beds and their evolution may seem a far cry from questions governing human history, we share the problem of studying long gone and thus inaccessible systems. Yet we are not alone; a surprisingly large group of scientists cannot experiment on their objects of study for practical or ethical reasons. There are those studying the past, like the big bang or dinosaurs; those who study topics that are too big, too small, too expensive to build or too far away, like galaxies or underwater cities; and finally those whose experiments, if ever allowed, could pose a risk to human life or welfare, for example, fire evacuation scenarios or large economic interventions. None of these researchers can simply try things out on real subjects and observe what happens. So how do other disciplines approach these limitations? In the past few decades, scientists have been able to build theoretical frameworks and sophisticated hypotheses by testing them against available data with the aid of advanced computational techniques, in particular, simulation modeling. In archaeology and historical disciplines, simulation modeling gives us a way of observing the possible lives of people in the past and analyzing our theories about them. These in silico experiments can help us test and refute hypotheses, investigate the causal mechanisms underlying societal transformations, and better focus data collection to help us answer the key questions. This truly is a revolution in how we do research in disciplines concerned with the past. One can think of simulation as a type of Binfordian middle-range theory that enables the linkage of empirical databased research and theory-building exercises (Binford and Sabloff 1982). Often one can easily guess the most likely explanation for a data pattern. Simulation proves invaluable in the many cases where we deal with systems that

Introduction: The Art & Science of Building Societies in Silico are inherently complex, full of nonlinear interactions and feedback loops, and occasional historical contingencies. History is rife with such complex systems, and thus it requires appropriate tools to study them. A Complexity-Science Approach The study of complex systems is known as complex-systems science, also shortened to complexity science, complex systems, or complex adaptive systems—all of which will be used more or less interchangeably in this book. It provides tools for examining the dynamics of systems composed of interacting elements and the contingencies of their histories. Complex systems differ from chaotic systems, whose behavior is highly dependent on initial conditions and therefore difficult to predict in the long term, but which lack a certain level of organization typical of complex systems. Complexity science can be encapsulated in the axiom “the whole is greater than the sum of its parts.” Put another way, a complex system is one in which the individual elements interact to form something that could not have been achieved merely by summing the characteristics of these individual elements. A simple illustration of this can be found in the dynamics of flocking birds. A single bird may fly with a specific goal in mind, and a skein of geese may form a V with predictable (though quite sophisticated) flight dynamics. Yet when starlings flock together, they travel in complex murmurations that seem to resemble a living organism (fig. 0.0). While watching the intricate twisting and turning of the murmuration, it looks like the birds must be guided by a leader bird who possesses an intricate ability to anticipate the movements of the flock as a whole. How else could the individual birds move almost as one without running into each other? In fact, murmurations can form when each bird follows just three simple rules, none of which involve high-level cognitive capacity:

Complexity science’s guiding axiom is “the whole is greater than the sum of its parts.”

1. Do not come too close to neighboring birds. 2. But do not stray too far away from them either. 3. Fly at about the average speed and direction of your neighbors. In his Boids simulation of a flock of birds, Reynolds (1987) demonstrated that, despite their individual simplicity, the birds’ interactions form the complex and unpredictable whole that creates the organism-like entity

5

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 0.0. A murmuration of starlings [Source: James Wainscoat, Starling roost at Otmoor, UK (Unsplash)].

that we admire in nature. The actions and interactions of the individual birds lead to the complexity of a whole flock. Intuitively, we may be able to understand the interactions between two or among perhaps three individuals who follow one or two rules of behavior. But with increasing quantities of individuals and the different processes that influence them, analyzing these interactions becomes intractable for any analog method. This is where computers enter the stage as the main tool used in complexity science. In a simulation, we are able to outsource to a computer’s processor the impossible task of keeping track of thousands of parallel computations. This is a task well beyond the cognitive ability of our own brains but which computers excel at. It is therefore not surprising that the rise of simulation and complexity science trailed closely behind the development of computers and their ever-increasing computational power. What are Agent-Based Models & Why Should We Care? Agent-based modeling investigates complex phenomena from the bottom up.

6

Agent-based models (ABM) are a type of computer simulation that enables investigation of complex phenomena from the bottom up. We will explain the terms model and simulation in the next chapter, but for now it suffices to say that ABMs encapsulate three key elements:

Introduction: The Art & Science of Building Societies in Silico 1. Individual, heterogeneous, and autonomous software units— agents; 2. User-defined rules of behavior that govern the actions and interactions of these units; and 3. Explicit spatial and temporal dimensions (common, but not required). The agents can stand for any object of study. In archaeological simulations, they have represented individuals (Wren et al. 2020), households (Kohler, Bocinsky, et al. 2012), settlements (Clark and Crabtree 2015), and villages or cities (Brughmans and Poblome 2016). In other disciplines, they have represented proteins or viruses (Semenchenko, Oliveira, and Atman 2016), ants (Epstein and Axtell 1996), cars (Raney et al. 2003), monkeys (Bonnell et al. 2010), individuals with illnesses (Epstein et al. 2008; Hammond 2009), and phonemes (Stevens, Harrington, and Schiel 2019). These agents interact with each other and with their environment following a set of behavioral rules, which, when aggregated, produce population-level patterns. It is this ability to model the interactions of individuals and their roles in structuring systems (the whole) that leads many social scientists, including those studying the past, to turn to agent-based modeling. There are no hard-and-fast rules dictating what agent-based models can represent, nor how they should be built. In this way, ABMs are light on assumptions, can be built according to user specification, and depend on the developer to build the model in a logical and realistic way. While the following axioms are not necessarily always followed, modelers will choose to build an agent-based model if at least a couple of the following characteristics of the system is true. Here we will use examples from epidemiology.

There are no hard-and-fast rules dictating what agentbased models can represent, nor how they should be built.

1. The actions and interactions of individual agents will lead to unintuitive and often unpredictable (emergent) population-level patterns. Emergence refers to a phenomenon in which simple interactions between a system’s elements lead to unexpected global behavior (Epstein 1999). If a system does not exhibit emergent properties, we could probably simply guess how it will behave and would not need to bother with simulation. In contrast, we wouldn’t be able to predict the future trajectories of chaotic systems at all. We have already 7

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

The major strength of agent-based models compared to other types of simulation is that the modeled populations are heterogeneous.

seen an example of emergence in the Boids model when individual birds’ actions formed an unexpected global-level pattern—the murmuration. These types of emergent phenomena are visible in many other complex systems. For example, Hammond and Ornstein (2014) model how the public health crisis of obesity can emerge from individuals updating their idea of what average body weight is; over time, the population will experience a gradual increase in body weight. 2. There is heterogeneity among individuals, and interaction among agents is important. The major strength of agent-based models compared to other types of simulation is that the modeled populations are heterogeneous. For example, different types of people (e.g., children, adults, elderly) may have different susceptibility to infection or engage in different activities, which increase or decrease their chance of contracting a disease (e.g., hand-washing habits of a three-year-old versus an adult). 3. The dynamics of individual interactions unfold over time. Agent-based models often examine processes that unfold over time in a complicated and often unpredictable manner. Without the time dimension, no interaction can take place, and we would simply look at a static snapshot. For example, epidemiologists do not simply describe the current situation but rather use their mathematical models to simulate the processes and phenomena that led to a disease outbreak, and then extrapolate them to the future (Willem et al. 2017). 4. The dynamics have spatial variability or the interactions with the environment are important. Although not strictly necessary, the spatial dimension is present in the majority of agent-based models. It naturally adds heterogeneity to agents, since each one finds itself in a unique set of circumstances due to its location with respect to other agents and the environment. Agent-based models were deployed to predict, for example, the spread of flu pandemics, taking into account different types of space, such as urban or rural areas (e.g., Epstein 2009). In this way, models look at how agents interact with their environment (spatially) and how this changes the ways we could expect epidemics to spread.

8

Introduction: The Art & Science of Building Societies in Silico 5. The studied system consists of entities that may learn or adapt, thus dramatically changing the rules of interaction. Humans are rarely passive in the face of a crisis. For example, if the burden of the disease in the early stages of an epidemic becomes high enough to merit behavioral changes (such as mask-wearing or socialdistancing mandates), the epidemic may enter into a phase governed by completely different rules.2 ABM is able to capture these kinds of “sudden game-changer” dynamics. Often a modeler will use these to determine whether to invest in building an agent-based model instead of using another technique, such as coupled differential equation models, GIS, or data modeling methods. In some agent-based models, one or many of these elements may not be as apparent. For example, a model of mate choice may not be spatially explicit, if the modeler opted for a network representation, even if the network may have an underlying topology. In some models you may only have one agent (e.g., Brantingham 2003), so agent heterogeneity is not involved. It is up to the modeler to determine which aspects are important given the research questions. To recap, creating agents, letting them interact with each other and their environments, and allowing the simulation to play out over space and time enables us to build societies in silico and to experiment on them without the practical limitations or ethical implications of experiments in living communities. Once these models are created, we run them multiple times, changing the various parameters to examine under which circumstances agents’ interactions lead to patterns comparable with the data trends we want to compare them to, such as archaeological data or daily infection numbers during a pandemic. Thus, agent-based models provide a way to examine the contingencies of history, to test our assumptions about the dynamics that governed these systems, and to investigate how individual interactions lead to chains of consequences that produce observable facts. We can examine with precision alterna2

We wrote these parts of the book before the COVID-19 pandemic began, in late 2019. Needless to say, from an observational context, it is interesting to see how much agent-based modeling has been used to tackle the COVID pandemic (e.g., Squazzoni et al. 2020). 9

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

tive historical trajectories and scenarios and identify which of our theories about the past best agree with the data. For example, in Crabtree (2015) agents follow simple rules that maximize farming and hunting returns, while also trying to minimize trading costs. As a result, the agents end up aggregated on the landscape in a specific pattern comparable to the archaeological record. Agent-Based Models: A Concise History E A R LY A B M S

Like many modern scientific techniques, agent-based modeling has its deepest roots in the Manhattan Project, where John von Neumann and Stanisław Ulam worked on a self-replicating machine (Macal 2009). Ulam developed an innovative implementation of von Neumann’s concept in the form of a grid with squares—an idea that later developed into a direct ancestor of ABM: cellular automata (mostly known from the famous Game of Life model). Various models are cited as the earliest true agentbased modeling attempts, among them the Schelling–Sakoda segregation model (Sakoda 1971; Schelling 1971), the Axelrod Prisoner’s Dilemma tournament (Axelrod 1980), or the aforementioned Reynolds (1987) flocking model. However, the real boom for ABMs came in the 1990s with the explosion in popularity of complexity science and a relatively sudden appearance of several ABM frameworks (including NetLogo, the platform we will use in this book), which removed much of the coding overburden that previously had to be painstakingly coded by the modelers themselves. Combined with more widespread personal computers, these computational frameworks made it entirely possible for researchers without a computer science degree to code a model. Since then, ABM has been used extensively in ecology (where it is often known as individual-based modeling or IBM; see Grimm 1999), social sciences (Epstein and Axtell 1996; Gilbert and Troitzsch 2005; ChattoeBrown 2013), geography (Heppenstall et al. 2012; O’Sullivan and Perry 2013), health sciences (Hammond 2010; Hammond, Osgood, and Wolfson 2017), economics (Farmer and Foley 2009; Hamill and Gilbert 2016), and other fields. The diversity and increasingly rapid pace of agentbased modeling across virtually all domains of science has led to models 10

Introduction: The Art & Science of Building Societies in Silico often incorporating submodels from outside of their modeler’s specialty—geography, health, economics, or sociology—to account for multiple dimensions of human behavior and social evolution. Coders from disciplines beyond archaeology and history have meticulously developed models to explore the complexity of human societies. This book often refers to those existing models, as we can adapt them to study communities that lived in the past. ABM IN ARCHAEOLOGY

To truly understand the human past, a comprehensive approach has always been needed. Archaeological sciences pull together many different, and often incomplete, lines of evidence to try to weave them into a cohesive understanding of past human societies. For this reason, archaeology was a somewhat unexpected early adopter of agent-based modeling methods (Lake 2014). Although the first archaeological simulations established roots in the 1970s (Doran 1970; Zubrow 1971; Thomas 1973; Wobst 1974), it was not until the 1990s that the agent-based models started to make an impression on the wider discipline (e.g., Mithen 1990). Agent-based models were spearheaded by archaeologists interested in questions encompassing the functioning of a system as a whole and the role of individual elements in their dynamics (processual and systems archaeology). Due to their inherently complex nature, such questions are especially difficult to understand via traditional archaeological methods. Unfortunately, the times when systemic questions dominated the archaeological mainstream (i.e., in the 1980s) did not coincide with the development of methods and tools that could facilitate this kind of study. The aforementioned ABM frameworks only became available in the late 1990s. This has caused a bit of a delay in archaeology’s application of ABM methods compared with other disciplines (especially ecology, but economics has also lagged behind considerably), and the true flourishing of archaeological ABM happened only in the 2000s (Lake 2014). One canonical agent-based model in archaeology, Artificial Anasazi (Axtell et al. 2002), which will be discussed in detail in chapter 3, showed society-level processes of maize farmers adapting to the unpredictable environment. Another early model (Brantingham 2003) looked at individuallevel behavior, demonstrating how the variability of lithic raw materials

Archaeological sciences pull together many different lines of evidence to try to weave them into a cohesive understanding of past human societies.

11

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

relate to individual decision-making. In a similar vein, Mithen (1987, 1990) and then Lake (2000, 2001) also modeled foragers but integrated other quantitative methods, such as GIS. The 2000s saw a significant increase in the number of published models (Cegielski and Rogers 2016) that encompassed a wider range of topics from hominin food sharing (Premo 2005) to the origins of urban centers in Mesopotamia (Wilkinson et al. 2007). There are several large families of archaeological agent-based models. In particular, the two topics that have been more extensively explored are evolutionary processes, often related to questions about human evolution and the Palaeolithic, and the dynamics of socionatural systems focused on the relationship between human groups and the environment (Lake 2014). However, even if the coverage is quite uneven, almost all time periods and geographical areas have been addressed with ABM. We will review many of these models in this book and you’ll find their code in the ABMA Code Repo.3 SOFTWARE

Throughout the book we will be working in a simulation platform called NetLogo (Wilensky 1999), a free and open-access ABM coding environment. While it was initially intended for teaching schoolchildren beginning-level programming, it has developed into a language of its own used to build simulations in fields as diverse as archaeology, ecology, public health, and economics. NetLogo is the most popular ABM platform among archaeologists (Davies and Romanowska 2018) and also has relatively readable code, which means that it is at least superficially understandable to human readers, even nonmodelers. While there are many other programming languages, NetLogo’s accessibility enables quick mastery of programming and a shorter route to writing your own working models. Further, it can be an entry point to learning other programming languages, such as Java, Python, R, JuLiA, or Objective-C. NetLogo offers the added functionality of user-developed extensions that can easily scale up the program’s abilities without much additional work for the programmer (see part III). It also comes with a built-in Models Library, which contains peer-reviewed models ranging from phys-

NetLogo is the most popular ABM platform among archaeologists.

3

12

https://santafeinstitute.github.io/ABMA/

Introduction: The Art & Science of Building Societies in Silico ical to biological to social systems, providing a great baseline for beginning and advanced model builders alike. For these reasons, NetLogo is a useful platform for teaching agent-based modeling and for quickly building archaeological ABMs. The Book’s Structure The book4 is divided into three parts: I. Learning to Walk; II. Learning to Run; and III. Learning to Fly. Each part consists of three themed chapters: movement, exchange, and subsistence. This structure means that you can read the book in a number of ways. If you’re new to ABM and want to make it your thing, start from the beginning and work through all the chapters in order. If you have a particular agent-based modeling level you want to consolidate or advance, you can read horizontally through one part (see table 0.0). The first part, Learning to Walk, focuses on gaining coding skills and gives the basic outline of the methodology of modeling. A “zoo” of algorithms and more in-depth treatment of modeling concepts and methods are given in the second part, Learning to Run. Finally, the third part, Learning to Fly, deals with combining ABM with different types of data: spatial data (GIS) (ch. 7), relational data (networks) (ch. 8), and data analysis of artificial (output) data (ch. 9). If you’re an expert in a particular topic and want to build a model (or are supervising a student modeler), you can read the book vertically. Chapters 1, 4, and 7 will give you all the necessary tools for models of human movement at different scales. Chapters 2, 5, and 8 focus on models of exchange such as trade or cultural transmission, while chapters 3, 6, and 9 deal with the vast topic of modeling subsistence and human–environment interactions. If you just want to get a taste of coding, or if ABM is a lesson in your digital archaeology curriculum, then the chapters in part I, Learning to Walk, contain independent practical tutorials that can be easily integrated into classroom curricula. You can pick and choose whether you will focus 4

Each part consists of three themed chapters: movement, exchange, and subsistence.

Each chapter opens with a grid similar to this one, representing the structure of the book. The white square corresponds to the chapter in question.

The open-access, full-color PDF version of this textbook, as well as supplementary resources, can be downloaded from our website: https://santafeinstitute.github.io/ ABMA/ 13

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

on the coding skills (chs. 1, 2, and 3 in part I) or on a particular topic (for example, subsistence, chs. 3, 6, and 9). Similarly, the book can serve as a reference to quickly look up, for example, movement algorithms (ch. 4) or how to integrate network approaches (ch. 8). The main elements introduced in each chapter are summarized in table 0.0. Thus, this book can be used to introduce a novice practitioner to agentbased modeling, but equally it can serve as a handy reference publication for a veteran modeler. It includes tutorials for more advanced techniques as well as a review and, in some cases, a reimplementation of published models. Finally, our broader goal is to provide a thorough grounding in complexity science through models of past societies and the three general themes of mobility, exchange, and subsistence. It is our intent that readers use the book in any way most suited to their particular circumstances. E

14

Introduction: The Art & Science of Building Societies in Silico

Table 0.0. The structure of this book and how it may be read horizontally (by the level of modeling proficiency) or vertically (by one of the three themes). This 3 × 3 chapter grid is also reflected in the matrices at the top of each chapter.

15

PART I: LEARNING TO

WALK



1 THE FOUNDATIONAL STEPS OF B U I L D I N G A N A G E N T- B A S E D M O D E L

1.0

Introduction

In this and the subsequent two chapters, we will use examples of simulations typical of archaeological agent-based modeling. Our aims are to: • familiarize you with the agent-based modeling technique and some vocabulary specific to complexity science and simulation; • introduce the basic principles of coding; and • explain the epistemological position of ABM in scientific practice and its role in the wider field of complexity science. Thus, by the end of Part I: Learning to Walk,1 you will have a good grasp of what ABM is all about, what it’s for, and how can it benefit archaeological inquiry. You will also be able to build a basic simulation and understand the challenges involved. Contrary to many textbooks that begin with background, each chapter will start with a hands-on practical element—implementing a model in NetLogo—and only later provide theoretical explanation. In our experience, our students gain a much better understanding of the concepts related to simulation and complexity science once they have tried them out for themselves first. If, while working through these chapters, you feel as if you do not fully understand what you are doing, reading ahead a few pages will likely clarify the situation, as each chapter is organized as a self-contained unit; trust that all will fall into place by the end of the part. Important note: When in doubt about any aspect of coding, head straight to the NetLogo documentation. In particular, the NetLogo Dictionary2 and the Programming Guide3 will be 1

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch1

2

https://ccl.northwestern.edu/netlogo/docs/dictionary.html

3

https://ccl.northwestern.edu/netlogo/docs/programming.html

OVERVIEW ▷ Intro tutorial in NetLogo software: INTERFACE and CODE tabs, agents, and procedures ▷ Definitions of modeling, simulation, and algorithm ▷ What is pseudocode? ▷ Types and purposes of models

19

PA RT I : L E A R N I N G TO WA L K

Model: Young & Bettinger (Y&B) Dispersal TEST ABMA Code Repo: ch1_Y&Bdispersal

of great help whenever you feel lost. They may initially look confusing but you’ll quickly get to know them well. To begin our tutorials, we will start with a simple model of human dispersal. Models of human movement lend themselves particularly well to simulation, especially ABM. They concern an inherently spatial and dynamic process, characteristics that make ABM particularly useful in comparison with other modeling techniques. To illustrate the process of developing a simulation, we will use a well-known model by Young and Bettinger (1995). It was designed to investigate the first dispersal of humans out of Africa. This model is a good example of the so-called “models from first principles” or “toy models”—that is, simple, abstract models investigating basic dynamics of a system, which became very popular in archaeology in the late 1990s (Lake 2014). We will implement the Young and Bettinger model in a NetLogo tutorial, taking you through the full process of model development. Finally, we will look back and use the experience gained to define such terms as model and simulation. We will discuss how these tools fit within the scientific process and how they can aid archaeological research. 1.1 The Model: Young & Bettinger’s Simulation of Dispersal

You can find a detailed description of the Fisher-Skellam-KPP model in chapter 4.

20

In their 1995 paper, Young and Bettinger (Y &B henceforth) used a simple diffusion model to investigate the out-of-Africa dispersal of modern humans (Gamble 2013). The authors asked whether the patterns in the archaeological record could be explained using the most basic principles of population growth and spread. Their simulation is not an agent-based model; instead, the authors used an equation known as the Fisher–Skellam– KPP model. Using equation-based models as the foundation for building an agent-based model is common, as they often provide a very clear baseline. The main Y &B algorithm creates a simple diffusion wave in all directions from the point of origin (East Africa) following a gradient, from more densely inhabited areas to those that are less populous. In a mechanism similar to that of a spreading wildfire, the population moves away from the point of origin in all directions and without turning back on itself. If this was the whole model, we could easily predict the results—areas closer to the point of origin in a strict geographical distance will be inhabited earlier than those farther away from it. However, the archaeological

Chapter 1: Building an Agent-Based Model data indicate that humans arrived in some areas (e.g., Europe) later than in others (e.g., Southeast Asia) irrespective of their geographical proximity. Clearly, a factor other than geographical distance must have influenced migration, slowing down or speeding up the dispersal in certain regions. Y &B hypothesized that the most plausible factor is the environment: species spread more rapidly across familiar environments than those to which they have not yet adapted. To account for that, the population growth rate and mobility values were set higher in the tropics and semitropical conditions similar to the starting area of the dispersal and lower in the northern, less familiar regions. Once the model was run, the pattern of dispersal was compared to archaeological data consisting of locations of archaeological sites and the dates of earliest traces of Homo sapiens in each region. The two patterns (often referred to as artificial data and empirical data) matched very well. But what does it mean in terms of our understanding of the out-of-Africa dispersal? Had the Y &B model captured the dynamics of that process? We will talk about the knowledge generation process in simulation studies at the end of this chapter. Let’s look at the model in more detail now. We will write an algorithmic description of it to make the subsequent implementation in code easier. An algorithm is simply a set of instructions like a cooking recipe: “Take A, mix with B, add C, and you get D” (see ch. 4 for a more thorough definition). We often write algorithms in pseudocode, that is, in a way that resembles the syntax of computer code but is readable to humans. You can then use it as a step-by-step summary of what the model does. Almost all ABM simulations consist of two phases. First is the initialization phase, where you define the world and its inhabitants, effectively setting up the state of the world at time step zero. Let’s write out our model’s setup in pseudocode: Set parameters [ population-growth = popG initial-pop-size = n initial-location = (x,y) ]

algorithm: a sequence of instructions given to a computer. pseudocode: a simplified notation of the structure of the code.

TEST TEST

PSEUDOCODE BLOCK 1.0

21

PA RT I : L E A R N I N G TO WA L K TEST TEST

PSEUDOCODE BLOCK 1.0 (cont.)

TEST PSEUDOCODE BLOCK 1.1

Create n agents For each agent, A, Place A in (x, y) Second, we define the run phase as the clock starts ticking and at each time step the world undergoes a series of events, such as climate change and agents’ actions. In pseudocode: At each time step, T, For each agent, A, Draw random number, N, between 0-1 If N < popG AND If there is at least one adjacent cell, C, (x±1, y±1) that is empty Create new agent, B, Place B on cell C The pseudocode says that at each time step, each agent will create a new agent if two conditions are met. The first condition is expressed probabilistically. Let’s imagine we define population growth as 0.1, aiming at a population that grows by approximately 10% over the course of one time step. Each agent draws a random number between 0 and 1; if this number is between 0.0 and 0.1, then the condition is met. The probability that a random number between 0 and 1 is lower than 0.1 is about 10%, so on average about 10% of agents could produce an offspring. However, we only allow them to do so if there is an empty cell available in their immediate neighborhood that can be colonized. Read carefully through the pseudocode, ensuring that you understand all abbreviations and can point out where they are defined. You have probably noticed that the pseudocode above is a simplified version of the Y &B model that does not yet have the environmental factor built in. We will start with this simple version and then expand it as we go. This is a common approach to building models: you start simply and gradually layer on complexity (see ch. 5).

22

Chapter 1: Building an Agent-Based Model

Figure 1.0. Main elements of NetLogo’s graphical user INTERFACE tab.

N E T LO G O I N T E R FA C E

NetLogo is used widely across virtually all scientific disciplines. It is often the first choice when creating proof-of-concept models, but it can also be used for modeling systems to their full complexity. It is particularly prevalent among social and life scientists (Hauke, Lorscheid, and Meyer 2017) and is by far the most popular agent-based modeling framework among archaeologists (Davies and Romanowska 2018). Logo—the ancestral language of NetLogo—was developed as an educational tool, so it resembles a natural language, making it easy to read and write. Nevertheless, if this is your first attempt at computer programming, you may initially feel intimidated. Fear not: you will rapidly grow accustomed to writing code. We will go particularly slowly with the coding challenges in this chapter to ease you in. Let’s start with the NetLogo program itself (fig. 1.0). When you open it, you will immediately notice three tabs: INTERFACE, INFO, and CODE. In the next few pages, we will look at these in turn. The INTERFACE tab consists of:

This heritage is why NetLogo refers to agents as turtles and to grid cells as patches.

• The VIEW panel for watching the simulation;

23

PA RT I : L E A R N I N G TO WA L K

Figure 1.1. The dialog box for adding a GO button. Note that the FOREVER box is checked.

• A few buttons, choosers, and a slider along the top of the window; and • The COMMAND CENTER toward the bottom of the window. This INTERFACE tab is where you will run and observe the dynamics of your model while the CODE tab is where you will write out the code of the model itself. You will flip back and forth between these tabs constantly as we continue. Finally, when you’re finished you should describe the model and how to use it in the INFO tab (there are headings to get you started). SETUP PROCEDURE

TIP Right-click anywhere on the white space in the INTERFACE to create a button. Click the FOREVER box if you want the code to repeat indefinitely.

24

The two phases we have seen in the pseudocode (initialization and run) are usually called setup and go in the NetLogo lingo. In the setup procedure, we will create the starting population of agents and build their environment. The go procedure is the main simulation loop with all processes that the agents and the environment undergo at each time step. We will activate (call) those procedures using buttons. Right-click anywhere on the white space and choose BUTTON. A dialog box will pop up (fig. 1.1). Type setup in the COMMANDS box and click OK. Follow the above step to create a second button and write go in the COMMANDS box. This time also tick the FOREVER box. Ticking FOREVER means that this action will repeat until the simulation ends or the user toggles the button off again by pressing the GO button a

Chapter 1: Building an Agent-Based Model second time. You can see that the text on both buttons has instantly turned red, indicating an error. The NetLogo interpreter does not recognize the code because go and setup have not been defined yet. Let’s move to the CODE tab to fix it. The CODE tab is dominated by white space. This is where we write code directing the flow of the simulation. To do so we use commands and reporters. Commands define the actions of an agent, while reporters calculate and report a value. We will come back to reporters in chapters 2 and 3. There are two types of commands and reporters in NetLogo: the userdefined procedures and built-in ones called primitives. The NetLogo Dictionary provides a description of all existing primitives and includes sample code.4 First, to define a procedure we use the keywords to and end . Like brackets they mark the beginning and the end of a procedure. In addition, we can already specify one action that the simulation has to perform at each time step: move the clock forward after each step. The tick primitive is often used to mark the end of all procedures in the current time step and to start a new one. It moves the time forward and triggers many commands that are called once per time step; for example, it updates plots. Type the following in the CODE tab: to setup end to go tick end If you now click the PROCEDURES list at the top of the screen, you’ll find that setup and go are listed there. Next to PROCEDURES is the debugger button, CHECK, which when clicked will check if the code’s basic syntax is correct. Click it now. If it throws an error, look at the line it highlights and make sure your spelling is correct. Now, let’s build the initial state of our model in the setup procedure. This procedure usually starts with the clear-all primitive, which 4

A procedure consists of all code enclosed between to and end . primitive: built-in procedure or variable name. TIP To check a primitive’s documentation, move your cursor so that it is within the word and press F1.

TEST CODE BLOCK 1.2 TEST

Click CHECK every time you write new code or change the existing one.

DON’T FORGET If you do not clear-all , your model will include turtles and patches from previous runs.

https://ccl.northwestern.edu/netlogo/docs/dictionary.html 25

PA RT I : L E A R N I N G TO WA L K

Figure 1.2. A small 5 × 5 patch landscape with randomly located agents and shaded patch color. We have added numbers that show the (X,Y) coordinates of each patch.

You can play with the setup in the ch1_patches model in the ABMA Code Repo.

26

removes any remnants of the previous run, including clearing plots and monitors, and finishes with reset-ticks , which resets the clock to zero. Write them in separate lines after setup but before end . Now that all the housekeeping has been taken care of, we can move to defining the elements of the simulation. If you look back at the pseudocode, you’ll see we need to create a number of agents. In NetLogo, agents are referred to as turtles, and the grid cells on which they live are called patches. This is a holdover from when NetLogo was developed to teach programming to children. We will use the create-turtles primitive to bring our agents to life. We also need to position the agents somewhere in the world using the setxy primitive. Let’s place them on a random cell between cells (0, 0) and (5, 5). Refer to figure 1.2, where we labeled the shaded patches to give you an idea of the area encompassed by random 5 random 5 . Inside the setup procedure, type:

Chapter 1: Building an Agent-Based Model TEST

to setup clear-all create-turtles 20 [ setxy random 5 random 5 ] reset-ticks end

CODE BLOCK 1.3

TEST

random 5 chooses one value at random among 0, 1, 2, 3, and 4.

Go back to the INTERFACE tab and hit SETUP. Do your agents appear? The brackets after create-turtles can also enclose features (variables) of the agent other than its location, for example, color , size , or shape . All of these built-in variables have default values, but you can also

You can check the documentation of create-turtles in the NetLogo Dictionary.

customize them, as in this example:

TEST

to setup clear-all create-turtles 20 [ set color random 140 set size 2 set shape "turtle" setxy random 5 random 5 ] reset-ticks end When you’re done, hit the CHECK button to make sure there are no errors and move back to the INTERFACE tab. Click the SETUP button again. Your agents are clustered to the upper right from the middle point of the screen, because by default the patch at point (0, 0) is located in the center. Instead, we would like the agents to start from the corner. Click the SETTINGS button in the top right corner of the INTERFACE tab. A window will pop up. Change the LOCATION OF ORIGIN to the bottom left corner and untick the WORLD WRAPS HORIZONTALLY and WORLD WRAPS VERTICALLY boxes. This will make our map a flat surface. If you hit SETUP now, all the agents should cluster in the bottom left corner.

CODE BLOCK 1.4 TEST

TIP Brackets are square [...] , parentheses are round (...) , and curly brackets are . . . curly {...} .

The map’s Point of Origin (0,0) can be moved to any one of the corners or to the center of the VIEW.

27

PA RT I : L E A R N I N G TO WA L K GO PROCEDURE

The body of all simulations, the go procedure, is a loop of commands that ask turtles [...] will ask each turtle (in random order) to perform the actions specified within the square brackets.

TEST CODE BLOCK 1.5

Many procedures require input values, e.g., fd 1 or create-turtles 10 . Consult the NetLogo Dictionary to see what type of input is required.

repeat at each time step. All commands aimed at agents in NetLogo are initiated by the word ask , followed by the entity that is to perform the tasks. The code block that defines these tasks is enclosed in square brackets [ ] . In this piece of code, we’ll ask all turtles ( ask turtles ) to turn right ( rt ) by a random number of degrees between 0 and a full circle ( random 360 ) and go forward one step ( fd 1 ). Write this code inside the go procedure, before tick , so that it looks like code block 1.5: to go ask turtles [ rt random 360 fd 1 ] tick end The number 1 after fd indicates that the turtle should move forward by the length of one patch. Hit CHECK, move to the INTERFACE tab and hit GO. You can use the SPEED slider at the top of the screen to make the simulation slower so you can see the turtles’ movement pattern more clearly. In the Y &B model, two factors drive the wave of advance. One is the random mobility that we have just coded, and the other is population growth. Without growth, the population will not be able to cover a larger region; instead, they will become like butter scraped over too much bread. So next we will code in population growth through reproduction, and then put the two together. I N T R O D U C I N G T H E I F STAT E M E N T

In the previous step, the movement happened with every tick of the model. We could do the same with reproduction, but we would rather be able to control how often reproduction occurs. This is where an if statement comes in. An if statement consists of two elements: a condition and a code block. The if statement’s code block is only run if the condition is fulfilled (true). If the condition is false, the code is simply not executed.

28

Chapter 1: Building an Agent-Based Model

Figure 1.3. To add interface elements to your model (buttons, switches, sliders, etc.) right-click where you want to place them (within the white area) and a drop-down menu will appear. Alternatively, click the ADD button and select the element from the drop-down list, before left-clicking the desired location.

While we work on the reproduction part of the code, we will comment out the turn and move commands. We will tell NetLogo not to execute these lines of code by placing a semicolon ( ; ) at the beginning of the line. Commenting out code is usually safer than just deleting it, as we may need it later. You should also use the semicolon to write short notes next to the code that explain what it does. Comment out the first two lines after ask turtles by adding a semicolon at the start of each line before the movement commands. Then add the if-conditional statement, so that your procedure looks like this: ask turtles [ ;rt random 360 ;fd 1 if random-float 1 Properties > Details Mac: right-click > Get Info > More Info > Dimensions

The PATCH SIZE setting regulates how the VIEW panel looks on your screen; it does not change the number of patches. TIP In NetLogo colors are represented by numbers from 0 to 140, but you can also refer to them using keywords like white , green , sky , or violet .

36

If you have ever worked with geographic information systems (GIS), you already have some experience with gridded raster data. If not, all you need to understand here is that the map is a grid of cells, and that we can assign each cell to a patch by taking a number corresponding to its color value. We need to import our map into NetLogo so that numeric values can be assigned to each patch ’s pcolor variable. NetLogo has a command to do this easily. Within the setup procedure, before we create any turtles but after the clear-all command, add the following line so that it looks like this: to setup clear-all import-pcolors "ch1_map.png" ... Click SETUP on the INTERFACE tab. We can see the map now, but it doesn’t fit our VIEW panel very well. The map image we imported is 600 × 351 pixels, and we would like each pixel to be assigned to one patch. Click the SETTINGS button and set the max-pxcor to 599 and the max-pycor to 350 (fig. 1.5). Why not 600 and 351? NetLogo space, like all Cartesian spaces, starts at a point (0, 0). Thus, the first column number is 0, the second is 1, etc. Whether it is the primitive random or the screen dimensions, NetLogo (as well as our book) always starts counting from 0. Since the earth is a globe, also check the WORLD WRAPS HORIZONTALLY box (but not WORLD WRAPS VERTICALLY—this would turn our world into a torus-ring doughnut shape). Check the text under the black square in the MODEL SETTINGS panel to verify that everything is correct. It should state “Vertical Cylinder: 600 × 351.” Next, click OK. If your VIEW panel is far too large now, reopen MODEL SETTINGS and set the PATCH SIZE to a smaller value. Click SETUP once more and verify that the map fits well. Run the model again, and you’ll notice a couple of things: first, it takes a lot longer to finish the run, because there are a lot more agents and patches now, and second, the agents are completely ignoring our map. Y &B’s dispersal model keeps things simple by coding patches as either 1 for land or 0 for water or ice sheets. All we need to know is the

Chapter 1: Building an Agent-Based Model

Figure 1.5. The MODEL SETTINGS box controls the size of the patches, position of the grid origin (one of the corners, center, etc.), and edge-wrapping options.

pcolor assigned to water on the imported map. Right-click on any water patch and choose INSPECT PATCH X Y from the drop-down menu, where x and y correspond to the coordinates of the water patch you clicked on. An INSPECTION panel will come up that provides variable values of that patch, as well as a close-up view of the patch. In our case, the pcolor value is 9.9, corresponding to white . We will use that value to tell turtles where not to go. We have two things left to do: move the turtles’ start location to eastern Africa, and then tell the turtles that they can only move on land. In the VIEW panel, right-click on any cell in East Africa and note

DON’T FORGET Parentheses are often not necessary, but they help to keep the code readable— an important consideration for future readers of your code (including yourself six months from now).

37

PA RT I : L E A R N I N G TO WA L K

its x, y coordinates. In setup , change the x, y coordinates inside the create-turtles command to ( your_X_coordinate + random 5 ) TEST CODE BLOCK 1.10

TEST CODE BLOCK 1.11

DON’T FORGET Change neighbors to neighbors4 to avoid unintended moves over diagonal boundaries.

If you open hatch in the NetLogo Dictionary, you’ll spot a turtle icon. observer: an agent that builds and controls all other simulation objects.

38

like this: setxy ( 360 + random 5 ) ( 170 + random 5 ) Next, go to the reproduce procedure and change the following lines to further limit the set of patches the turtles are evaluating for their offspring to only include land patches: to reproduce if any? neighbors4 with [ count turtles-here = 0 and pcolor != white ] [ let empty-patch one-of neighbors4 with [ count turtles-here = 0 and pcolor != white ] ... The ! = means “does not equal,” which tells the agents not to consider any white cells for their offspring. The and , known as a logical operator in computer programming, is a way of combining criteria within the condition where both have to be true. To prevent agents from jumping diagonally across bodies of water, we will also switch to the neighbors4 primitive, which means agents only move in cardinal directions. Check your code, then switch to the INTERFACE tab and run the simulation a few times (fig. 1.6). What do you notice about the dispersal wave as it passes through geographic bottlenecks like the Sinai Peninsula or south of the Black Sea? What pattern do you notice in the agent colors, and what could this represent? Note that we wrote the reproduce procedure to be agent-specific, thus only turtles can perform the procedure. We know this because it contains the turtle-specific primitive hatch . At each time step, each turtle (in random order) assesses their own situation (e.g., if any? neighbors4 ) and performs their actions accordingly. If you stop to think about it, though, who is doing the asking? NetLogo refers to this as the observer. Many commands can only be called by the observer, such as clear-all , tick , and our setup and go procedures. We’ll

Chapter 1: Building an Agent-Based Model

Figure 1.6. The population of agents disperses from eastern Africa and begins to spill out into Eurasia. Note that the agents are small enough that they almost look like a continuous surface.

discuss how to control which variables belong to agents, patches, or the observer in the next chapter. Finally, reflect on how you wrote your code. Just as you put thought and effort into creating a clear and easy-to-follow methods section in a scientific paper, you must also create code that can easily be followed by an outsider. NetLogo doesn’t care about white spaces, so you could write this whole model in one very long line of code. This is a bad idea, though. Like the methods section of your paper, code tends to get more and more complicated as you progress, so keeping it well laid out will spare you a lot of frustration. We have not included comments in the code blocks here, but if you check the model’s code in the ABMA Code Repo you’ll see inline documentation. 1.4

Summary

The simulation we built in this chapter is a model of human dispersal. It is a model because it is a simplified representation of the behavior of past human groups including their mobility and reproduction. Many possible factors influencing dispersal were deliberately left out of our model because we were using it to test the hypothesis that the pattern and speed of human dispersal across the world was primarily driven by population 39

PA RT I : L E A R N I N G TO WA L K

“All models are wrong, but some are useful.” – G. Box (1979)

40

growth and undirected movement. To test this hypothesis, we must parameterize the model by assigning reasonable values to our population growth rate and movement distance relative to the time step. You can consult Young and Bettinger’s paper for those values. If the simulated population arrives in Israel, Italy, China, Indonesia, Alaska, Chile, and other locations around the date of the known first occupation of those regions, then we will have demonstrated the plausibility of the hypothesis. Our simulation results may also have implications for theory building concerning early human dispersal. If the model exposes particular patterns in the spreading dispersal wave that disagree with archaeological data, this spurs the question of what factors might have been in play. For example, your agents might arrive in France before China, despite ample evidence that the contrary occurred in the Pleistocene. This could be because of differences in population growth rates or carrying capacity, as Y &B suggested, or it could be due to competition from Neanderthals. These and other options can be tested and compared against each other by extending the simulation further. These kinds of considerations can also nudge the researcher to return to the archaeological record and explore its possible biases and gaps. Do some geographical areas show particularly poor fit to the simulation? Have they been extensively studied, or is it likely that traces of the dispersal are underreported there? Models are not static end products in the research process but part of the cumulative understanding we are building about the past at both theoretical and empirical levels (Hesse 1978; Dunnell 1982; Neiman 1995). Models will not prove your hypothesis to be “true” with perfect certainty. A common saying in modeling, attributed to statistician George Box (1979), is that “all models are wrong, but some are useful.” In other words, while you’re unlikely to replicate the exact timings of dispersal across the world, the model will provide insight into what is and is not a likely factor driving dispersal. Even better if a model, built according to a common narrative explanation, is completely wrong and we must change our own understanding. Finally, it is worth reflecting on the technical side of things. If, prior to reading this chapter, you had never seen a line of code and the whole programming enterprise felt daunting, take a moment to contemplate the

Chapter 1: Building an Agent-Based Model fact that, after only a couple hours of basic training, you were able to replicate a published scientific study. It truly is not rocket science (even if rocket scientists build models, too). E End-of-Chapter Exercises 1. Change the other basic agent characteristics: size and shape . 2. Add a second population of turtles spreading from eastern Asia. Give each population its own fixed color . 3. Add an initial-pop-size slider. Modify the setup code to use this to vary the size of the original population. Also adjust the code so that these initial agents must be created on empty patches only. 4. First, add more population dynamics by adding age and death after a certain age. Second, add probability of death (which is similar to reproduction-probability). Define this probability as a function of age, so that the older a turtle gets, the higher its probability of dying. 5. Y &B use a variable carrying capacity to affect the dispersal characteristics. First, give all patches a variable called carrying-capacity (check patches-own in the NetLogo Dictionary). For land patches, set it to 1, and for water patches set it to 0. Modify the reproduction procedure to only allow turtles to hatch onto patches where carrying-capacity is greater than the count of turtles on that patch. Second, follow Y &B in setting carrying-capacity higher for patches below 30° of latitude, which corresponds on our map to pycor 307 . Does this make any difference to the dispersal rate? Further Reading ▷ A. J. Ammerman and L. L. Cavalli-Sforza. 1973. “A Population Model for the Diffusion of Early Farming in Europe.” In The Explanation of Culture Change: Models in Prehistory, edited by C. Renfrew, 343– 358. London, UK: Duckworth. ▷ J. Fort. 2018. “The Neolithic Transition: Diffusion of People or Diffusion of Culture?” In Diffusive Spreading in Nature, Technolo and

41

PA RT I : L E A R N I N G TO WA L K

Society, 313–331. Cham, Switzerland: Springer. doi:10.1007/978-3-31967798-9_16 ▷ S. J. Mithen and M. Reed. 2002. “Stepping Out: A Computer Simulation of Hominid Dispersal from Africa.” Journal of Human Evolution 43 (4): 433–462. doi:10.1006/jhev.2002.0584 ▷ R. L. Bettinger and D. A. Young. 2004. “Hunter-Gatherer Population Expansion in North Asia and the New World.” In Entering America: Northeast Asia and Beringia Before the Last Glacial Maximum, edited by D. B. Madsen. Salt Lake City, UT: University of Utah Press, September. ▷ P. Riris. 2018. “Assessing the Impact and Legacy of Swidden Farming in Neotropical Interfluvial Environments through Exploratory Modelling of Post-Contact Piaroa Land Use (Upper Orinoco, Venezuela).” The Holocene 28, no. 6 (June): 945–954. doi:10 . 1177 / 0959683617752857 ▷ I. Romanowska. 2015b. “So You Think You Can Model? A Guide to Building and Evaluating Archaeological Simulation Models of Dispersals.” Human Biolo 87 (3): 169–192. doi:10.13110/humanbiology. 87.3.0169 ▷ J. Steele. 2009. “Human Dispersals: Mathematical Models and the Archaeological Record.” Human Biolo 81 (2-3): 121–140. doi:10.337 8/027.081.0302. ▷ U. Wilensky and W. Rand. 2015. An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. Cambridge, MA: MIT Press, April. ▷ D. A. Young and R. L. Bettinger. 1992. “The Numic Spread: A Computer Simulation.” American Antiquity 57 (1): 85–99. doi:10.2307/ 2694836. ▷ D. A. Young and R. L. Bettinger. 1995. “Simulating the Global Human Expansion in the Late Pleistocene.” Journal of Archaeological Science 22 (1): 89–92. doi:10.1016/S0305-4403(95)80165-0 42

N OT E S

2 TRADING UP TO COMPLEX MODELS OF ECONOMIC INTERACTIONS

2.0

Introduction

Production, distribution, exchange, and consumption of goods are all topics of immense interest to those studying past societies. It is also a branch of scientific inquiry so vast it comprises hundreds of models, theoretical frameworks, and analytical methods. In this chapter we will show how to approach a modeling study departing from a data pattern and how to formulate research questions and hypotheses that we will then investigate using simulation. We will also consider the role of simple abstract models in giving us general intuition as to what dynamics might drive the system we study. Often we do not need to include all possible details into a model to gain a better insight into certain processes. This is something to keep in mind particularly when approaching economic models that are usually developed in data-rich environments, such as present-day economies—circumstances that we simply cannot mimic within the archaeological record. Nevertheless, in this chapter we will take a more data-centered approach compared with chapter 1 and look at how simulation can help us to understand common types of data patterns—here, the frequency curves of different types of artifacts. In particular, we will investigate how the distance from a Roman production center, the trading capacity of intermediate markets, and the number of goods being produced influence the introduction time of a product and its uptake curve at different markets. These trend lines can be directly compared with the changes in the distribution of different types of archaeological material at archaeological sites. We will further tackle the topic of exchange (which includes, but is not limited to, trade) in chapter 5, and we will focus on how to formally represent relationships using network science techniques in chapter 8.

OVERVIEW ▷ Tutorial in intermediate NetLogo: variables, loops, breeds, reporters, lists, and plots ▷ Building up to complex models ▷ Definitions of scale, entity, stochasticity ▷ Principles of code development and debugging techniques

45

PA RT I : L E A R N I N G TO WA L K

syntax (in computer programming): the set of rules, or grammar, governing the programming language.

In the first chapter, we used a simple model of hominins spreading across the world to introduce the process of building a simulation and to begin a few basic coding tasks. In this chapter, we will make further progress on coding skills. Similar to learning a natural language, such as French or Hindi, it takes some time and effort to fully grasp the grammar and the vocabulary of a programming language—so be aware that you may feel lost at times. This is absolutely normal and disappears quickly as you gain confidence in coding and solving errors. Similarly, thinking through a problem by means of formal representation, such as a simulation, may take some time to get used to, especially if this is your first experience with modeling. This chapter will introduce most of the key components of NetLogo syntax, which constitute its core functionality: • • • •

breeds and agents’ variables, global and local variables; if, while, and for loops; lists; and common primitives, such as of , with , any? , one-of , and myself .

We will continue following in parallel two important lines of the development of your modeling capacity: we will work on coding fluency by introducing new structures and methods, but we will also work through the process of building a simulation to better understand what kind of decisions the modeler needs to make and how to best approach them. 2.1 The Model: Simple Roman Trade The origin of many models lies in the quest to explain a data pattern revealed in the archaeological record.

46

When approaching a new modeling project, it is worth spending some time to evaluate what we know about the system, what kind of data can help us and what format it comes in, and what exactly we want to learn. In this chapter’s case study we start with a simple observation that at most archaeological sites one can trace the frequency of different types of artifacts over time (think of the famous battleship-shaped seriation curves). Imagine you plot the number of different pottery sherd types from your site on a time axis—all of them will likely start with a low number and then increase. However, these temporal trends have spe-

Chapter 2: Complex Models of Economic Interactions

Figure 2.0. Hypothetical pottery frequency curves at two archaeological sites. This type of data pattern is common in the archaeological record.

cific shapes—some grow in their popularity more gradually, others see a meteoric rise with a very rapid uptake curve (fig. 2.0). For example, you may observe that at your site certain types of Roman pottery (say, amphora type Dressel 20) arrive later than others (say, amphora type Pascual 1) but become ubiquitous quickly or, on the contrary, take years to get established. Why is that? Isn’t it true that “a pot is a pot is a pot”? Perhaps some were better than others, or perhaps some were produced in higher quantities, or maybe some types were easier to transport. What processes cause differences among products has been a source of much debate and usually focuses on the price, accessibility, and functionality of goods, though can also amount to a preference for one type over another (Brughmans and Poblome 2016; Crabtree 2016). We cannot test all possibilities at once, so in this chapter we will focus on factors related to accessibility, while exploring the general dynamics

Each simulation scenario is like a single experiment; as in any experiment, you can only test one factor at a time.

47

PA RT I : L E A R N I N G TO WA L K

entity: any object in a model.

48

of a simple trade model following the approach set out in Romanowska (2018). The aim of this study was to establish a baseline of how the frequency curve of different Roman amphora types may appear under different circumstances: low production, limited flow of goods between settlements, or restricted trading capacity of intermediate markets. This abstract model could then be useful for comparing against real archaeological data; its generality is its strength in that it can be applied to any category of archaeological finds that were produced and traded. We will build a simplified model of a trading system in which goods move from a production center to different markets following simple exchange rules. We will then record the frequency of goods at each market over time, thus essentially creating an artificial archaeological record. Because the format of the simulated assemblages will be the same as frequency curves recorded at real archaeological sites, it will give us an idea as to what factors could have caused these patterns. As we saw in chapter 1, it’s common to begin a model from the simplest approximation by capturing the key dynamics of a system in the most general sense, even if this implies making some gross simplifications. It’s worth revisiting the definition of model at the end of chapter 1: a simplified representation of a real system consisting of elements deemed relevant to the research questions. The first simplification we will make in the model is that we will not specify what is being traded. This could be foodstuffs (e.g., grain or livestock), craft products (e.g., pottery), or specialized goods (e.g., luxury items). It may come as a surprise that we would model each of these as if they were the same, since in reality they would display particularities in how they were handled by different commercial actors. However, on reflection one quickly notes that all products go through the same phases of their economic life: production, transport, distribution, consumption, and discard. By focusing on the general process rather than the specific details relevant to each product, we can create a model that is applicable to a much wider range of cases (we will discuss in detail the trade-offs it involves in ch. 3). The second simplification we make is collapsing a market with all its vendors and consumers into one entity. If we think of the buzzing marketplaces across the world’s small and big cities, this may seem unwise. Yet

Chapter 2: Complex Models of Economic Interactions considering the scale of the model, it may be appropriate to represent the entirety of commercial activity within one urban center as one entity. We can visualize this as a model in which towns and cities are traders, scale: the size of spatial units and the duration of temporal units within the modeled system. rather than particular individuals. When approaching a new model, it is important to identify the scale at which the system is represented and consistently apply that scale. This is particularly important in the first iteration of a model—one can always add more details and nuances later. Models are never a static last word but rather small steps forward in the incremental scientific process. In fact, if you want to explicitly model the system at multiple scales, a whole family of multilevel models exists to help model dynamic phenomena interacting across scales. (Hjorth et al. 2020). 2.2

Setting up the Trade Model

For our trade model1 we will need to differentiate between producers, who create products, and vendors, who distribute them to different markets. Making specific groups of agents that behave differently from one another is fairly common. You could achieve this simply by giving them a variable (an attribute) and then calling all agents with a given value of that variable. For example (no need to type it in): ask turtles with [color = pink] [ ; do something that only pink agents do ] In this code snippet, we created an agentset on the fly. Here, turtles distinguished by the variable ( color = pink ) inside a reporter block can be asked to perform particular actions. You can use any value or a range of values, e.g., turtles with [age > 30] or turtles with [energy storage * storage-threshold and any? next-tier-neighbors with [ goods < storage ]] [ set goods goods - 1 ask one-of next-tier-neighbors with [ goods < storage ] [ set goods goods + 1 ] ] end

DON’T FORGET You should have four sliders by now on the INTERFACE tab: LEVEL, PRODUCTION-LEVEL, STORAGE, and STORAGE-THRESHOLD. TEST CODE BLOCK 2.10

58

If you hit the CHECK button, you’ll get a familiar sight—the yellow warning that nothing named storage has been defined. Create a new slider and set the values to between 0 and 100 with 50 as the default. You will also need to do this for storage-threshold . This time, set the slider values to between 0 and 1 with an increment of 0.01 and a default value of 0.5. Altogether, this new code may look a bit intimidating at first, so let’s unpack it line by line. First, we define who are we going to be trading with: let next-tier-neighbors (vendors-on neighbors4) with [distance-level = [distance-level + 1] of myself]

Chapter 2: Complex Models of Economic Interactions Here, we have created a local variable next-tier-neighbors , which stores all the vendors on the neighboring patches ( vendors-on neighbors4 ) whose distance level is one step higher than the calling agent ( with [distance-level = [distance-level + 1] of myself] ). Note that the parentheses around (vendors-on neighbors4) are necessary for the order of operations to be correct: with [...] refers to the variables of the vendors rather than the patches designated by neighbors4 . The next few lines are the heart of this procedure. Let’s express it in pseudocode: While you have any goods left for sale AND if any trading partner has space left in storage: ask one of them to increase the number of goods by one and decrease your own number of goods by one Now that the flow of the logic is clear, let’s look at a few potential traps in the code. First, you might have noticed the repetition of the following line: next-tier-neighbors with [ goods < storage ] You may wonder why we haven’t just asked one of the other traders to trade with us, like this: ask one-of next-tier-neighbors [ set goods goods + 1 ] This would work most of the time. But sooner or later, one of the agents would find itself in a situation where none of their neighbors fulfilled the criteria (fewer goods than storage). What then? This is when NetLogo halts and throws a rather cryptic error message: ASK expected input to be an agent or agentset but got NOBODY instead. What this means is that in order to use the primitive ask , there must be at least one agent (i.e., not “nobody”) that can do it. If there is not one, the simulation does not know what to do and halts. To avoid this, we first check whether there is an agent who fulfills the criteria any? next-

TIP If you click on a square bracket, NetLogo highlights its counterpart. TEST PSEUDOCODE BLOCK 2.11

TEST CODE BLOCK 2.12

TEST CODE BLOCK 2.13

TEST CODE BLOCK 2.14

This algorithmic structure of first establishing that there are one or more turtles fulfilling a condition, and then asking one of them to do something is a common code structure in NetLogo. 59

PA RT I : L E A R N I N G TO WA L K

tier-neighbors with [ goods < storage ] and only then ask one of them to perform an action. We need to specify again that it has to be a next-tier-neighbors with [ goods < storage ] ; otherwise we will just trade with anyone. You will see this apparent repetition in NetLogo models again and again. LOOPING CODE SEGMENTS

TEST PSEUDOCODE BLOCK 2.15

TEST PSEUDOCODE BLOCK 2.16

TEST PSEUDOCODE BLOCK 2.17

TEST CODE BLOCK 2.18

Avoiding unnecessary operations speeds things up. For example, at the beginning of the simulation only a few agents have any goods.

60

Congratulations! This is your first time using a while loop, one of three main control flow structures used in NetLogo. Let’s take a closer look at these control flow structures. Here, again, we will turn to the handy tool of pseudocode. The structure of an if loop is the following: If condition is true: [ do x ] The structure of a while loop is the following: While condition is true: [ keep on doing x ] The structure of an ifelse loop is the following: ifelse condition is true: [ do x ] otherwise, if false: [ do y ] We will reuse the trade procedure to model exchange between vendors. Add the following line to the go procedure: ask vendors with [ goods > 0 ] [ trade ] Here we ask traders who have goods to go and sell their goods. We could have just asked all vendors ask vendors [ trade ] , but this way we avoid having empty-handed vendors perform all the trading operations for nothing. To finish off the go procedure, add a line asking vendors to display the number of goods they have using the label variable (similar to the

Chapter 2: Complex Models of Economic Interactions one in the setup ). Because the number of goods changes with each tick, we need to update the label accordingly. Also, write a line telling vendors that those who have at least one good in their storage lose an item at the end of a time step to account for accidental loss or breakage of goods; if we do not add this, the amount of goods never decreases. The full go procedure should look like this: to go ask ask ask ask ask

DON’T FORGET Add tick at the end of the go procedure. . CODE BLOCK 2.19

turtles [ set label goods ] producers [ set goods production-level ] producers [ trade ] vendors with [ goods > 0 ] [ trade ] vendors with [ goods >= 1 ] [ set goods goods - 1 ]

tick end

Explore the way in which the frequency curves change depending on the production level, the storage, and trading capacity (storage-threshold). Does it matter how far from a production center the market is located? LISTS

The simulation is mostly ready, but as you might have noticed when exploring the model with the sliders, the results are hard to interpret directly. We need some kind of output measure to see how the trends of goods change with the different scenarios. What interests us are the different amounts of market goods at various distances from the production center. The stochastic nature of the simulation means that the amount will differ from one vendor to another, but we can aggregate them to get a mean value for each distance-level . We will do this using NetLogo lists, an exceedingly useful and computationally efficient data structure. Lists help enormously when creating more complex simulations, so it really is worth spending some time to understand them. Let’s start with adding a new global variable mean-goods at the very beginning of the code. This will be the global list:

stochasticity: degree of randomness in a model’s dynamics and outcomes; involving randomly generated numbers. list: an ordered sequence of values. They can be of any type (integer, string, another list, etc.) and can repeat multiple times.

61

PA RT I : L E A R N I N G TO WA L K TEST CODE BLOCK 2.20

TEST CODE BLOCK 2.21

globals [ mean-goods ] Then we need to initialize our list in the setup procedure: set mean-goods [ 0 0 0 0 0 0 ] If you go to the INTERFACE tab, click SETUP, and write mean-goods in

The alternative way of initializing a list is: set (list x y z)

You can visualize a list as a kind of spreadsheet row in which each cell contains a value.

the Command Center, it will print your new list: [0 0 0 0 0 0] . Each value stores the mean number of goods at each particular distancelevel . So the first value will be used to store volumes from the distance-level 1 , the second from the distance-level 2 , and so on. At each time step we will calculate and add a new value to the appropriate position. Note that NetLogo lists are indexed such that the first entry is item 0 . This becomes particularly important when you try to read the value from a specific position in a list. distance 1 index 0 34.7

reporter: a type of procedure that calculates a value and reports it back. TEST CODE BLOCK 2.22

distance 2 index 1 28.98

distance 3 index 2 25.07

distance 4 index 3 15.12

distance 5 index 4 5.1

Let’s create a new type of procedure—a reporter procedure. It will calculate the volume of goods of all vendors in one distance-level , and then report a number back. Add the following code: to-report calculate-volume [ current-distance-level ] let vendors-tier vendors with [ distance-level = current-distance-level ] report mean [ goods ] of vendors-tier end You can easily spot a reporter because it starts with to-report ... , instead of to ... like in a standard procedure. You might have also noticed that we pass a variable here, current-distance-level , in the brackets after the procedure name. We use it to specify which distance-level we are calculating ( vendors with [distance-level = current-distance level] ). So when the reporter function is called to calculate the mean

62

Chapter 2: Complex Models of Economic Interactions number of goods for distance-level 1, it will pass current-distancelevel equal to 1; when calculating distance-level 2, currentdistance-level will be set to 2; and so on. We will now construct a procedure that will collect this artificia data for each distance-level by passing current-distance-level and appending the results of calculatevolume to the mean-goods list. Don’t forget to add the iteratelist-of-mean-goods procedure to go . to iterate-list-of-mean-goods let i 1 while [ i produce goods ask producers -> distribute goods (trade) ask vendors -> distribute goods over storage threshold (trade-vendors) ask vendors -> consume one item of its goods

PSEUDOCODE BLOCK 2.26 (cont.)

to populate hatch agents at neighboring cells give them a distance level to trade if any goods in your storage if any neighbors want to buy (their goods < storage) give an item to one of the neighbors remove one item from own storage This is a highly abstract model designed to investigate the dynamics of a simple trade system. Although the majority of models aim to test hypotheses related to particular patterns in the archaeological record, occasionally we build more abstract, theory-driven models. Sometimes called toy models, they are used to play with the system to better understand, for example, how a change in one aspect of the system (e.g., level of production) affects another aspect (e.g., how far the goods travel). In this case, the exact model you have just replicated (Romanowska 2018) was used to investigate the role of intermediaries in Roman trade. It was possible to show that the limited capacity of a redistribution center can play a decisive role in terms of a distribution of a particular good, even in cases where production and demand for that good are high. We will further discuss the spectrum of models from highly abstract theory-driven simulations to more realistic, data-driven ones in chapter 8.

This model also illustrates one useful way to compare abstract dynamics to highly specific archaeological data.

69

PA RT I : L E A R N I N G TO WA L K

2.5 Summary

See chapter 9 for an introduction to programming in Python and R.

In chapter 1, we introduced the most basic elements of NetLogo. Here, in chapter 2, we dove into the nitty-gritty of coding in NetLogo. We learned how using variables in a local context can be more dynamic, but that global variables are necessary when their values need to be accessed by all agents in the model. We explored loops, in particular, conditional loops, which are the main vehicle for model logic. We used breeds, which enabled us to categorize groups of agents efficiently. Finally, we introduced one of the most difficult yet important methods in NetLogo— lists—which enable a much swifter and easier manipulation of code. In the process, we used several common primitives and further cemented our familiarity with the NetLogo dictionary. This may have been a lot to take in, but, on the plus side, we covered all the most important elements of NetLogo syntax. The foundations have been laid, and in theory you now have the ability to create any model, even if in practice this may require honing these new skills a little bit more. Moreover, loops, lists, variables, etc. are coding elements common to all programming languages, and you will come across them regardless of whether you continue with NetLogo or move on to a general-purpose language such as Python, R, or Java. In the next chapter, you will see these common coding elements combined in more complex structures, but in principle you will have seen nearly all of it before. In this chapter we employed pseudocode, showing its many uses during model development; it’s also a useful tool to guide you in communicating models to your peers. As you develop your code, you will want to ask friends and colleagues to check your work. Pseudocode can be instrumental in facilitating this. Finally, we explored different strategies used to squash bugs in the code and get the code to work the way we want it to. Practice makes perfect, so the more opportunities you have to write code, the easier it will become. E End-of-Chapter Exercises 1. If you set the level slider at more than 6, you will get an error. Can you figure out why and change the code so that it incorporates any

70

Chapter 2: Complex Models of Economic Interactions number of distance levels? Check out the n-values primitive, which creates a list composed of a specified number of elements. 2. Add a second production center. This may be by changing one of the existing vendors to a producer or by repeating the setup procedures to create two producers and two overlapping concentric sets of markets. 3. At the moment, markets remove one good at each time step to account for a general loss from breakage and the like. We can use this code to represent consumption instead. Change the number of consumed goods into a user-defined value and explore how the results change. Then, in a second iteration, make the number of consumed goods market-specific, so that some markets representing large cities consume more goods than others. 4. Can you think of other ways in which we could measure the economic activity in the model? The total number of goods, number of transactions, amount of archaeological material being generated at each step, etc. are just a few options. Think about what would be a meaningful measure and how to implement it. Further Reading ▷ T. Brughmans and J. Poblome. 2016. “Roman Bazaar or Market Economy? Explaining Tableware Distributions in the Roman East through Computational Modelling.” Antiquity 90 (350): 393– 408. doi:10.15184/aqy.2016.35 ▷ A. Chliaoutakis and G. Chalkiadakis. 2020. “An Agent-Based Model for Simulating Inter-Settlement Trade in Past Societies.” Journal of Artificial Societi and Social Simulation 23 (3): 10. doi:10.18564/jasss.4341 ▷ S. Graham and S. Weingart. 2015. “The Equifinality of Archaeological Networks: An Agent-Based Exploratory Lab Approach.” Journal of Archaeological Method and Theory 22, no. 1 (December): 248–274. doi:10.1007/s10816-014-9230-y

71

PA RT I : L E A R N I N G TO WA L K

▷ L. Hamill and N. Gilbert. 2016. Agent-Based Modelling in Economics. Chichester, UK: Wiley. doi:10.1002/9781118945520 ▷ I. Romanowska et al. 2021. “A Study of the Centuries-Long Reliance on Local Ceramics in Jerash Through Full Quantification and Simulation.” Journal of Archaeological Method and Theory (February). doi:10.1007/s10816-021-09510-0 ▷ I. Romanowska. 2018. “Using Agent-Based Modelling to Infer Economic Processes in the Past.” In Quantifying Ancient Economi . Problems and Methodologi , edited by J. R. Rodriguez, V. R. Calvo, and J. M. Bermudez Lorenzo, 107–118. Instrumenta 60. Barcelona, Spain: University of Barcelona.

72

N OT E S

3 REAPING THE REWARDS: ADDRESSING ARCHAEOLOGICAL QUESTIONS

3.0

Introduction

In the previous chapter, you mastered the foundations of computer programming: lists, loops, variables, etc. Proficiency in coding is a challenging but necessary aspect of computational modeling, as it enables a swifter and easier manipulation of the models you write in NetLogo or any other programming language. The skills you develop in NetLogo syntax and the knowledge of primitives add a level of dynamism in representing agents and their environment. Similarly, writing elegant code that does not repeat commands or have unnecessary redundancies facilitates the subsequent steps of the modeling process. The skills you are building will enable you, as a modeler, to approach more difficult concepts and ask more complicated questions. Most of the agent-based models that approach complicated questions require these more advanced programming techniques. Modeling subsistence requires some of the concepts we dealt with in the first two chapters— movement to find a resource patch and exchange code to gather it—but also quite a lot of accounting code to sort through all the rates, amounts, and transactions. As usual, we will start with a basic model, and then build up to discuss the programming concepts in more detail. The goal is to replicate the SugarScape model, which you can then take further toward the full Artificial Anasazi simulation. As opposed to the first two chapters, here we will not introduce many new coding concepts. Instead we will make the code more complex, with loops within loops, lists within lists, etc. In addition, we will give you most of the necessary code but also leave some small coding decisions to you. By the end of this chapter, you should have all the fundamental building blocks of NetLogo code well in hand. We will also touch upon a critical modeling phase: validation. We looked at verifi ation (debugging) in chapter 2. This focused on remov-

OVERVIEW ▷ Tutorial in advanced NetLogo: complex structures ▷ Definitions of parameterization, artificial data, validation, and equifinality ▷ Simulating archaeological record and validation against data ▷ Writing efficient code

Since NetLogo is a language, the building blocks include the vocabulary (primitives), grammar (syntax), and conceptual logic.

validation: establishing that the model is conceptually correct with respect to the system being modeled.

75

PA RT I : L E A R N I N G TO WA L K

ing mistakes in the code. In contrast, the validation phase is designed to demonstrate that your model is a reasonably accurate representation of reality. You need to get this phase right so that the model can serve its intended purpose. There is much discussion within the modeling community about how to facilitate validation, avoid potential pitfalls, and determine the minimum requirements to ensure that the results produced by the model can be used to infer the dynamics of the real-world system (e.g., Arifin and Madey 2015). Without doubt you will recognize this challenge when building your own models. 3.1 The Model: SugarScape & Artificial Anasazi

The Ancestral Puebloans were referred to as the Anasazi until the 1980s. However, “Anasazi” is considered disrespectful by living Pueblo people, so the term has been changed.

76

Perhaps one of the longest-running and most hotly debated questions in North American archaeology centers around why the Ancestral Pueblo people chose to abandon their homelands in the late AD 1200s. Given the complexity of their societal structures, relations with their neighbors, and interactions with the constantly shifting environment, it clearly merited a formal model for investigation. Two families of models have examined the questions surrounding the depopulation of the Ancestral Puebloan settlements in the US Southwest: the Artificial Anasazi model led by Axtell (Axtell et al. 2002; Dean et al. 2000), later reproduced by multiple independent labs (Janssen 2009; Stonedahl and Wilensky 2010), and the Village Ecodynamics Project led by Kohler (Crabtree et al. 2017; Kohler and Varien 2012). To briefly sum up the main points, the Ancestral Pueblo people migrated into the northern part of the American Southwest (areas of northern Arizona, southern Utah, and southwestern Colorado) in the early sixth and seventh centuries AD, settling as maize farmers in the region. After seven centuries of successful farming, they abandoned the region and moved to New Mexico in the late thirteenth century, leaving behind much of their material culture. Throughout their occupation, regular episodes of drought beset the farmers in these regions (Bocinsky and Kohler 2014; Kintigh and Ingram 2018) as well as periodic incidents of violence (Kohler et al. 2014; Kohler, Cole, and Ciupe 2009; Kuckelman 2010), yet they continued to inhabit the region. So what, in the end, made them all decide to leave?

Chapter 3: Addressing Archaeological Questions Solving this question requires looking at the full historical trajectory of Ancestral Puebloans within the region, which is why the teams of Axtell and Kohler independently turned to agent-based modeling. In chapter 8, we will reimplement one of the published models from the Village Ecodynamics Project, originally written in Java and translated to NetLogo. In this chapter, however, we will focus on Artificial Anasazi, replicated in NetLogo by Janssen (2009). It will allow us to explore how building complexity on top of a simple base model can generate new understanding. Artificial Anasazi is built on a simple resource extraction model: the SugarScape model (Epstein and Axtell 1996). It has agents moving about a landscape with resources distributed across patches and attempting to collect and metabolize as much “sugar” as they can. Dean et al. (2000) set out to test a hypothesis that environmental variability led to the abandonment of Long House Valley, Arizona. They wanted to assess how much of the historical trajectory of this society was due to the climatic changes that affected the valley. To investigate this, they combined a model of environmental variability with an expanded version of the SugarScape model. Agents in Artificial Anasazi represent maize-farming households that move across the landscape, constantly looking for the most productive locations to farm. Households grow due to reproductive capacity related to farming productivity, but if they cannot grow sufficient amounts of maize, they die. Climate fluctuation over the simulated period of 500 years changes the amount of resources that agents can gather. If the model showed that Ancestral Puebloans struggled to make a living during the thirteenth century, then the environmental variability hypothesis would be supported as plausible. Otherwise, it would have to be rejected. And so it was. The simulation was instrumental in demonstrating that environmental variability alone cannot explain the depopulation of this region in the fourteenth century. At the same time, it showed that a computer model can capture the dynamics of an ancient population. With a bit of tuning of the model parameters, Artificial Anasazi produced an in silico archaeological record similar to the one created by the people who inhabited Long House Valley over half a millennium ago.

It is very common to build an ABM of a particular case study upon an existing more general model.

Environmental change is often a first go-to narrative explanation for cultural change. However, human complex systems are rarely that simple, and other factors need to be considered.

77

PA RT I : L E A R N I N G TO WA L K

3.2 First Steps in Subsistence & Model Accounting The first step in any subsistence model is to decide on the characteristics of a resource landscape. We already touched on the issue of how agents assess patch variables and how they pass data between one another. In this chapter, we will focus on the nature of that agent–environment interaction in more detail. Previously, patches were passive entities holding variables and having them read by agents (e.g., agents checking pcolor in chapter 1). But a patch is really an agent itself, just an immovable one, and we can give patches agency when needed. So an agent consuming a resource from a patch is a specific case of an agent–agent trade similar to the one we developed in the previous chapter; a resource is passed from the patch to the agent, and the variables of each are updated accordingly. Subsistence, though, includes a combination of patch and agent procedures including regrowth rates, gathering rates, heterogeneous resource landscapes, search algorithms for finding the best source of resources, and even population dynamics that stem from having either insufficient or a surplus of food. The simplest way is to start with a homogeneous landscape, but all sorts of interesting things can happen when we introduce spatially variable resources including randomly scattered patches, gradients, and shaped “hills.” Our basic subsistence model here will include procedures for gathering, plant regrowth, consumption of minimal stored resources, and searching for new plots. Agents will each be a small forager group, and each time step of the model will be a month. Begin by creating a new model1 and write code for the details listed below without looking ahead to the upcoming code block:

Model: Archaeological SugarScape . ABMA Code Repo: ch2_sugar_basic

DON’T FORGET Remember to include clear-all and reset-ticks in setup , and tick in go . We will take a closer look at landscapes in chapter 7.

random-pxcor and random-pycor are shortcut primitives that look at the size of your landscape and return a randomized coordinate within that range. moveto one-of patches would also work.

• go and setup procedures and their buttons. • Add a third button named step , where the command is also go but the FOREVER box is unchecked. This allows us to slowly step through the model tick by tick. • Create a forager breed and a number-foragers slider on the INTERFACE.

1

78

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch3

Chapter 3: Addressing Archaeological Questions • Write code in the setup to create those foragers, give them a shape, scatter them randomly across the landscape, and create a storage variable initialized to 0. • Add a resources variable for patches in patches-own . • Put code in setup to give patches a base resources value of 10 and pcolor them green. Your code should resemble something like this: breed [foragers forager] globals [ ] patches-own [ resources ] foragers-own [ storage ] to setup ca ask patches [ set resources 10 set pcolor green ]

TEST CODE BLOCK 3.0

TEST

If you get an error, make sure you created a storage variable for the forager agents (i.e., in foragers-own [ ] ). TEST A few key primitives have short forms, e.g., ca is short for clear-all .

create-foragers number-foragers [ set shape "house" set storage 0 setxy random-pxcor random-pycor ] reset-ticks end to go tick end We want our forager agents to be able to gather resources from their land, and since these are semi-sedentary foragers, they will store a little

79

PA RT I : L E A R N I N G TO WA L K

bit of their resources. With each time step, ask foragers to run a new . CODE BLOCK 3.1

Complex models require a lot of testing. A method for this type of issue is to check whether the total amount of resources in the world remains the same. TEST CODE BLOCK 3.2

DON’T FORGET Make sure to add the eat procedure to the go .

80

gather procedure, and write out that procedure like this: to gather set storage storage + [resources] of patch-here end While this is a good start, we have already made an error in our accounting. While the forager now has resources, we did not remove them from the environment. Think of this like an exchange from the patch to the forager’s storage. We could just set the patch to zero, but then we might lose track of how many resources were gathered. Instead, we will make sure to account for the correct resource amount by using a local variable: to gather let current-gather [resources] of patch-here ask patch-here [ set resources resources current-gather ] set storage storage + current-gather end The foragers do well in month one, but since they gather all the resources, there is nothing left for month two. In real life, however, there is a limit to how much a single person can deplete a patch of land. Foragers also need to eat, so after gathering they should consume some resources. Finally, with all of these dynamic changes it would be good to visualize the impact on the landscape, so we will develop a procedure to update our map’s color scheme. Add two sliders to the INTERFACE tab: one for gather-rate (values 0 to 10) and one for consumption-rate (values 0 to 10). These are stand-in values for our sliders that enable us to build a working simulation. Sometimes we have empirical values—for example, we know how much people consumed and gathered (i.e., we can parameterize the model). For now, though, we will use these stand-in values to enable swift code building and to verify that the model is functioning correctly. Move to the CODE tab, and add the code block below that makes the foragers eat a particular amount from their stores each month.

Chapter 3: Addressing Archaeological Questions To keep our accounting in order, we also need to make sure agents do not eat more than they have in storage nor do they gather more than there is in the patch. to eat ifelse storage >= consumption-rate [ set storage storage - consumption-rate ][ set storage 0 ] end Remember that the ifelse loop has a structure of: if condition is true [ do something ] else [ do something else ] In our case, if the consumption-rate (number of resource units consumed by the household per time step) is equal to or larger than the available resources storage , then that amount is consumed (i.e., it disappears from the storage). Otherwise the storage is set to zero because all that is left has been eaten. We will need to adjust the gather procedure in a similar fashion so that the foragers do not gather more resources than are available on the patch. to gather let current-gather 0 ifelse [resources] of patch-here < gather-rate [ set current-gather [resources] of patch-here ][ set current-gather gather-rate ] ask patch-here [ set resources resources - current-gather ] set storage storage + current-gather end

TEST CODE BLOCK 3.3

TEST PSEUDOCODE BLOCK 3.4

TEST CODE BLOCK 3.5

81

PA RT I : L E A R N I N G TO WA L K

Here, we have defined a local variable current-gather and temporarily set its value to 0. If there are not enough resources, then agents can only get what is available ( [resources] of patch-here ); otherwise the forager can gather the maximum amount possible (i.e., the gatherrate ). Finally, let’s ensure that we can observe the dynamics of the simulation: how foragers gather and consume resources. Before reading the code below, go to the NetLogo Dictionary and look at the syntax for the scale-color primitive. You can use it to color the patches depending on their resource level. Write a procedure, to update-display , in which patches set their color depending on their level of resources and foragers change color if their storage is empty. Your code should resemble this code block:

TIP Get to the Dictionary quickly by placing your cursor on a primitive and pressing F1. . CODE BLOCK 3.6

to update-display let max-color max [resources] of patches * 2 ask patches [ set pcolor scale-color green resources 0 max-color ] ask foragers [ ifelse storage > 0 [ set color blue ][ set color red ] ] end Note that we adjusted the max-color ( * 2 ) just for aesthetics so that full patches would be green instead of white. Look at the Colors section of the NetLogo Programming Guide.2 Add update-display to the end of setup right before resetticks , then add all the procedures we have just written inside go (including update-display ). By now it should look like this:

You can also find the color swatches in the TOOLS menu.

2

82

https://ccl.northwestern.edu/netlogo/docs/programming.html

Chapter 3: Addressing Archaeological Questions TEST

to go ask foragers [ gather eat ]

CODE BLOCK 3.7

update-display tick end Now you can run your model with the sliders set to different amounts, and everything should work. If your gather-rate is equal to or lower than your consumption-rate , then your foragers will be in the red. Use the STEP button we created earlier to tick through a few time steps of the model and inspect one of the agents. After a few ticks, the foragers go red when their patch runs out of resources (fig. 3.0). At that point, the foragers should have a move procedure to transport them to a fresh patch. Also, patches should regrow their resources at a steady rate; otherwise the whole world will soon be depleted, and all the foragers will go red. Let’s begin with the move procedure. First, we want foragers to check whether their patch has enough resources to feed them. If not, they need to choose another patch that has no foragers on it and at least enough resources to fulfill the forager’s consumption rate. Try writing the code yourself and then check with the following: to move if [resources] of patch-here < consumption-rate [ let p one-of patches with [not any? foragers-here and resources >= consumption-rate] if p != nobody [move-to p] ] end Notice the if p != nobody . The local variable p is a randomly chosen patch (as we used the primitive one-of ) from among those that are unoccupied and have enough resources. The if p != nobody ensures that

TEST CODE BLOCK 3.8

TEST Be careful with if p != nobody as it will not catch empty patchsets. NetLogo understands empty patchsets as (agentset, 0 patches) instead of nobody .

83

PA RT I : L E A R N I N G TO WA L K

Figure 3.0. Forager agents have depleted their patch (shown here as black cells) compared to the surrounding unexploited patches. Using “update-display” will show the foragers that have depleted their stores in a darker shade.

such a patch exists (is not equal != to nobody ). Recall that in the previous chapter we used if any? patches with [...][do ...]. These two methods are nearly equivalent, but note that you need the one-of to make sure p is a single patch. Finally, write a simple procedure in which patches regrow their resources and add it to the go code. TEST CODE BLOCK 3.9

You might start with something that looks like this: to regrow-patches set resources 10 end Here, the patches undergo instant regrowth, meaning there is no incentive for the foragers to move because food is always available. Even though they consume resources, the patches replenish each month, so foragers stay where they are. This is not very realistic for most resources, so we will change the plant regrowth to be more gradual. Add a growth-rate rate slider (values 0 to 10) and change regrow-patches to this:

84

Chapter 3: Addressing Archaeological Questions TEST

to regrow-patches set resources resources + growth-rate end Running this model, initially the foragers quickly exhaust the resources (displayed as darker shades of green) of their patches and move to another patch (use the STEP button, or set the model speed much slower than normal to see). However, over time the foragers will move less and less frequently. Why is that? Inspect one of the green patches by right-clicking on it. The value of the resources variable is much higher than expected, isn’t it? In our setup , we gave each patch a resource starting value of 10, but nothing in the model is limiting how many resources there can be on a single patch. Again, we have forgotten to control our accounting. Create a max-plants slider (values 1–100) in the INTERFACE tab and change regrow-patches so that it only regrows the resources if they are below the maximum value, that is, the max-plants : to regrow-patches if resources < max-plants [ set resources resources + growth-rate ] end The go procedure should now look like: to go ask foragers [ gather eat move ]

CODE BLOCK 3.10

TEST

DON’T FORGET Add move to the ask turtles and regrow-patches to ask patches in the go procedure.

This is the normal iterative process of model building: add a component, check it, find bug, fix bug, move on. TEST CODE BLOCK 3.11

TEST CODE BLOCK 3.12

ask patches [ regrow-patches ]

85

PA RT I : L E A R N I N G TO WA L K

Figure 3.1. After a few steps, the agents have moved on to new patches several times, leaving the previously occupied patches at various stages of regrowth (darker patches). The sliders are set to sustainable levels and the foragers remain fed, indicated by houses in a lighter shade. TEST CODE BLOCK 3.12 (cont.)

update-display tick end You may also adjust the color scheme by changing the first line in updatedisplay to let max-color max-plants * 2 .

Adjusting these parameter values and running the model repeatedly is a good way to verify that the model is logically sound and that you understand its dynamics.

Toy landscapes are simple landscapes with carefully controlled characteristics designed to help us understand a model’s functioning (see ch. 7).

86

At this point you can let the model run while manipulating the values in the sliders: growth-rate , consumption-rate , gather-rate , max-plants , and number-foragers (fig. 3.1). Intuitively, consumption-rate must be equal to or less than gather-rate for the foragers to not go hungry (red). It is perhaps less easy to predict the growth-rate value, relative to the other sliders, that will keep the landscape healthy or how many foragers are sustainable for a given value. You may also add a line of code so that if their storage value stays at 0 for a prescribed time, such as three or four months, the agent has to die . A TOY LANDSCAPE

For the last section of code we will redesign the resource landscape. Rather than import a map like in chapter 1, we are going to make a toy landscape with two resource “hills” using this code block:

Chapter 3: Addressing Archaeological Questions TEST

to make-hills let hills (patch-set patch (max-pxcor * 0.33) (max-pycor * 0.33) patch (max-pxcor * 0.67) (max-pycor * 0.67)) ask patches [ let dist distance min-one-of hills [distance myself] set resources max-plants - (dist / (max-pxcor * 0.75) * max-plants) set max-resources resources ] end

CODE BLOCK 3.13

The first line defines the centers of two high resource hills. The second part asks patches to first measure their distance from the nearest peak and then to convert that distance measurement into a resource value (similar to ch. 2 when we set the distance-level ). The last part, set maxresources resources , sets the regrowth maximum for each patch so that it cannot grow beyond that patch’s capacity. Think of this as the maximum level of resources, similar to max-plants , but specific to each particular patch. Now we have to adjust the rest of the code to this new function. First, add a switch to the INTERFACE called hills? . INTERFACE switches create global variables with only two possible values: true and false . Next, take the old patches setup procedure ( ask patches... ) from the setup and move it to a new procedure to make-plain and modify it

TIP If you get an error, check your parentheses and square brackets. They are necessary for NetLogo to match input values with each primitive.

to reflect our new patches-own variable, so that it looks like this:

TEST

to make-plain ask patches [ set resources max-plants set max-resources max-plants ] end

DON’T FORGET Got the “Nothing named . . .” error? Did you add max-resources to patches-own ?

CODE BLOCK 3.14

TEST Change the location of the origin of the world to the bottom left corner in SETTINGS.

87

PA RT I : L E A R N I N G TO WA L K TEST CODE BLOCK 3.15

TEST TIP Naming switch variables with a question mark is common NetLogo practice to keep track of the logic.

Then add the following code to the setup : ifelse hills? [ make-hills ][ make-plain ] You could keep the make-plain code in the setup , but by writing it as a separate procedure you make the code more readable, facilitate debugging, and can efficiently profile it later (i.e., check how fast it runs; we will work on this in ch. 7). Finally, change regrow-patches such that resources grow not to the global variable max-plants but to the patch variable max-resources . This ensures that the landscape is maintained throughout the run, and the regrow-patches procedure will not turn the hills back into a homogeneous plain. Move the slider to see how different resource values change the landscape of resources in the model. If the hills? switch is off, the model should perform the same as before, but what’s different about the agent behavior if hills? is on? How do the foragers respond depending on their consumption-rate and gather-rate ? 3.3 Validation: Is my Model “Right”?

You’ll find several SugarScape extensions in the NetLogo Models Library.

88

The model you just wrote constitutes the basic version of the SugarScape model (Epstein and Axtell 1996). This model is very simple, yet it was used to explore complex aspects of social evolution, such as the formation of wealth inequality in societies. Its ability to explain complex phenomena with a simple set of rules is shared by a number of classic agent-based models: the aforementioned Boids (Reynolds 1987) and the Segregation model by Schelling (1969) and Sakoda (1971) that demonstrated how moderate prejudice leads to strongly segregated neighborhoods. So how do simple models like these allow us to study highly complex social phenomena? And how much can we trust them? In the end, foragers don’t live on “hills” of resources, and they engage in many activities other than foraging. Notice that while designing and coding the simulation we made a number of decisions: we set the scale of the simulation, decided to use agents to represent forager groups, gave those groups the ability to gather resources, assumed no group would trade with any other, etc. Now, how can we assess whether these decisions are correct? Can we prove that our model represents the reality of a past society and be used to study its dynamics? As we

Chapter 3: Addressing Archaeological Questions mentioned briefly in chapter 1, the simple answer is “No.” It is not possible to formally prove that a given model is the best possible representation of the system—this is known as the equifinality principle (Premo 2010). In simple terms, it is never possible to assure beyond any doubt that another model would not be a better representation of the reality than the current one. This is not a limitation particular to agent-based modeling, or even simulation in general, but a result of the fundamental characteristics of inductive reasoning, also known as the underdetermination of scientific theory (Stanford 2017). Indeed, most archaeologists should be familiar with this principle from trying to interpret archaeological data. However, it is definitively possible to say that a given model is not correct (i.e., to reject a hypothesis), that it is possible (i.e., confirm its plausibility), or that it matches data better than another one (i.e., ranking hypotheses). To achieve that, we use a process known as validation. It is a fundamental element of almost all simulations, so we will spend some time explaining different validation techniques in chapter 3, as well as an arsenal of closely related methods such as calibration, sensitivity analysis, and model selection in chapter 4. For now it will suffice to define validation and work through an example of how it can be applied. Validation refers to the phase of the modeling process when the output of a model (so-called artificial data) is compared to real-world data. In our case, this usually refers to comparing the model’s prediction to the archaeological record. If the two match, we can state that the model is a plausible hypothesis regarding the system we study (e.g., out-of-Africa dispersal, Roman trade, or foraging societies). If they do not match, however, we can reject the model as an impossible or unlikely scenario of how things were in the past. As you can imagine, this is usually not as straightforward as it seems, and decisions need to be made regarding such issues as: What do we compare to what? How similar do they need to be to one another to be deemed “well matching?” And does the model match the data within a realistic range of parameter values? “Well matching” may be quite abstract while still being useful. In programming this chapter’s model, we have been using arbitrary values like 10 or 100 for our parameters, rather than carefully selected values derived from, for example, present-day foraging societies or historical sources. This is like excavating by arbitrary 10 cm levels rather than by stratigraphic levels. Both allow you to move forward in a controlled fashion but must be

equifinality: multiple past processes could equally have led to the same final archaeological pattern; note, though, that not all are equally likely. This also explains why “correlation does not imply causation.” Underdetermination of scientific theory is a complex idea, but the Stanford Encyclopedia of Philosophy explains well its many facets.

arbitrary values: setting a model’s variables not to real-world values but to numbers that reflect ratios between the variables: e.g., X is double Y , X = 10 if Y = 100.

89

PA RT I : L E A R N I N G TO WA L K

parameter: a constant used to describe the modeled world and a particular scenario, such as initial number of agents, population growth rate, or carrying capacity of a patch.

We will explore the trade-off between realism, precision, generalism, and tractability, i.e., the ability to describe the causality in the model, in ch. 8.

analyzed slightly differently. In agent-based modeling, choosing arbitrary values allows us to verify that the model design functions as intended without getting stuck validating every parameter value. Parameterization is usually a much later stage of the research project (Romanowska 2015b), and we will talk about it in detail in chapter 6. Using arbitrary values lets you experiment with how the relative values (i.e., ratios) between parameters affect your model’s dynamics. How does our foraging model change if the resources’ regrowth rate is higher or lower than the consumption rate? What if we run simulations with our population size set to 5%, 25%, or 50% of the patch count, thereby increasing our population density? Understanding the interactions and causality chains between model’s entities is critical if you do not want to produce a “black box.” SugarScape was entirely built using arbitrary values, such as its 50 × 50 grid of cells with 400 agents, and a per-time-step metabolism of 1 to 4. However, by looking at the ratios, the modelers were able to demonstrate that the uneven wealth distribution of their agents matched well-known economics principles like the Lorenz curve and Gini ratio (Epstein and Axtell 1996). In the next section, we will create an output from our model so that we can validate it against the archaeological record; this is where we build upon the simple SugarScape model to recreate some key parts of Artificial Anasazi. In the process we will make the model more complex and experiment with modeling concepts such as lists and reporters. 3.4 Simulating the Creation of an Archaeological Record

ABMA Code Repo:

ch2_sugar_archrec

90

As we discussed above, to validate the model against the archaeological record, we need to create some model outputs that can be compared to it. In chapter 1, we compared the order of arrival of the wave of dispersal in different continents against the dates of archaeological sites, while in chapter 2 we looked at the change in the frequency distribution of pottery at different archaeological sites. In this chapter, we focus on the interaction between humans and their landscape, making the spatial distributions the most appropriate dimension to compare to a real archaeological record. We will record the occupation of a patch as the number of time steps a forager stays on it; one time step is one unit. What that unit represents does not matter right now, since we are interested in a relative frequency of occupa-

Chapter 3: Addressing Archaeological Questions tion of all sites over the duration of the simulation. Although we are only counting the foraging group’s presence or absence, we are assuming that the occupation is correlated with duration and therefore the density of objects left behind (mimicking the creation of the archaeological record; see Varien and Mills 1997). Create a new record-occupation procedure to update a new variable occupation-frequency , which will act as a rolling counter of where agents have spent their time. Your code should look like this: to record-occupation set occupation-frequency occupation-frequency + 1 end

Should occupationfrequency be added to ( globals ), ( patchesown ), or ( foragersown )? Not sure? Try each and see what happens. TEST CODE BLOCK 3.16

You may be surprised that it is the foragers that set occupationfrequency even though it is a patch variable. This works because NetLogo understands that agents are only talking to patch-here , that is, the patch they are currently standing on. Likewise, in the code sections above where we wrote [resources] of patch-here , we could have just written resources . This would be cleaner code, but we wrote it in longer form to make sure the accounting was easy to follow. We will also duplicate and then modify the update-display code to visualize our results. to update-display-occupation let max-color max [occupation-frequency] of patches ask patches [set pcolor scale-color red occupation-frequency 0 max-color] ask foragers [set hidden? true] end Since we are interested in the long-term results of the simulation (its archaeological record) and not individual foragers, we told the foragers to “disappear” from the view using the built-in turtle primitive hidden? (fig. 3.2). We can call this procedure at the end of the run or create a button in the INTERFACE. How does the occupation map compare to the two different resource landscapes on the short term versus after a long run of the simulation? Would it be different if instead the occupation was record-

Call record-occupation from the ask foragers part of go , after the move procedure.

TEST CODE BLOCK 3.17

TEST

TIP It’s common to duplicate and rename code to use it for a slightly different task. What would happen if you didn’t change the name of the duplicate procedure?

91

PA RT I : L E A R N I N G TO WA L K

Figure 3.2. Simulated archaeological record on the hills landscape with more occupation as darker shades close to the peaks of the hills. Note that forager agents are set to “hidden? true.”

ed only during certain activities? There are many GIS techniques we could use to compare this occupation frequency map to the spatial distribution of archaeological material in our study area, some of which we will describe in chapter 7.

TIP Lists are computationally “cheap,” making your simulation faster than if you used a lot of variables.

data structure: the format and organization of variables and parameters. Common data structures in NetLogo are integers, floats (decimal numbers), strings, Booleans (true/false), lists, agents, and agentsets.

92

DY N A M I C L I ST S & T H E I R M A N I P U L AT I O N

Thus far, we have avoided using lists in this simulation, though recall we introduced lists in the previous chapter. One way of avoiding lists is to make more variables. For example, if our foragers wanted to gather three edible species instead of just one, we could have resourceA, resourceB, and resourceC as patch variables. But what if we are not sure how many resources we need, or if the number of resources will vary during the simulation? It would not scale either if there were 1, 000 resource types. When we need to hold only one piece of information, simple variables are the best option. But if we need to keep track of a lot of information, especially if of unknown quantity, lists are a more flexible approach. Let’s give each forager the option of gathering multiple resources. What we are doing here is switching data structures from a single numerical value to a list, and that tends to cause a cascade of necessary changes to our code. It is common to change the underlying architecture of the model

Chapter 3: Addressing Archaeological Questions as you develop the code, but it is also a major source of code errors, so it is worth paying attention. We can actually reuse the variable names patches-own [resources max-resources] of the existing model because in the declaration of a new variable (e.g., in the turtles-own ), NetLogo does not care what data structure it will end up being (e.g., integer, list, etc.). NetLogo will care that the procedures that act upon the variable receive the correct data type. Since NetLogo has a good syntax-checking debugger, we can run the model and let the debugger find all the errors that we introduced. Find the first place we assign a value to that variable, change that, and then try to run the model again. Repeat until all errors have been found. The declaration of the resources and max-resources occurs first in setup ’s make-plain procedure: set resources max-plants set max-resources resources We will replace max-plants with code initiating a list. In chapter 2, we did this once by just writing out set mean-goods [ 0 0 0 0 0 0 ] to make a six-item list, and then again using replace-item to dynamically replace items as needed. Here we will first make a num-resources slider (values 1–10) in the INTERFACE tab, and then use the NetLogo primitive n-values : set resources n-values num-resources [ max-plants ] set max-resources max resources n-values creates a list containing the value of [max-plants] repeated the number of times given by num-resources . Notice also that the second line has max added, since now resources is a list and we still want a single number to be attached to max-resources (i.e., the maximum value in that list). In the INTERFACE, try to set up and run your model. Creating the agents goes fine, but update-display gets an error because it is trying to scale-color against a list instead of the expected single number. We will shift our display to represent the total among all resource types by using sum resources to add the values of the list together. We will also change max-color to scale properly with multiple resources:

Admittedly, this is a bit of a hacky way of developing our code, and ideally all this would have been thought out in advance. But you should not be afraid of the yellow error bar, so hack away and fix bugs as you go. TEST CODE BLOCK 3.18

TEST CODE BLOCK 3.19

TIP NetLogo Dictionary specifies which data structure the primitive accepts, e.g., hatch .

93

PA RT I : L E A R N I N G TO WA L K TEST CODE BLOCK 3.20

If you try to pass the wrong data structure to a primitive, you’ll get the error “primitive x expected input to be . . .”

TEST CODE BLOCK 3.21

Recall that the NetLogo list index starts from 0.

94

let max-color max-plants * 2 * num-resources ask patches [ set pcolor scale-color green sum resources 0 max-color ] setup should work without error now, assuming hills? is false. However, when we run the model we quickly find that gather , eat , and move all need to be updated. For gather , we need to think about the logic of having multiple resources available to a forager. Can you gather them all at once? Is there a cost to switching? Do we choose some to gather before others? To keep it simple, we’ll assume that our list is in order of preference, and you can gather one resource type per time step. If there is not enough of the first type, the forager will gather the second, and so on. Update the gather procedure so that it looks like this: to gather let current-gather 0 ifelse max [ resources ] of patch-here < gather-rate [ set current-gather max [resources] of patch-here let i position current-gather [resources] of patch-here ask patch-here [ set resources replace-item i resources 0 ] ][ let resources-available map [ x -> x >= gather-rate ] resources let i position true resources-available set current-gather gather-rate ask patch-here [ set resources replace-item i resources (item i resources - current-gather) ] ] set storage storage + current-gather end Most of this code should be understandable. For example, max in front of [resources] returns a single number, i.e., the highest value in

Chapter 3: Addressing Archaeological Questions the list, which makes the comparison to gather-rate possible. In the ifelse loop, the “if true” part uses the primitive position , which searches for a value, in this case current-gather , and returns its position in the list (the index). We then ask the forager’s patch to update its resources list at that position, to show it has been gathered, using replace-item . We are assuming an agent can only gather one resource type at a time. The below shows the steps of an agent gathering from a hypothetical patch with five resource types when gather-rate is set TEST

to 7: ;initial state of a partially consumed patch with 5 resource types [resources] of patch-here: [1 6 6 6 6] ;set current-gather to most that can be gathered here current-gather: 6 ;position of first current-gather value in list i: 1 ;final state after gathering [resources] of patch-here: [1 0 6 6 6]

TEST PSEUDOCODE BLOCK 3.22

The “else” part of the ifelse statement is a bit more complex. For this, we already know that one of the resources in our list is enough to satisfy our gather-rate , using max , but we are not sure in which position in the list that resource is, so we are going to check each position on the list using the map primitive, where true means “yes, there is enough” and false means “no, there is not enough.” The command map includes what NetLogo calls the anonymous procedure -> . Anonymous procedures apply a function to each item in the list one by one while collecting the results into a new list. Here, we are going through the list resources and asking for each item x , “Is x greater than or equal to gather-rate ?” The answer is either “true” or “false” for each item. The resulting list resources-available is a sequence of true and false values, for example, [true true false...] . In short, you can read this line as “create a list called resources-available that has true for each item x from a resources list greater than gather-rate or false otherwise.”

For Python coders: This is the same as a lambda function.

TIP If you feel lost, print out the values at each step, as if you were debugging (see ch. 2).

95

PA RT I : L E A R N I N G TO WA L K

TEST PSEUDOCODE BLOCK 3.23

Next, we record in a temporary variable i the position along the resources-available list where the first true appears. We then ask patch-here to subtract that amount of gather from the item of the list with index i . Remember that lists are immutable, so we have to set a new list made up of the old one after we adjust it using replace-item like in the lists in chapter 2. Again, we show the output of each step for an agent gathering a hypothetical patch, though this time there must be enough resources to satisfy the gather-rate of 7: ;initial state of a partially consumed patch with 5 resource types [resources] of patch-here: [5 4 4 10 10] ;after map compares to gather-rate of 7 resources-available: [false false false true true] ;position of first true in list i: 3 ;after taking gather-rate from position i [resources] of patch-here: [5 4 4 3 10] The next changes will be much easier. Run the model again so that the debugger shows you where the next problem is. You can use the max primitive to adjust move . Simply write max before each instance of resources . To update regrow-patches we can use map again,

TEST CODE BLOCK 3.24

Notice that ifelsevalue doesn’t require you to add set as you would in a regular ifelse command block.

96

though we will also put the ifelse into the function part of map : to regrow-patches set resources map [ x -> ifelse-value (x < max-resources) [x + growth-rate] [x] ] resources end Here we update the resource list by mapping a function to each value. But contrary to the previous code block, we use the ifelse-value primitive. This works just like the regular ifelse except that the two parameters after the conditional statement are reporters and not commands like with a traditional ifelse . In short, you change the x value to x + growth-rate if the condition x < max-resources is true

Chapter 3: Addressing Archaeological Questions and x if it is not. In our case, each item in the list has to be checked one by one to see whether it needs updating and, if so, to apply the growth-rate to just that item. The last thing we need to change is a little update to make-hills : to make-hills let hills (patch-set patch (max-pxcor * .33) (max-pycor * .33) patch (max-pxcor * .67) (max-pycor * .67))

TEST CODE BLOCK 3.25

ask patches [ let dist distance min-one-of hills [distance myself] set resources n-values num-resources [round (max-plants - (dist / (max-pxcor * .75) * max-plants))] set max-resources max resources ] end In this update, we have left the two resource landscapes the same shape for all of the resources. If needed, we could have separate growthrates , max-plants , and spatial distributions for each resource. We will learn more about how to work with spatially heterogeneous landscapes in chapter 7. As we have just seen, map is useful when applying a function across a list, particularly when you want the outcome to also be a list, because the function you give as a parameter is structured as a reporter. A similar primitive, foreach , also uses anonymous procedures (i.e., the -> ) to work through a list but does not produce a list as a result. Instead, foreach can be used to run a code block of commands repeatedly, where an argument for that code is each one of the list items in turn. NetLogo’s Dictionary clarifies the difference in both the syntax and the parameters needed: map reporter list foreach list command

reporter: a type of procedure that calculates a value and reports it back.

TEST CODE BLOCK 3.26

97

PA RT I : L E A R N I N G TO WA L K

For example, in the regrow-patches code block above, map needed the reporter x + growth-rate , whereas if we programmed something similar with foreach , we would need to write it as set x x + growth-rate because it takes a command as the parameter. With foreach , you would also need to write extra code to collect the result of those commands into a list, for example, using lput . We will see a few examples of that in the subsequent chapters (e.g., ch. 5). 3.5 Building Artificial Anasazi Complexity science excels in simple, abstract models, which can be used across very different systems.

Comparing the model output against multiple independent data sources is the ideal way to do validation. The Artificial Anasazi model was replicated by Janssen (2009) in NetLogo and is available on CoMSES. See Further Reading at the end of this chapter.

98

In this chapter we built a simplified model of foragers gathering resources from a landscape and moving about to find more plentiful resources. This is a simple model, but it formed the backbone to the Artificial Anasazi model, in which patches continuously change their productivity in a simulation of environmental variability. This required only a slight modification of SugarScape, yet the authors were able to examine an archaeological hypothesis. Although Artificial Anasazi models a semi-sedentary farming society rather than hunter–gatherer foraging, you can see this does not really affect the model’s ontology; the farmer agents “forage” for arable land to plant. There is a certain universality in simple models. Often they can represent very different real-world systems (Page 2018, ch. 3). Although it is an excellent model in many respects, it is worth focusing here on the authors’ validation strategy. Axtell and colleagues used two independent sources of archaeological data to compare to their model results: first, they had the spatial-temporal distribution of Ancestral Puebloan settlements, and second, they counted the number of households over time as a demographic proxy (fig. 3.3). Thus, the model results were compared to two independent data patterns, giving them confidence that this correspondence did not happen by chance. In subsequent chapters, we will build up to some other aspects of Artificial Anasazi, like its targeted mobility (ch. 4) and population dynamics (ch. 6). You will also see many more of these “baseline” models that we use to approach our particular case studies.

Chapter 3: Addressing Archaeological Questions

Figure 3.3. Map and population plot produced from a single run of Janssen’s NetLogo replication of Artificial Anasazi. One can compare the evolution of the artificial population with historical records, but also the spatial distribution of simulated settlements, to the one recorded archaeologically.

3.6

Summary

Modeling subsistence is all about tracking the flow of resources, energy, and population. Manipulating lists is a difficult task for both seasoned practitioners and new modelers, but they serve this accounting task well. We intentionally rounded out the last coding exercises of part I, Learning to Walk, with genuinely challenging tasks to push you to think about how these simple NetLogo primitives can be combined in more complex ways. Combining and expanding on the techniques you have learned so far will make some truly flexible code that does exactly what you want it to do. We do not expect that you will grasp every aspect on your first read-through, but hopefully through trying it out on your own, and adding in print , type , and show lines to examine the state of the model and its variables at each step, you will be able to figure it out. Don’t forget that whenever you get stuck, you can simply search for answers on the internet. Usually this will lead you to Stack Overflow,3 which is where coders of all programming

3

TIP You can apply these strategies whenever you need to dive into the code to understand what it is doing.

https://stackoverflow.com 99

PA RT I : L E A R N I N G TO WA L K

languages go to check whether someone else has already solved a similar issue.4 The first three chapters consisted of replications of published models. Replication is as critically important in agent-based modeling as it is in science in general. We always learn something new in the process of reproducing an existing model, sometimes just reinforcing that the previously published research was sound. Often, finding new ways to code and extend an old model leads to valuable and novel research directions (Marwick 2017). Replication is easier when the model’s code is accessible, and agent-based modelers are usually very good about sharing their code. SugarScape is a highly abstract model, while Artificial Anasazi is a highly empirical one. The key difference is in the conceptualization and parameterization of the model, that is, what you decide the unit being passed from patch to agent represents and what its characteristics are (value, quantity, abundance, species, etc.). By looking at these models in detail, one realizes that these building blocks—algorithms—are highly flexible and adaptable to many different research questions. Part II, Learning to Run, focuses on expanding your knowledge of these building blocks so that you will be able to start building your own models by combining and extending these common algorithms in novel ways. E

See chapter 9 for more details on how, where, and why you should make your models available to others. Taking a highly abstract, generalized model and applying it to your specific case study is a common way to develop models.

End-of-Chapter Exercises 1. Add a line plot to the INTERFACE tab to track the average amount of resources in storage of the agents over time. Next, create a histogram to show the variance in storage amount (i.e., wealth inequality) over time. What can these models tell us about wealth equality/inequality? 2. Experiment with different population sizes. Does this have an effect on the “wealth” of agents? How? 3. Change the code to design several new landscapes with: (a) four hills, each with a different amount of sugar; (b) sugar distributed randomly in patches throughout the landscape; and (c) one or more barriers 4

100

It is so prevalent that a satire news site circulated an article titled “Computer Programming to Be Officially Renamed ‘Googling Stack Overflow.’ ”

Chapter 3: Addressing Archaeological Questions that partially restrict movement between the sugar hills. How does this lead to areas of wealth and areas of poverty in your model? 4. Add in a patch pollution variable. Have agents leave pollution when they eat sugar and restrict agents from entering cells with a pollution amount that is too high (use a slider to play with what is “high” here). Pollution should dissipate over time as well, so write a countdown procedure for the patches’ pollution. This is one of the original SugarScape experiments. 5. Download Janssen’s replication of Artificial Anasazi from CoMSES. Find the harvestconsumption procedure and work through his list code to figure out how it works. Add print statements to print out the list contents at different points within the procedure. A STEP button might also be helpful so you can go slow enough. Further Reading ▷ A. Angourakis et al. 2017. “The Nice Musical Chairs Model: Exploring the Role of Competition and Cooperation Between Farming and Herding in the Formation of Land Use Patterns in Arid AfroEurasia.” Journal of Archaeological Method and Theory 24, no. 4 (December): 1177–1202. doi:10.1007/s10816-016-9309-8 ▷ T. Baum et al. 2020. “How Many, How Far? Quantitative Models of Neolithic Land Use for Six Wetland Sites on the Northern Alpine Forelands between 4300 and 3700 BC.” Vegetation History and Archaeobotany 29, no. 6 (November): 621–639. doi:10.1007/s00334-01900768-9 ▷ S. A. Crabtree et al. 2017. “How to Make a Polity (in the Central Mesa Verde Region).” American Antiquity 82, no. 1 (January): 71– 95. doi:10.1017/aaq.2016.18 ▷ J. S. Dean et al. 2000. “Understanding Anasazi Culture Change through Agent-Based Modeling.” In Dynamics in Human and Primate Societi : Agent-Based Modeling of Social and Spatial Process ,

101

PA RT I : L E A R N I N G TO WA L K

edited by T. A. Kohler and G. J. Gumerman, 179–205. Oxford, UK: Oxford University Press, July. ▷ J. M. Epstein and R. Axtell. 1996. Growing Artificial Societi : Social Science from the Bottom Up. Complex Adaptive Systems. Washington, DC: Brookings Institution Press. See NetLogo Model Library for SugarScape models. ▷ M. A. Janssen. 2009. “Understanding Artificial Anasazi.” Journal of Artificial Societi and Social Simulation 12 (4): 13. https://jasss.soc. surrey.ac.uk/12/4/13.html, NetLogo Code: https://doi.org/10.25937/ krp4-g724 ▷ T. A. Kohler, R. K. Bocinsky, et al. 2012. “Modelling Prehispanic Pueblo Societies in their Ecosystems.” Ecological Modelling 241 (August): 30–41. doi:10.1016/j.ecolmodel.2012.01.002

102

N OT E S

PART II: LEARNING TO

RUN



4 MOBILITY ALGORITHMS: HOW DOES MOVEMENT LEAVE ITS MARK?

4.0

Introduction

The previous part, Learning to Walk, was designed to establish a baseline of skills necessary for any modeler. We used practical tutorials replicating published models to introduce NetLogo, its syntax, and its most common primitives. The second objective was to develop a steadfast understanding of the modeling process, its many uses, and its role in the scientific practice. You may find yourself revisiting the first chapters to look up a term or specific NetLogo primitive, but you are now well equipped to read and understand any existing models. As usual, the NetLogo Dictionary and Programming Guide are the ultimate arbiters when in doubt. We will return to the tutorial-style chapters in Part III. Part II, Learning to Run, builds on the foundation of the first section. Where Learning to Walk was a whirlwind tour of the NetLogo language, this part aims to consolidate what was introduced before. Here you will gain steadiness in your modeling steps, in terms of both coding and model building. Thus, this and the following two chapters will differ in structure from part I. Instead of working through a published case study, we will do what you probably have been eager to do all along: give you the tools to create your own models. As in the previous part, we will use the three topics constituting the building blocks of most archaeological models: human movement (ch. 4), exchange (ch. 5), and subsistence (ch. 6). We will review the algorithms used to model these phenomena and their applications, including published examples and potential applications in archaeology. The aims of this part are:

OVERVIEW ▷ Algorithm zoo: pedestrian movement, group migration, and population dispersals ▷ Simulation scales ▷ Types of validation ▷ What is equifinality?

• To offer a comprehensive overview of the modeling approaches and building blocks of most archaeological simulations.

107

PA RT I I : L E A R N I N G TO R U N

• To look in more detail at the modeling process, from research questions, formalization, and implementation to calibration and validation. • To gain the necessary proficiency in coding to write your own models independently. This part showcases how modeling even seemingly basic processes can be done in multiple ways and how decisions made at each modeling step can impact the overall results of your model in occasionally unpredictable ways. One of the topics may be closer to your research than others—we nevertheless recommend you at least skim through all three chapters. You never know what the modeling journey may throw at you, so having an idea of what exists is useful, even when it is far from your current interests. While we will not produce fully worked models in this section, we nevertheless recommend that you keep NetLogo open to try things out as we go along. The final section of this chapter contains a full bibliography of the models included in this chapter, along with links to their original code if available. You can also refer to the ABMA Code Repo for working versions of all models.1

TIP We recommend you open a new model, set the world’s screen to 100 × 100 patches (patch size 4, or adjust to suit your screen) with all edges wrapped.

4.1 Modeling Human Movement Human movement is one of the prime topics in archaeology and, coincidentally, a good example of a research area where simulation techniques are particularly easy to apply. Human movement is inherently about individual decision-making in response to external factors such as the environment or other agents that, when aggregated, can produce unexpected populationlevel patterns. These patterns are easily recognizable in the archaeological record. For example, we can detect the earliest (known) traces of human presence in a previously uninhabited territory (see ch. 1, Mithen and Reed 2002; Romanowska et al. 2017), changes in the spatial distribution of a specific cultural tradition (Crema and Lake 2015; Gravel-Miguel and Wren 2018; Wren and Burke 2019), or the arrival of a previously unknown subsistence strategy (Lemmen, Gronenborn, and Wirtz 2011; Fort et al. 2016). We will illustrate the mechanisms that lead to these kinds of population-level pat-

The classic

ABM-in-geography

textbook is (O’Sullivan and Perry 2013); for a more recent one, see (Crooks et al. 2019).

1

108

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch4

Chapter 4: Mobility Algorithms terns. We will also discuss validation, the phase of the modeling process that addresses one of the most fundamental questions in modeling: How do we test whether our model is a correct representation of the past system? It is relatively simple to model human movement, as it essentially depends on one decision event. The agent has to update its location—that is, choose where in space (including its current position) it wants to be. How this decision is made, what will be weighed to assess options, or how much information the agent possesses will depend on the studied context, and thus differs from one model to another. In many models, the ultimate goal is to maximize one’s fitness by foraging for food and other resources, or by avoiding overcrowded areas. Such models are often accompanied by a sensing submodel that enables the agent to assess each option and choose accordingly. Other models focus on individual micromovements; for example, pedestrians walking through the streets of an ancient city or traveling the roads of an empire. In these cases their decisions will depend on the individual’s particular goals (follow a procession, find a workshop, reach another city, etc.). Finally, in some cases the type of movement is unknown, or not relevant, so the agent’s decision of where to move is modeled as a random or semirandom process, as in the Y &B model from chapter 1. In this chapter we will explore the question of scale, one of the crucial challenges of initial phases in the modeling process. The scale chosen for the model depends on the research questions as well as the archaeological data available for validation. For example, most human movement models fall into one of the following three categories:

DON’T FORGET Remember the difference between verification and validation. Verification means we ensure there are no errors in the code; in validation we try to assess whether the model is a valid representation of the real system we’re modeling.

Not all agents have the same sensing ability. They may also differ in what they want to optimize depending on their particular circumstances.

scale (in models): the size of spatial units and the duration of temporal units within the modeled system.

• individual/pedestrian movement; • group/household movement; and • medium- and long-range population dispersal. Pedestrian movement (sec. 4.3) concerns an individual; in this instance one agent equals a person, and one time step is usually measured in seconds, minutes, hours, or days. The topics that fall within this category often have very fine temporal resolution, for example, battleground simulations (Rubio-Campillo, Matías, and Ble 2015; Rubio-Campillo, Cardona, and Yubero-Gómez 2015), and be precise in terms of the topog109

PA RT I I : L E A R N I N G TO R U N

To model something on the scale of hours and meters, we need matching data. Thus, case studies usually come from the more recent past.

We often quip that in demic diffusion it’s people that move, while in cultural diffusion it’s pots.

raphy, for example, people finding their seats in the Colosseum (Gutierrez et al. 2007) or taking part in a procession (Crawford 2019b), but may also concern much more abstract systems. For example, in foraging models, an agent may look for food, water, or other resources within an abstract landscape (Brantingham 2003). Group movement (sec. 4.4) refers to the seasonal or annual changes in the main location of a small group or family unit. The agents represent small groups of people, and time generally passes in increments of weeks, months, seasons, or years. This kind of movement may be associated with the creation of a new household (e.g., when “children” move out), a household move due to environmental or social changes, or the spreading of a city’s urban area (Batty 2005). The third type, medium- and long-range population dispersal (sec. 4.5), is modeled using whole populations of people as agents and years, decades, or generations as time steps. We often differentiate between two main types: the cultural diffusio that concerns the spread of an idea, such as an innovation, a decoration pattern, or a belief, and the demic diffusio that concerns physical movement of people, such as in the out-of-Africa dispersal. Although these processes are fundamentally different, they often leave behind similar data patterns, for example, a new artifact type being found farther and farther from a point of origin, making it difficult to distinguish them in the archaeological record without the use of mathematical tools (Fort 2015). We will cover demic diffusion in this chapter and cultural transmission in chapter 5. In this chapter we will use these three scale categories to structure our discussion, reviewing the algorithms used to model these types of processes and their application in archaeology and other disciplines. Since movement is not inherent to humans alone, many of our methods and algorithms originated with chemistry or ecology but have been shown to mimic human behavior in surprisingly sharp detail. 4.2 An Introduction to Algorithms In chapter 1, we gave a brief definition of an algorithm as a set of instructions to be followed in a specific order by the computer. But algorithms do not exist only in the computing world; think of a cooking recipe.

110

Chapter 4: Mobility Algorithms When you open Julia Child’s Mastering the Art of French Cooking, you follow her steps to go from raw eggs to mayonnaise. For example: “Place the egg yolks in a bowl, add vinegar, mustard, and oil, beat until the mix thickens.” You may notice how the ingredients need to be specified (egg yolks and not whole eggs) and the order is important (you cannot beat the ingredients before you put them in a bowl). By employing this same clearly defined sequence of actions, we can ensure the final output can be replicated by others (e.g., not Julia Child herself) and in other contexts (e.g., using a different bowl). Computer algorithms are, in principle, the same as cooking recipes but described with much less ambiguity. The entities involved, exact order of actions, and modification to variables are all highly specified. An algorithm, then, turns the current state of a model into the state of the model at the next time step. It’s a good idea to have a variety of algorithms in your modeler cookbook because, just like any methodology, each comes with its own set of assumptions that may or may not be appropriate depending on the particular research questions. With this in mind, let’s look at algorithms used to model human movement. 4.3

Think of software as a cookbook for the computer. Data are the ingredients that go into the recipe, and the output is the prepared dish.

As with different recipes for the same dish, it is possible to achieve similar results via different algorithms.

Pedestrian Movement

RANDOM WALKS

The most basic method for modeling individual movement is a random walk. Here, the agent has an equal probability of moving onto any location within its movement radius. The movement does not have a predominate goal or direction. We often use a random walk when we do not know what drove mobility decisions, when we think that there are many independent types of movements overlapping, or as the null-hypothesis pattern of movement to establish a benchmark other types of mobility could be compared to. The most distinctive feature in a random walk is that it involves a lot of turning back on itself and that the agent takes a while to move away from the starting point (fig. 4.0). With a large number of steps, the average behavior should approximate the central limit theorem, meaning that the agents’ positions around the origin point will

Model: Random Walk . ABMA Code Repo: ch4_pedestrian_movement

111

PA RT I I : L E A R N I N G TO R U N

be normally distributed (Pearson 1905; Viswanathan et al. 2011).2 Random walks have been applied in many archaeological simulations, for instance, Brantingham (2003, see ch. 7 in this book) created a behaviorally neutral model of stone raw material procurement using a random walk. The two implementations below illustrate the point that even something as simple and common as a random walk can be coded in different ways, with different implications. First, we make a simple setup to create one agent and use the pen-down primitive to draw the path taken by the agent. While this last step is not necessary, it helps us to see how the agent moves around on the landscape. Then we provide two different implementations of choosing the new location at random: random-walk and random-walk-patches .

During writing, the three authors of this textbook discovered that we each coded random walks in a different way.

.

CODE BLOCK 4.0

to setup ca crt 1 [ pen-down ] end

. You can make buttons in the INTERFACE tab for each type of walk, or add them to the go procedure and uncomment as required.

to random-walk ask turtle 0 [ if random 2 = 1 [ ; rt random 360 ; alternative implementation set heading random 360 fd 1 ] ] end

2

112

In thanking the reader who wrote in with a solution to his random walk query, Pearson (1905) wrote: “The lesson of Lord Rayleigh’s solution is that in open country the most probable place to find a drunken man who is at all capable of keeping on his feet is somewhere near his starting point!”

Chapter 4: Mobility Algorithms

Figure 4.0. One random-walk agent and one random-walk-patches agent with “pendown” to display their movement paths. The random-walk agent has more variation in turn angles and moves less often. Note that the agents both recross their paths frequently.

.

to random-walk-patches ask turtle 0 [ move-to one-of patches in-radius 1.5 ] end In the first implementation, random-walk , we flip a virtual coin ( random 2 ) which returns a value of 0 or 1. If it is 1, the agent moves; if it is 0, they stay put. Then we ask the agent to face a random direction (using either rt random 360 or set heading random 360 ) and take one step forward. In the second version, random-walk-patches , we ask the agents to move to a random cell within a radius of 1.5 cells. In effect, this is the agent’s current cell plus each of the eight cells around it. At first glance, these two ways of coding a random walk seem to be equivalent. In fact, they are not, for two reasons. First, in the randomwalk version, the agent always moves a distance of 1.0 map unit (the width of a patch) at any direction of 360 degrees of heading. Thus, an

CODE BLOCK 4.0 (cont.)

. One- and two-dimensional random walks are recurrent (they come to the starting point infinitely often) and unbounded (they will, eventually, reach any value).

move-to transports the turtle to the center of a patch. Radius 1.5 will include the centers of all eight neighboring patches and the currently occupied patch.

113

PA RT I I : L E A R N I N G TO R U N

Figure 4.1. Correlated random walk agents recross their own path less often, as their turns are limited.

TIP If neighbors was used instead of in-radius 1.5 , the agent would always move. See these and other random-walk versions in the ABMA Code Repo.

Model: Correlated Random Walk

114

agent traveling along the diagonal could step on a single patch twice, then step over another without touching it at all. In the random-walkpatches version, the agent always moves from a patch center to another patch center, thus ensuring that interaction with all neighbors of the current patch occurs at the same rate. However, it also means that they move farther on the diagonals (~1.41 map units) versus the straight compass directions (1.0 map units). Second, in the first version the probability of staying on the current cell is 50% (one in two), whereas in the second version it is ~11% (one in nine). Neither of these implementations is more correct, but, if deployed in the Y &B model from chapter 1, they would yield different dispersal rates. If used, the second algorithm ( random-walk-patches ) would have moved the agents away from their origin faster because just under half of the agents’ steps are 41% longer. C O R R E L AT E D R A N D O M WA L K S

Moving beyond the basic random walk, a more realistic approximation of an individual may be for the agent to mostly follow the same direction. Here we are taking the view that the directions chosen per step are correlated, that is, not independent of one another even if the agent is not heading anywhere specific. Correlated walks are also known as persistent random walks, because the general directionality persists as the walker continues (Patlak 1953; Codling, Plank, and Benhamou 2008). To

Chapter 4: Mobility Algorithms

Figure 4.2. Correlated random walk. Agents have the highest probability of moving in the direction they are facing.

implement a correlated random walk, we change the base algorithm only slightly. to random-correlated-walk ask turtle 0 [ rt random-normal 0 45 fd random 2 ] end

. CODE BLOCK 4.1

Here, we limited the options of the agent’s initial heading. Instead of turning on their heel and going in any random direction, the agent has the highest probability of moving in the general direction they are already facing (fig. 4.1). The random-normal 0 45 primitive draws a random number from a normal distribution centered on the mean (here: 0) and the standard deviation (here: 45 degrees). See figure 4.2). LÉVY FLIGHTS

So far, the agent has moved only up to one step at a time. However, some research (e.g., Raichlen et al. 2014; Viswanathan et al. 1996) indicates that many animals and humans follow a completely different pat-

Model: Lévy Flights by O’Sullivan & Perry

115

PA RT I I : L E A R N I N G TO R U N

Figure 4.3. In a Lévy flight, the heading is completely random, but the step length is taken from a Cauchy probability distribution. This means that most steps are short, with only occasional longer-distance steps.

TIP If your agent’s long jumps wrap the map several times, increase the world-size. .

CODE BLOCK 4.2

tern of movement, called Lévy Flights. The distribution of step lengths in Lévy Flights forms a fat-tailed distribution called a Cauchy distribution. In practice it means that, although most of the steps are short, from time to time the agent covers a particularly long distance in one step (fig. 4.3). to levy-walk ask turtle 0 [ set heading random 360 let step-length abs r-cauchy 0 1 fd step-length ] end to-report r-cauchy [loc scl] ; NetLogo tan takes degrees not radians let X (pi * (random-float 1)) report loc + scl * tan(X * (180 / pi)) end

Model: Targeted Walk 116

TA R G E T E D WA L K

In many models, the agent engages in a search for resources, other agents, or particular locations. This means that they need a form of sensing—an

Chapter 4: Mobility Algorithms ability to gather information about their surroundings. Add some target patches in the setup that the agent aims to find. to setup ... ask patches [set pcolor white] ask n-of 100 patches [set pcolor black] ... end

. CODE BLOCK 4.3

to target-walk ask turtle 0 [ let target min-one-of patches with [pcolor = black] in-radius 10 [distance myself] ifelse target != nobody [ move-to target ask patch-here [set pcolor grey] ][ set heading random 360 fd 1 ] ] end The in-radius primitive is particularly useful here, as it can define the agent’s sensing distance. The min-one-of primitive, followed by [distance myself] , specifies that the agent should move to the target closest to the agent if there is more than one within the sensing radius. We can include multiple criteria, here the target type and distance, in one local variable target, and then choose the one that best fits these conditions. The main decision-making algorithm here is based on an ifelse loop: if there is a sought-after patch within the sensing radius ( if target != nobody ), the agent moves to it; otherwise it engages in a random walk (fig. 4.4). This is a universal algorithm that can be easily adjusted in terms of the sensing radius, the characteristics of the target

TIP It’s important to account for unlikely but possible situations. Although the agent will rarely be at exactly equal distance from two targets, it can occur. In this case min-one-of chooses randomly between them.

117

PA RT I I : L E A R N I N G TO R U N

Figure 4.4. Agents find and move toward resource patches if they are within a specified radius, or random-walk if not. Lighter patches have already been visited.

Model: PaleoscapeABM by Wren et al.

TIP If the friction surfaces are isotropic—not direction dependent—it is much simpler and more computationally efficient to calculate a cost map in GIS software and then import it into NetLogo.

118

(e.g., instead of the distance, it may be its caloric return), or the choice among multiple targets. We can use this adjustable algorithm to incorporate a more goaldirected approach to searching a landscape than a simple random walk (also see sec. 6.4). In a model by Wren et al. (2018), a series of ecological habitat types were assigned kcal/hour return values to all patches in a landscape, and then a version of the code above was used to model forager agents searching out the most profitable food resources within the landscape. Rather than simply minimizing distance with min-one-of... [distance myself] , the model accounts for certain resources that are only available for parts of a day, calories not acquired while walking to a distant resource, and the capacity for anticipating resources that are not yet available. If the landscape is particularly rugged, the algorithm may also be adjusted to account for the differences in travel cost incurred on shallow versus steep slopes or from other friction surfaces, such as differences in vegetation (e.g., traveling through short grasses versus thick jungle). It takes some knowledge of trigonometry, but this would allow you to incorporate the least-cost path methodology used in standard GIS software into your agent-based model (e.g., Gravel-Miguel and Wren 2018, see ch. 7 for details on using GIS data in NetLogo).

Chapter 4: Mobility Algorithms WEIGHTED RANDOM WALK

A targeted walk assumes that the agent has perfect knowledge of the criteria being used for choosing the target and that they will always pick the most desirable cell. However, if there is a set of acceptable cells with similar values, it may not be realistic to assume a human agent could or would always choose the single best cell. We can model this by weighting a random walk by a continuous variable so that many cells have the potential to be picked randomly, but some have more chances than others. Think of it as rolling a die, but instead of having one each of numbers one to six, the die has two ones (33%) and four twos (67%). NetLogo has a built-in extension to help us with randomness. Extensions are like an extra library with additional primitives. Some extensions are bundled with NetLogo; others you need to install.3 Add extensions [ Rnd ] to the top of the code, and the primitive rnd:weighted-one-of is available for use (Payette 2013). Again, we can combine a number of conditions to decide on the weighting of target patches, for example, the quality of the habitat: let target rnd:weighted-one-of patches [habitat_quality] Or the quality of the habitat within five map units: let target rnd:weighted-one-of patches in-radius 5 [habitat_quality] Or both of these conditions combined with another criterion, the patch being empty: let target rnd:weighted-one-of patches in-radius 5 with [not any? turtles-here] [habitat_quality]

3

Model: Weighted Random Walk by Wren

. CODE BLOCK 4.4

. CODE BLOCK 4.5

. CODE BLOCK 4.6

For more information on extensions, see the NetLogo Extensions Guide: https://ccl. northwestern.edu/netlogo/docs/extensions.html. 119

PA RT I I : L E A R N I N G TO R U N

Figure 4.5. The agent’s random walk is weighted toward patches with a higher value (lighter shade toward the right). There is still randomness in the movement, but over time the agent shifts to the richer side of the landscape.

. CODE BLOCK 4.7

.

There is no limit to the number of criteria you can add, but be aware that each one will complicate the analysis of final results.

120

Putting it all together: extensions [ Rnd ] patches-own [ habitat_quality ] ... to setup ... ask patches [ set habitat_quality pxcor set pcolor scale-color green habitat_quality 0 100 ] ... to weighted-random-walk ask turtle 0 [ let target rnd:weighted-one-of patches in-radius 5 with [not any? turtles-here] [habitat_quality] if target != nobody [face target move-to target] ] end

Chapter 4: Mobility Algorithms Some of the criteria are strict; for example, patches must be within a radius of five cells and must be unoccupied. However, the use of rnd:weighted-one-of patches...[patch_variable] means that the algorithm is more flexible. The agent is merely more likely to choose a cell with a higher value of the patch’s habitat_quality variable rather than forced to do so. In figure 4.5, our agent is sitting along a gradient of habitat_quality values. At any given point, the cells to the east have a higher value, say, a value of ten, and cells to the west have a lower habitat_quality of, say, five. In the strict target-walk algorithm above, the agent will always go east. With a weighted-randomwalk , the agent is twice as likely to go east, but there is still a chance that they will occasionally go west. Adding this kind of “fuzziness” to an agent’s decision-making process is a key strength of ABM. Here we can easily incorporate the erratic nature of human (or animal) behavior. Humans do not always choose the most optimal solution. Sometimes they do not know or have no time to correctly assess which option is better; sometimes it just does not matter because the difference is small or unimportant. Contrary to widely held opinion that computational modeling always implicates reducing humans to utility maximizers devoid of agency or imperfections, we can and should include these aspects in our models if the research questions or the context demands to do so. RESTRICTED WALKS

In some simulations, in particular those concerning pedestrian movement within the built environment, agent movement is restricted by barriers, such as walls and rivers, or limited to specific transport channels, such as roads (e.g., Graham 2006). In those cases, a function limiting the agents’ movement is required. Here you have two options: either eliminate cells of a given color from potential targets (see code block 1.11) or change the heading every time a barrier is found at the cell ahead (code block 4.8).

Herbert Simon received a Nobel Prize for the “discovery” that humans tend to be satisficers— they often settle for a good enough solution rather than the optimal one.

Model: Restricted Walk (Look Ahead Example in NetLogo Library)

121

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 4.8

to setup ... ask patches with [pxcor = 50] [set pcolor white] ... end to walk-restricted ask turtle 0 [ ifelse [pcolor] of patch-ahead 1 = white [ lt random-float 360 ] [ fd 1 ] ] end

We have not

unclicked WORLD WRAPS

HORIZONTALLY, so agents

can still access it from the other side.

Model: MAGICAL by Lake . ABMA Code Repo: ch4_remembered_ landscape

122

Here we have built a wall the agents cannot cross. Instead, they turn until they no longer face the wall and can move forward. You can restrict them to a more limited range of turning angles to produce realisticlooking movement patterns. REMEMBERED LANDSCAPES

In all of the above algorithms, the agents have no memory of their prior experiences; they merely keep moving forward. Imagine a situation where you would want agents to be able to remember the places they have been or the routes that they previously traveled. In an early application of agentbased modeling to human foraging called MAGICAL (multi-agent geographically informed computer analysis), Lake (2000, 2001) allowed each agent to slowly build up their own mental map of a landscape of foraging locations as they encountered them. The agent then made mobility decisions based on this subset of the larger landscape. In the previous versions of the walk algorithm, we restricted mobility options to a subset of the landscape closest to the agent by using the in-radius primitive. Here the goal is to store the location of previously visited patches and direct movement toward remembered patches. NetLogo makes this relatively easy for us through the primitive patch-set , which is a list of patches that can either be defined based

Chapter 4: Mobility Algorithms on some criterion (e.g., set patch-set patches with [pcolor green] ) or can be used as a dynamically evolving list, which is what we will do here. As with the target-walk above (code block 4.3), agents can hone in on a small number of white target cells on the landscape. turtles-own [memory] ... to setup ... ask n-of 30 patches [ set pcolor white ]

. CODE BLOCK 4.9

crt 2 [ set memory patch-set patch-here set color 15 + (10 * random 12) ] ... end to memory-walk ask turtles [ ifelse any? memory with [pcolor = white] [ let p one-of memory with [pcolor = white] face p fd 1 ][ set heading random 360 fd 1 ] set memory (patch-set memory patch-here) ask memory with [pcolor != white and pcolor != grey]

123

PA RT I I : L E A R N I N G TO R U N

Figure 4.6. Two agents explore a landscape with isolated targets (black). The darker areas show which patches are “remembered” by each agent.

. CODE BLOCK 4.9 (cont.)

[ set pcolor [color] of myself - 2 ] if [pcolor] of patch-here = white [ ask patch-here [ set pcolor grey ] ] ] end The result will be a colorful mess of agents taking turns to move, and then recoloring their remembered landscape according to their personal color. In figure 4.6, you can see that one agent has just discovered a new patch (now turned gray). Since multiple agents may have the same cell in their memory, when the run stops, whichever agent went last will have their color on top of the others, which is why it looks like one agent has explored less. While this color coding may not be perfect, underneath the turtles store their mental landscape regardless of the displayed color. Similarly, keeping the resource patches (marked, for example, by their white color) in memory can be important in simulations where resources regularly “regrow” and there is a benefit to returning to them periodically. We will return to patch use and regrowth in chapter 6. For now you can just implement a simple probability of gray patches changing back to white using a slider and the code that follows:

124

Chapter 4: Mobility Algorithms .

ask patches with [pcolor = grey] [ if random-float 1 < regrow-rate [ set pcolor white ] ]

CODE BLOCK 4.10

. DON’T FORGET Add a regrowth-rate slider with values between 0 and 1 (increment 0.01).

Beyond mental maps, Lake was also interested in the idea of cultural learning. He imagined a group of foragers sharing resource information with each other back at camp at the end of the day. We can add cultural learning to our memory-walk by having agents merge their respective mental maps, or patch-sets , when they stumble upon one another (see ch. 5 for more examples of learning). ask turtles [ ... if any? other turtles-here [ set memory (patch-set memory [memory] of one-of other turtles-here) ask one-of other turtles-here [ set memory (patch-set memory [memory] of myself) ] ] ] Here, each individual agent “memorizes” a new patch-set for themselves out of the combination on their own patch-set and the turtle they currently share a patch with. Add a learning? switch to the INTERFACE tab and make it a second conditional after if any? other turtles-here if you’d like to be able to toggle this behavior on and off. In a similar approach to this agent-learning algorithm, Costopoulos (2001) gave agents different memory capacities with respect to remembering their own past resource extraction activities. He then experimented with more or less abundant landscapes and found that the behavior of agents with different memory capacities (i.e., number of patches remembered) diverged.

. CODE BLOCK 4.11

.

A patch-set made up of two previous patch-sets equals a larger patch-set (i.e., the union of both). This doesn’t work when combining lists; instead you end up with a list of lists.

Model: Foraging Memory Capacity by Costopoulos

125

PA RT I I : L E A R N I N G TO R U N

Figure 4.7. Flocking/Boids model. Small “flocks” of agents spontaneously emerge as they adjust their headings and distances to coordinate with their nearest neighbors.

Model: Trail Evolution by Helbing et al.

Model: Walk This Way by Crooks

126

The recognition of signs of human activity offers a less explicit model of shared past experience impacting movement. Helbing, Keltsch, and Molnar (1997) imagined the repeated footprints of many walking people flattening down grass and their accumulated tracks slowly merging into established trail systems as people found it more comfortable to walk on existing paths than on untrodden ground. They modeled the individual’s walking direction as an average of movement toward a specific destination and movement toward previously flattened ground. One can imagine such a process leading to the development of a transport system. This is similar to the alignment of directions used in the flocking model (see below), though it focuses on the directions to specific targets ( face target-patch ) rather than the directions of other agents. A similar model, called Walk Th Way, was implemented in NetLogo by Crooks et al. (2019) .

Chapter 4: Mobility Algorithms FLOCKING

Flocking, discussed briefly in the introduction to this book, is a type of movement algorithm that is often applied to groups of agents. We are still modeling the behavior of individuals, but this time in coordination with other individuals. In some of the algorithms above, agents could “sense” specific locations or characteristics of patches (like their color), but to coordinate with other agents this sensing must expand to include other agents’ locations and characteristics. Originally developed by Reynolds (1987) to mimic the flocking of birds, the Boids model’s algorithm consists of three simple rules:

Model: Boids by Reynolds (Flocking in NetLogo Library)

1. Separation: Do not fly too close to neighboring birds (i.e., sensing their direction). 2. Alignment: Adjust the direction of your flight to an average of your neighbors’ headings (i.e., sensing their headings). 3. Cohesion: Do not fly too far from the center of gravity of the nearest birds (i.e., sensing their positions). Surprisingly, this simple algorithm replicates complex patterns of bird flocking and pedestrian movement (fig. 4.7). Janssen and Hill (2014, 2016) used a modified flocking algorithm to model the movement of human hunting parties spreading out to search for game while staying within auditory range of each other. In contrast, Crawford (2019a) used the flocking algorithm to model the passage of ritual processions through the streets of ancient Ostia. 4.4

Model: Procession Movement by Crawford

Group/Household Movement

For research questions that involve a wider area and longer timescale, it often makes more sense to model movement with an agent that represents a household, family unit, or other small group of people. The decision-making algorithm may be quite similar to that of the pedestrian movement already discussed, but is designed to represent widerscale movements. For example, the residential mobility of a forager band could be modeled by the household agent moving once a month to a neighboring patch to represent a move of a couple of kilometers. While this now represents the collective decision-making of many people, in127

PA RT I I : L E A R N I N G TO R U N

Model: Ger Grouper by Clark & Crabtree . ABMA Code Repo: ch4_ger_grouper

In Mongolia, ger refers to the nomadic yurt-style house. For Ger Grouper’s patch grazing, energy, and population dynamics, see chapter 6.

128

stead of a single person, from a coding perspective it makes little difference. Random, targeted, restricted, and memory walks may all be applied to group movement with minor adjustments for the different spatial and temporal scales. However, when modeling once-a-season types of movement decisions, some algorithms like random walks or Lévy flights make little sense, since the modeled groups would be relatively knowledgeable about their surrounding landscape. With the longer timescale, social dynamics—household population growth, children splitting off to form new households, or interactions with other households, for example— may come into play as well. We will examine the questions of household-level seasonal migration using the Ger Grouper model (Clark and Crabtree 2015). This model sought to understand how households can fission and fusion in response to environmental stress, as well as how seasonal migration impacts levels of storage and subsistence. We will explore this model further in chapter 6. For now, though, we will examine the movement algorithm. In this model, agents migrate between summer and winter patches and exploit productive (i.e., pcolor = green ) patches for grazing. There are two types of movement: first, a “teleporting” type between summer and winter areas ( move_spring and move_autumn ), and a more local movement aiming to land precisely on a productive patch if one is available. Agents first move to a random patch in their summer grazing area ( moveto one-of summer-patches ). They do not need precise knowledge of the summer lands, so their movement is only vaguely targeted within the summer region, which mimics pastoralist practices. Next, agents move in their eight-cell Moore neighborhood (fig. 1.4 in ch. 1) to a green patch ( ifelse any? neighbors with [ pcolor = green ] [ move-to one-of neighbors with [ pcolor = green]] ) using the ifelse primitive to assess the productivity of the neighborhood, and moving to a better patch. Note that in the following code block we only include the movement algorithm of Ger Grouper .

Chapter 4: Mobility Algorithms .

to setup ... set summer-patches patches with [pxcor < (max-pxcor / 2)] set winter-patches patches with [pxcor >= (max-pxcor / 2)] ask summer-patches [set pcolor green] ask winter-patches [set pcolor one-of [green brown brown gray gray gray]] ... to move-season ifelse ticks mod 2 = 0 [set current-season "winter"][set current-season "summer"] ask turtles [ ifelse current-season = "winter" [ move-to one-of summer-patches with [count turtles-here = 0] ][ move-to one-of winter-patches with [count turtles-here = 0] move-local ] ] end

CODE BLOCK 4.12

to move-local if pcolor != green [ if any? winter-patches in-radius 1.5 with [ pcolor = green ][ move-to one-of winter-patches in-radius 1.5 with [ pcolor = green ] ] ] end 129

PA RT I I : L E A R N I N G TO R U N

In this algorithm, agents do not store their prior locations but merely operate on the chance that they will move near a productive location. We could update this algorithm to permit agents a memory of the productive patches they camped on during the previous winter, which is the more environmentally restrictive region. The code above would need to be adjusted to move-to one-of visited-patches and include a contingency (i.e., using ifelse ) to continue to search for new patches if no remembered patches were currently productive. This is a similar approach to memory-walk (see code block 4.9). When we return to this model in chapter 6, we’ll see how previously productive patches need time to regenerate but that it is likely that a patch will be within the radius of other productive patches and that local-movement will therefore enable the household to move somewhere productive. Also, these patches are certain not to be gray patches (half of the winter area is permanently barren), meaning that the household can count on previously visited patches being productive at some point (see ch. 6 for patch-regrowth algorithms). This follows the logic Clark and Crabtree (2015) gathered from ethnographic interviews where households in northern Mongolia responded to a combination of local environmental cues (dry and short grasses that season, local moisture, perception of weather patterns based on past weather patterns, etc.), curated knowledge of past winter camps, and the avoidance of known unproductive areas when deciding where to move (see also Moritz et al. 2018). M U LT I L E V E L M O B I L I T Y

Model: Ache Hunting by Janssen . ABMA Code Repo: ch4_ache_hunting

130

In certain cases, it might be appropriate to have both household and individual scales of mobility operating within the same model. In their model of Ache hunting patterns in Paraguay, Janssen and Hill (2014, 2016) have both camp agents and hunter agents who operate at slightly different timescales. At the end of the day, agents select a destination for the hunters’ camps that represents the collective interests of the group. This location is chosen based on a random-walk (shown in code block 4.13) or by targeting patches of preferred habitat types within a specified radius (see sec. 4.3). The agents then spread out into the forest, keeping track of their distance from camp and their remaining

Chapter 4: Mobility Algorithms foraging time to ensure they will end up at their camp agent at the end of the day. While each tick of the model represents a full day (i.e., the camp’s timescale), the hunter agents use a while loop to repeat their movement commands many times within that tick to represent their subhourly mobility and hunting activities (i.e., the hunter’s timescale).

breed [ camps camp ] breed [ hunters hunter ] to forage ask camps [ let found 0 while [found = 0] [ lt random 360 if patch-ahead 20 != nobody [ if [vegetation_type] of patch-ahead 20 > 0 [ move-to patch-ahead 20 set found 1 ] ] ] ]

. CODE BLOCK 4.13

.

This code block includes a lot of variables not defined here. Refer to the ABMA Code Repo for a fully worked version.

ask hunters [set time-left 12 set done 0] let allhuntersdone 0 while [allhuntersdone = 0] [ ask hunters with [done = 0][ let walk-time-to-camp (distance my_camp * time-walk-cell)

131

PA RT I I : L E A R N I N G TO R U N .

ifelse time-left > walk-time-to-camp [ lt random 360 if patch-ahead 1 != nobody [ fd 1 ] set time-left time-left - time-walk-cell ][ face my_camp if distance my_camp > 1 [ fd 1 ] if time-left Extensions Examples -> ls .

133

PA RT I I : L E A R N I N G TO R U N

the LevelSpace manual for more details on these primitives and the NetLogo Models Library for worked examples.4 4.5 Population Dispersal Large-scale dispersals encapsulate movements that are the most visible in the archaeological record: the first out-of-Africa dispersal, the peopling of the Americas, or the spread of Neolithic farming across Europe. Although, like all dispersal events, large-scale movement is the result of an aggregation of individual behaviors and decisions, at such a large scale the population is considered largely homogeneous. We become less interested in modeling the movements and reproduction choices of individual people or households, and instead model large-scale average behaviors as probabilities. Here, an agent will represent a group rather than an individual, and one time step will represent a generation rather than a second, day, or season. THE BASIC MODEL: FISHER–SKELLAM

The Fisher–Skellam–KPP equation was first developed in chemistry to model the spread of substances.

In a review paper on migration in archaeology, Anthony (1990) describes a number of different ways to conceptualize long-distance migrations. However, the most popular way to model large-scale human movement remains the Fisher–Skellam–KPP equation and its various extensions (Fort 2015; Steele 2009). If the name rings a bell, this is because you implemented it in your very first simulation in chapter 1. The Fisher–Skellam–KPP equation is commonly used across disciplines to describe the process of spatial spread. The equation describes two processes: population growth fueling dispersal, and diffusion from more to less densely occupied regions. The direction of that diffusion is often additionally shaped by exogenous factors such as topography and/or biotic zones (see equation).

Fort (2015) gives a more accurate version of the equations that more fully account for human population dynamics.

See Steele (2009) for discussion on derivations of the basic Fisher– Skellam–KPP model, including effects of spatial and temporal heterogeneity, multiple population interactions, and evolutionary dynamics.

n δn = αn 1 − δt k (

+ D∇2 n

(4.0)

The change in population over time ( δn δt ) is determined by the size of the population, n, and the growth rate, α, constrained by the carrying capacity, k. This change occurs along a gradient from more to less densely 4

134

)

https://ccl.northwestern.edu/netlogo/docs/ls.html

Chapter 4: Mobility Algorithms populated regions, D∇2 n, with D representing the distance moved with each generation. Using sustained population growth to drive population expansion means that spread is inevitable. That is, it is assumed that the population will spread unless the population growth is negative or static. What may change is the speed of the dispersal and the shape of the dispersal front when it comes across difficult or impassable areas such as mountain chains or bodies of water. This basic algorithm was applied by Romanowska et al. (2017) , in which the authors modeled the first out-of-Africa dispersal and the relationship between the demographics at the front of the spreading population and patterns in the archaeological record. Similarly, Fort, Pujol, and Linden (2012) used this equation to model the spread of Neolithic farming and estimate its rate of dispersal in different regions in Europe. P R O B A B I L I ST I C C E L LU L A R AU TO M ATA A B M -STY L E

A cellular automaton (CA) is another type of simulation in which individual cells impact other cells in specific ways. Cellular automata use cells’ variable states (e.g., occupied vs. empty) so that the emergent behavior occurs through cells probabilistically changing their state because of the state of other cells, usually their neighbors. This is how John Conway’s famous Game of Life model works (Wolfram 2002). A well-known early simulation of hominin dispersal, the Stepping Out model, used this cellular automata approach (Hughes et al. 2007; Mithen and Reed 2002). In their simulation, a patch marked as occupied by a hominin group had a certain probability of colonizing a random neighboring patch (Pcr ) or of going extinct (Pext ). Subsequently, Hughes et al. (2007) modified Stepping Out to vary the Pext value depending on the vegetation class (e.g., temperate forest vs. desert). We will replicate Stepping Out here as an agent-based model instead of true cellular automata, meaning we will make agents that move from patch to patch instead of having the patches affect each other directly.

Model: Out-of-Africa Dispersal by Romanowska et al. . Model: Neolithic Spread by Fort et al.

TIP Think of cellular automata as a world of just patches, with no turtles.

Model: Stepping Out by Mithen and Reed ABMA Code Repo:

ch4_steppingOut

We only give you part of the code here, so you have to work out the missing parts. Head to the ABMA Code Repo for the full code.

135

PA RT I I : L E A R N I N G TO R U N

Open NetLogo and create a new model with a world size of 360×180 patches. In the setup below, we first import a PNG map5 as in chapter 1. We then must carefully assign Pext values using the pcolor of the imported image so that some vegetation classes, like boreal forest and tundra, are excluded (Pext = 1); the desert is a bit harsh (Pext = 0.07), but the rest are easy (Pext = 0.01). In the original paper, the authors experimented with making the coasts more favorable as well (Pext = 0.01 for patches within 4 cells of ocean), though we will ignore that for now. We have listed each biome as a note in the code block below. We will also assign a new color scheme as we go to make it easier to refer to them (fig. 4.9).

We will reuse the code you wrote back in chapter 1, so have those exercises at hand.

.

... import-pcolors "ch4_veg.png"

CODE BLOCK 4.14

.

Here, we worked out what vegetation class each of the imported pcolors represented by comparing it to the figures in Hughes et al. (2007) and its data supplement.

ask patches [ ifelse pcolor = white [ set p_ext 0 ] [ ; 1) tropical forest = 64.1 ; 2) warm-temperate forest = 54.9 ; 3) temperate forest = 43.9 ; 4) boreal forest = 44.7 ; 5) savanna and dry woodland = 44.4 ; 6) grassland and dry shrubland = 27 ; 7) desert = 27.5 ; 8) tundra = 18.6 ; 9) land ice = 9.4

5

136

We created this PNG using layer 8 of the data supplied as a supplement with Hughes et al. (2007). It can be found here: https://archaeologydataservice.ac.uk/archives/ view/valdes_nerc_2006. See the ABMA Code Repo for the PNG map and the R script to extract other time slices from this dataset and to export PNGs for them. Thanks to Matt Harris for help with the R code.

Chapter 4: Mobility Algorithms .

if pcolor = 44.7 or pcolor = 18.6 or pcolor = 9.4 [ set p_ext 1 set pcolor brown ]

CODE BLOCK 4.14 (cont.)

if pcolor = 27.5 [ set p_ext 0.07 set pcolor yellow ] if pcolor != brown and pcolor != yellow [ set p_ext 0.01 set pcolor green ] ] ] ... Create a few turtles in setup and set their coordinates to eastern Africa (inspect a patch to get the pxcor pycor ). Create a slider in the INTERFACE tab for p_cr (which is the same as the old pop_growth parameter), and set it to Stepping Out ’s default value of 0.04. The rest of the code below is slightly modified from chapter 1, but you should see that the basic structure is still the same. to go ask turtles [ if random-float 1 goodsB [ let sellers turtles with [ goodsB > goodsA and goodsB >= 0 ] if any? sellers [ ask one-of sellers [ set goodsB goodsB - 1 set goodsA goodsA + 1] set goodsB goodsB + 1 set goodsA goodsA - 1 ] ][

Chapter 5: Exchange Algorithms .

let sellers turtles with [ goodsA > goodsB and goodsA >= 0] if any? sellers [ ask one-of sellers [ set goodsA goodsA - 1 set goodsB goodsB + 1 ] set goodsA goodsA + 1 set goodsB goodsB - 1 ]

CODE BLOCK 5.1 (cont.)

] ] Here, we asked agents to aim to have an equal amount of each good, but this is just the simplest baseline. In the real life it would be rare for the utility of one item to be exactly equal to another item, which brings us directly to the laws of supply and demand. S U P P LY & D E M A N D

The most fundamental extension of the null model above is the notion that humans sell and buy material goods depending on their needs, thus their trading is governed by the laws of supply and demand. A general rule of capital is that although buyers want to buy and sellers want to sell, what is in demand may not always match what is available, and not everyone will go home satisfied. In the first chapter of Hamill and Gilbert’s 2016 textbook in agent-based economics,2 the authors show a simple model of a market where agents can buy goods they need, such as fruit. We recreate it here very closely but with a small archaeological twist of trading pottery. The model consists of a few traders with stocks of various pot types, and more numerous buyers with individual shopping lists. Both are drawn randomly from a global list of pottery types: goods . Not every 2

Null models are often just one step simpler than you think is necessary to model your system. They provide a baseline output for comparison to the actual model dynamics you want to evaluate. Model: Market by Hamill and Gilbert . ABMA Code Repo: ch5_supply_demand

You can download the book, courtesy of the authors: https://hamill.co.uk/lynnehamill/abm-in-economics. 159

PA RT I I : L E A R N I N G TO R U N

Figure 5.1. Screenshot of the original Market model. Shoppers choose products available at different traders represented as houses.

. CODE BLOCK 5.2

seller will have all items a given buyer needs, so buyers will have to shop around (fig. 5.1). globals [goods] breed [ buyers buyer ] buyers-own [ shopping-list my-home ] breed [ sellers seller ] sellers-own [ stock ]

. CODE BLOCK 5.3

. When you see unfamiliar primitives in the following code blocks, check the NetLogo Dictionary.

160

This is a classic example where using two breeds of turtles (sellers and buyers) makes coding much easier. Each breed has a distinctive set of behaviors and variables, but they also have some in common, for example, goods . We usually differentiate them with color and shape (fig. 5.2). to setup ca set goods [ "potA" "potB" "potC" "potD" "potE" "potF" "potG" ]

Chapter 5: Exchange Algorithms

Figure 5.2. Screenshot of the modified Market model. As in the original model, shoppers are represented as people and traders as houses, but we have many more shoppers, and traders can be differentiated by their color.

ask n-of 7 patches with [count turtles-here = 0] [ sprout-sellers 1 [ set shape "house" set stock n-of 3 goods ]] ask n-of floor ( count patches * 0.5 ) patches with [count turtles-here = 0] [ sprout-buyers 1 [ set shape "person" setxy random-pxcor random-pycor set shopping-list n-of 5 goods set my-home patch-here ]] reset-ticks end

. CODE BLOCK 5.3 (cont.)

Now we will ask buyers to walk from one seller to another until they find all the items on their shopping list. Once that is done, they can go back home, and we remove that agent from the simulation.

161

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 5.4

.

The notation -> indicates an anonymous procedure, in this case with the temporary variable i taking on the values of their shopping lists.

to go ask buyers [ let target one-of sellers move-to target let purchases filter [i -> member? i shopping-list] [stock] of target foreach purchases [i -> set shopping-list remove i shopping-list] if length shopping-list = 0 [ move-to my-home die ] ] if count buyers = 0 [stop] tick end

Obviously, people in the past did not store broken pots in their cellars. It’s just a placeholder name. Be aware, though, that “controversial” variable names can occasionally draw critique even if they don’t change the functionality of the model.

162

The command filter takes two variables, a condition structured as a reporter (using an anonymous procedure here) and a list (the target’s stock list), then returns a reduced list with each item for which the condition was true. In this case, the condition was that each item in the stock was also a member? of the shopping-list . This constitutes the basic building block for a supply–demanddriven model. Here, the supply of sellers is unlimited; buyers know the locations of shops and have unlimited time to do their shopping. Thus, in the end everyone checks off all items from their shopping lists and returns home. Small tweaks, however, will make for a complex model in which some agents will not be able to fulfill their needs. Archaeologists are more concerned than an average economist with what happens to a purchase after the transaction, so we cannot entirely depend on ready-made models from the economic or social sciences. For archaeology an item’s final destination is important because it is what we uncover as part of the archaeological record. Thus, to be able to compare the simulation output with the archaeological record, we need to devise

Chapter 5: Exchange Algorithms additional functionality. Fortunately, just a few changes to the supply– demand model will transform it from abstract to archaeologically useful. First, add a “cellar” to each house (i.e., their currently occupied patch) in which agents deposit the goods they bought. Note that the code block below only shows the lines requiring changes to the code above and their location within procedures. patches-own [ cellar ] to setup ... sprout-buyers 1 [ ... ask my-home [ set cellar [ ] ] ... Now, if we just let buyers deposit all of their shopping in the cellars, we will get a random distribution of pottery in the cellars (since the shopping lists are randomly generated). Instead, we can limit their shopping time and give them a basket to hold items they managed to buy within the allocated time. First, initialize the basket as a list in setup . buyers-own [ shopping-list my-home basket ] to setup ... sprout-buyers 1 [ ... set basket [ ] ... ]

. CODE BLOCK 5.5

. Here, cellar is first initialized for all patches with 0, then buyers make their patch’s cellar a list. Keep track of your data structures!

. CODE BLOCK 5.6

Second, rather than just check goods off the shopping list, add them to the basket (this line should be placed just after let purchases filter... ). foreach purchases [i -> set basket fput i basket]

. CODE BLOCK 5.7

163

PA RT I I : L E A R N I N G TO R U N

. CODE BLOCK 5.8

. CODE BLOCK 5.9

. Above, remainder divides the two numbers but only returns the remainder, not the result of the division. It is commonly used to execute code every X number of ticks instead of every tick.

. CODE BLOCK 5.10

.

Note that we use the primitive one-of with modes cellar , so that if multiple types of pottery are equally frequent only one will be displayed.

Finally, add to the condition under which a buyer goes home, so that the buyer only has three ticks to complete the shopping. if length shopping-list = 0 or remainder ticks 3 = 0 [ We can now deposit the goods purchased from the sellers, and go back to shopping with a new shopping list. Replace the die line with deposit-pots and add a new procedure below: to deposit-pots foreach basket [ i -> ask my-home [ set cellar fput i cellar ] ] set shopping-list n-of 5 goods set basket [ ] end The final pattern of pot distribution can be visualized in many ways, but let’s assume that we want to see the most common type of pottery in each house. to show-distribution let colors [14 24 44 64 84 104 124] ask turtles [ hide-turtle ] ask patches with [cellar != 0][ let most-pottery one-of modes cellar let potcolor position most-pottery goods set pcolor item potcolor colors ] end This code block features a common trick used for lists: using the index ( position ) from one list ( let potcolor position most-

Normally, we spell out colors, e.g., “yellow,” but when grouped in a list, it is easier to refer to them with numbers.

164

pottery goods ) to access a specific variable (e.g., the pottery’s color) in another list ( set pcolor item potcolor colors ). For example, pottery A is the first in the goods list, so reading the index with position , we can retrieve the first color from the colors list. This works because in NetLogo lists are ordered; that is, the order of a list’s

Chapter 5: Exchange Algorithms

Figure 5.3. Model output shows the spatial distribution of the most common pot type in each household.

elements is fixed. Lists are also immutable, meaning that they cannot be directly modified even if you can build a new list from an altered copy of the original. The patterns we simulate will vary depending on whether agents wander at random or know the location of sellers, whether each seller has one unique good to sell or a collection of different types of goods, and whether the number of goods to purchase is unlimited. The resulting map of pottery distribution (fig. 5.3) shows an artificial archaeological record, which gives us an insight as to what kind of exchange processes produce what kind of spatial pattern. This insight can be particularly useful when interpreting spatial distribution of real archaeological material. To make it even more relevant to a particular case study, you might decide to include real topography of the area or known locations of human settlements. Similarly, the demand of agents can be modeled to a higher level of detail, such as by calculating the utility function for each household depending on its needs. For example, already purchased goods and overall budget can lead to interesting patterns in the resulting distribution of goods.

How would you investigate the relationship between the frequency of a given pottery type and the distance to the seller who produced it?

For a thorough introduction to modeling heterogeneous demand, see Hamill and Gilbert (2016, ch. 3).

165

PA RT I I : L E A R N I N G TO R U N

Models of economic interactions tend to be developed to a high degree of detail, so in most cases we may simply pick up existing frameworks and adjust them to the needs of our particular case study, research questions, and data. In those situations, it is often tempting to keep some functionality in the code because that is how it was in the original model. However, ultimately every model should stand on its own, that is, contain only these elements (entities, variables, algorithms) that serve its intended purpose. For example, if you use the supply–demand model above but going back home to deposit the purchases is not necessary for your particular research questions, you should remove it from the code. PRICE-SETTING MECHANISMS

Model: Mercury by Brughmans . ABMA Code Repo: ch5_price_setting

166

In more realistic models of commercial exchange, sellers set their prices based on the information about the market they have at a given moment. This information may not necessarily be accurate or always up to date. Agent-based modeling is particularly well suited for this kind of modeling because it facilitates tracking the individual knowledge of each trader. The simplest way for an agent to set a price for their goods is to take an average of the demand and supply, as far as they know. That knowledge may be based only on personal information (local knowledge) or on information gained from other traders (global knowledge). In the Mercury model (Brughmans 2015; Brughmans and Poblome 2016), local demand of an agent represents the maximum amount that a trader can satisfy of the total consumer demand for pots. During trading, the agent’s demand is decreased by one for every successful transaction. Local supply is modeled as the number of available goods stored from the previous time step or produced by the production centers, and a trader’s demand increases by one every time step, up to the maximum value in this time step. To calculate the price, agents assess a wide network (fig. 5.4). To determine the global (or at least regional) supply and demand, they ask traders in their network for the values of their local supply and demand. The price is then the average demand divided by the sum of average supply and average demand, including the trader’s own knowledge of supply and demand.

Chapter 5: Exchange Algorithms

Figure 5.4. Screenshot of the Mercury model. Trading centers (dots) assess the demand and supply based on information available to them through their commercial network (represented as lines).

.

to-report average-demand let sum-demand sum [ demand ] of known-traders report ((sum-demand + demand) / ((count known-traders) + 1)) end

CODE BLOCK 5.11

. The + 1 is added to include the trader who calls the reporter in the calculations.

to-report average-supply let sum-prod sum [ products ] of known-traders report ((sum-prod + products) / ((count known-traders) + 1)) end to price-setting set price (average-demand / (average-supply + average-demand)) end 167

PA RT I I : L E A R N I N G TO R U N

Figure 5.5. Screenshot of the Edgeworth Box model. Many economic models have a limited or no spatial aspect. Here patches have been used to show the space of possible outcomes: deal rejected by one or both agents or successful deal (light area).

We discuss different types of networks and how to construct them in chapter 8.

Model: Bidding Market by Baker

How to determine which traders are known depends on the type of model. This can be, for example, through spatial proximity—I know what traders close to me are doing—or through a network representation—I know what traders in my network are doing. This price-setting example is very simple, but we can also follow alternative theoretical frameworks, some of which have been translated into agentbased models by economists. Here we will look at a few examples demonstrating the principles of the process. In the Bidding Market model from the NetLogo Models Library (Baker 2017), the buyers and sellers adjust their asking and buying prices on the basis of the success or failure of previous transactions. That change can be executed using different algorithms: • random, in which traders randomly change their prices; • normal, in which both seller and buyer adjust their prices by a small percentage; • desperate, in which the buyer and seller adjust their prices by a higher percentage; and • a combination of all three. For models of generalized market dynamics with price-setting dynamics based on product utility, competition, and profit estimation, see

168

Chapter 5: Exchange Algorithms the models described in Hamill and Gilbert (2016), chapters 5 and 6. In their barter model, agents set the price by individually evaluating the utility of a given product in a barter situation and under different circumstances of supply and demand. The barter model features the basic algorithms for calculating a product’s utility for each agent individually (fig. 5.5). Although the model describes a barter situation, it can be easily translated into any exchange mechanism involving money (Hamill and Gilbert 2016, ch. 5). The basic mechanism for establishing the optimal price based on supply and demand is to repeatedly go through a haggling process between two agents. ask people [ set tempBudget ( goods * priceGoods ) + money ]

Model: Edgeworth Box Game by Hamill & Gilbert . CODE BLOCK 5.12

ask person 0 [ set optimalGoods round ( tempBudget * PersonAPreference / priceGoods ) if optimalGoods < 1 [ set optimalGoods 1 ] set demand ( optimalGoods - goods ) if demand < 0 [ set demand 0 ] if demand > ( goods - 1 ) [ set demand ( goods - 1 ) ] ] set PersonADemand [ demand ] of person 0 ask person 1 [ set optimalGoods round ( tempBudget * PersonBPreference / priceGoods ) if optimalGoods < 1 [ set optimalGoods 1 ] set supply ( goods - optimalGoods ) if supply < 0 [ set supply 0 ] if supply > ( goods - 1 ) [ set supply ( goods - 1 ) ] ] set PersonBSupply [ supply ] of person 1

169

PA RT I I : L E A R N I N G TO R U N

Model: Shops by Hamill & Gilbert Nash equilibrium: a set of agent choices such that no agent can benefit by altering its choice, assuming that the choices of the other agents remain unchanged.

For example, Romanists have been discussing the question of the level of economic integration in the Roman Empire for over a century, but archaeologists have only recently used modeling to address it.

bounded rationality: the idea, first proposed by Simon (1956), that humans will often settle on a “good-enough” solution rather than exert time and resources to find the optimal one.

170

The authors also provide a basic market dynamics model focused on assessing supply and competition from other producers. Companies can try to estimate the level of production of other companies until they arrive at the Nash equilibrium, where none of them needs to change their strategy. The Nash equilibrium is a very useful theoretical concept. In simple terms, it describes a situation in which none of the participants can improve their situation without others changing their strategies—the agents are locked in a specific set of circumstances. This model is too elaborate to present the code in its entirety. However, it is particularly worthy of spending some time on because it translates many economic concepts into ABM language: competition over clients, investment and capacity building, or dynamic adjustment of prices depending on market volatility, etc. (Hamill and Gilbert 2016, ch. 6). Just like other agent-based modeling topics, there is great heterogeneity in how economic interactions are modeled. In some models, reputation, relatedness, and memory feature heavily in how exchanges are established (Crabtree 2015). In others, specialization in one type of good may be the dominant factor (Cockburn et al. 2013). Finally, some agent-based models rely on almost random interaction, like the model we developed in chapter 2 (Romanowska 2018). From the authors’ personal observations in archaeological simulations concerning the deep human past, economic interactions are frequently modeled on a very rudimentary level, often not matching the sophistication of other elements. For example, harvest and soil depletion may be quite realistic, while trade is based on chance interactions alone. On the other hand, models of the Greco-Roman world or other historical periods often represent economic interactions to a much higher degree of detail. This largely stems from the questions researchers are interested in. The one important way in which classic economic models differ from the ABM approach is how they treat imperfect information and the resulting uncertainty. The standard approach sees economic agents as utility maximizing with full and perfect knowledge (unbounded rationality), perfect self-control (unbounded willpower), and only ever considering their own welfare (unbounded selfishness). While these three assumptions work as null heuristics, they fail to describe particularly well the reality we experience in our daily lives, something behavioral economics and new generations of economists are attempting to address (Farmer

Chapter 5: Exchange Algorithms and Foley 2009; Page 2018). Here ABM brings an easy way to loosen these three assumptions of the standard neoclassical model. For example, modeled transactions may be based on an agent’s estimates rather than exact knowledge, and traders can behave stochastically using dynamically updated probabilities. Interestingly, in some cases this makes no difference to the results, while in others it does, making this a highly dynamic field of study (Holcombe et al. 2013; Poledna, Miess, and Hommes 2019). To draw from the vast collections of existing theoretical frameworks requires a fair bit of effort to learn the foundations of economics. However, once an appropriate model is identified, translating already formalized models into ABM and archaeological case studies is a straightforward task. Models of trade and commercial exchange focus on the movement of goods and capital. In most cases they consider the utility of each option and the profit or loss for people involved. However, economic interactions do not happen in a social vacuum—they are often embedded in much more complex networks of social interactions involving status, prestige, trust, etc. In the next section, we will look at a family of models that also deals with exchange but of a social nature. 5.2

Remember, the ability to represent heterogeneity among individuals is a key advantage of ABM over other modeling approaches.

Models of Information Transmission

V E RT I C A L & H O R I ZO N TA L T R A N S M I S S I O N

Cultural evolutionary theory is a growing field of study concerned with how cultural traits are passed between individuals, groups, and generations and how the evolution of those traits shapes culture. The most thorough recent discussion of cultural evolution by Mesoudi (2011) provides a comprehensive background to understanding the concepts. Cultural evolutionary theory’s main framework focuses on cultural transmission (or social transmission), that is, the process of exchanging information between individuals through imitation, teaching, or languagebased communication. This process can be vertical (from parents), horizontal (from peers), or oblique (from individuals of a different generation, e.g., teachers), and it occurs in one-to-one (e.g., parent to child) or one-tomany interactions (e.g., teacher to multiple students). Finally, the transmitted values may be blended (e.g., an average of two values) or discrete (e.g., A, B, C). It is crucial to consider whether to model a given cultural trait

culture: in this context, any information passed between individuals via social transmission (Mesoudi 2011, p. 2).

171

PA RT I I : L E A R N I N G TO R U N

Model: Cultural Transmission Algorithms by Romanowska . ABMA Code Repo: ch5_culttrans . CODE BLOCK 5.13

cultural trait: different content transmitted between individuals: a skill, reference, piece of information, strategy, or particular behavior. . CODE BLOCK 5.15

. CODE BLOCK 5.14

. DON’T FORGET Square brackets indicate a reporter, in this case reporting the value of the cultural trait: cult1 or cult2 .

. CODE BLOCK 5.15

172

through vertical, horizontal, or oblique transmission because each has specific assumptions and will lead to a different rate and characteristic of information diffusion. Some types of information (e.g., related to subsistence) may be predominantly passed vertically from parents to children. Others (e.g., ceramic decoration) may not be as clear-cut—whether we learn them from our family or from peers is far from established. Vertical transmission is the default in NetLogo through the hatch primitive. ask turtles [ hatch 1 ] With hatch , each new turtle is an exact copy of the parent if not specified otherwise; thus, any variable representing a cultural trait will be copied exactly as it is. In vertical cultural transmission models, a common simplifying assumption is that the transmission occurs at birth, thus collapsing the child’s upbringing into a single event. The hatch command takes an optional series of commands for the newly created agent to perform at birth, so we can control their inheritance of cultural traits there. If the child has two parents, you can randomly assign a parent to copy from (e.g., cult1 below); if the trait is continuous, you can take an average (e.g., cult2 ). Uncomment the second line of code to change the model’s behavior from discrete to continuous: let parent1 self let parent2 one-of turtles in-radius 3 hatch 1 [ set cult1 [cult1] of one-of ( turtle-set parent1 parent2 ) ; discrete inheritance ;set cult2 mean [cult2] of ( turtle-set parent1 parent2 ) ; continuous inheritance ] Horizontal transmission does not occur at the moment a new agent is created, but rather needs to be triggered by an event during its life. In its most basic form, a cultural trait is copied at random from any agent in the population: set cult1 [cult1] of one-of other turtles

Chapter 5: Exchange Algorithms This copying event may be triggered by, and limited to, agents in close spatial proximity or related to the agents through other alternative topologies (e.g., within a particular breed or through links in an agent’s social network; see ch. 8): if any? other turtles in-radius 3 [set cult1 [cult1] of one-of other turtles in-radius 3] If you run this code, you will notice that even in situations where the starting population had 50–50 distribution of a cultural trait and copying is entirely random (known as unbiased transmission), very quickly one trait will take off and outcompete the others. This is a well-described phenomenon known as random drift in which some cultural traits become dominant over others as a result of random sampling rather than any inherent advantage they carry (Bentley, Hahn, and Shennan 2004). BIASED SOCIAL LEARNING

In most cases though, social learning does not happen at random. What to copy, or who to copy from, is usually a deliberate or culturally mediated decision. We can divide the modes of so-called “biased” social learning into three types following Mesoudi (2011, p. 57): content bias, frequency bias, and payoff bias (fig. 5.6).

. CODE BLOCK 5.16

random drift: random change in the frequency of traits. Often occurs in small populations. These choices about which mode of transmission to use are part of the model’s ontology, which we discuss in detail at the end of this chapter.

Content Bias Certain choices are simply better or more attractive than others. For example, some subsistence strategies may produce better caloric returns, or a given cultural trait may be simply more attractive to buyers (e.g., painted pottery vs. plain pottery). Similarly, innovations need to possess certain features that give them a relative advantage to replace existing technologies. Whether the agents are able to correctly assess the difference in utility between different options remains an important consideration in this type of model, but one of the distinguishing features of ABM is that it allows for imperfect information and resulting erroneous choices. To model content bias selection, a simple approach is to treat the utility of each cultural trait as a direct representation of its probability of being copied (the more I like something, the more likely I’ll buy/follow/adopt

“Unbiased” or “neutral” transmission means “random,” like in the previous examples where the value of the trait did not impact its transmissibility.

In the case of two options that sum to 1, they can be described as optionA and 1−optionA.

173

PA RT I I : L E A R N I N G TO R U N

Figure 5.6. Different transmission types will result in different trait frequencies. Top, from left: vertical transmission, content bias. Bottom: conformist bias, anticonformist bias. Note that these models include mutation, which is responsible, for example, for the reemergence of the cultural trait in the anticonformist scenario.

. CODE BLOCK 5.17

For longer trait lists with probabilities, look at the ROULETTE WHEEL selection in the Rnd extension.

174

it). Since the value of each preference is arbitrary, this can be done using a simple list of the probability of options. Here we just use the probability of the first trait, though we could nest ifelse statements if there were more traits or if they did not sum to one: to content-transmission let cult_traits (list ask turtles [ ifelse random-float [ set cult1 [cult1] [ set cult2 [cult2] ] end

0.7 0.3) 1 < first cult_traits of one-of other turtles ] of one-of other turtles ]

If the traits are mutually exclusive—that is, if you can have either one or the other—then this can be integrated through a set of nested ifelse loops. Note that here we are assuming binary trait states such that values are either 0 or 1, rather than using a continuous variable.

Chapter 5: Exchange Algorithms .

to content-transmission-exclusive let cult_traits (list 0.7 0.3) ask turtles [ ifelse random-float 1 < first set cult1 [cult1] of one-of ifelse cult1 = 1 [set cult2 ][ set cult2 [cult2] of one-of ifelse cult2 = 1 [set cult1 ] ] end

CODE BLOCK 5.18

cult_traits [ other turtles 0][set cult2 1] other turtles 0][set cult1 1]

You may decide to use a content bias algorithm in any context— economic, social, or cultural—in which one option is inherently superior. Depending on what the agents are trying to maximize, this may be due to: • price (cheaper vs. more expensive); • quality (better vs. worse); • personal preference, such as aesthetics, cultural association, or religious beliefs (I like it vs. I don’t like it); and • novelty and conservatism (new vs. known). In their work, Powell, Shennan, and Thomas (2009) model transmission leading to accumulating cultural skill in a spatially structured population during the late Pleistocene. They use a combination of vertical and oblique transmission with an important content bias, as their agents choose the most skilled individual to copy from. The availability of teachers to copy from varies depending on model parameters that govern the density of the population and migration. With this model they explain how behaviorally modern cultural traits heralding the onset of Upper Palaeolithic seem to appear and disappear repeatedly in different regions due to the variation in population density and mobility.

Model: Cumulative Cultural Evolution Demographic by Powell et al.

175

PA RT I I : L E A R N I N G TO R U N

Frequency Bias: Conformist Bias, Anti-Conformist Bias

conformist bias: probability of adopting a cultural trait proportional to its popularity in the population. The inverse is known as anti-conformist bias.

. CODE BLOCK 5.19

. CODE BLOCK 5.20

Conformist and anti-conformist biases are particularly useful for modeling the spread of beliefs and innovations.

176

To study peer influence, researchers often turn to frequency bias. The main premise behind this model is that in certain social situations, people decide on an option based on its popularity. Sometimes popularity is regarded as positive (conformist bias), as in I want what other people have , and sometimes popularity is regarded as negative (anti-conformist bias), as in I find th item particularly valuable because no one h it, for example, luxury goods. Mathematically, these are very easy to express, and their use is almost ubiquitous. As in the content bias example, each cultural trait has an associated probability of being copied; however, rather than being arbitrary, it is expressed as its frequency within the population. Assuming that 0 signifies the lack of a cultural trait and 1 its presence in each agent’s cultural repertoire, its frequency is equal to the mean value of the population. For example, in a population of ten agents, if four of them have the trait, its frequency will be 0.4(0 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 1)/10 = 0.4. to frequency-transmission-conf ask turtles [ if random-float 1 < mean [cult1] of turtles [ set cult1 [cult1] of one-of other turtles ] ] end The only difference for anti-conformist bias is that it uses the inverse of the frequency: ... if random-float 1 < 1 - mean [cult1] of turtles ... Frequency-based bias does not take into consideration any inherent qualities of the selected trait, only its popularity. Thus, it is often combined with content bias. In those cases, the probability of copying is calculated as a function of frequency and utility. Biases of different types can be combined to reflect the complexity of individual decision-making shaping population-level trends.

Chapter 5: Exchange Algorithms

Payoff or Model-Based Bias The two previous cultural transmission mechanisms assumed a high level of knowledge (e.g., agents knew the frequency of the trait or its value). This assumption can be easily loosened (e.g., agents may calculate frequency only among closest neighbors), but in some cases the utility of a given trait cannot be directly or reliably measured at all. Instead, individuals need to depend on a proxy to evaluate whether a particular trait is beneficial. These cases are often modeled with a so-called “payoff” or “model-based” bias. An example of this is copying the strategy of the most successful individual (success bias) or individuals with a higher level of prestige (prestige bias). In short, it is not a trait that is assessed but the individual who carries it. Model-based biases have simple implementations in NetLogo. For example, success bias can be modeled in the following way: to success-transmission ask turtles [ set cult1 [cult1] of one-of other turtles with-max [success] ] end In this case the variable success is dynamically allocated depending on the model. This could be the number of items collected by an agent, the overall profit of its business, or the size of stored resources depending on what is considered a “success” in a given situation. Prestige bias represents a specific type of success bias in which an individual or a group of agents is considered “special” and their level of success is usually static. This may be as a result of some inherent features (e.g., being a member of the elite) or due to perceived individual qualities (e.g., level of a skill). For example, copying individuals with a higher level of a skill (i.e., teachers) is an established form of learning. Other types of biases will follow the same pattern, replacing the success variable with age (age bi ), affinity or belonging to the same group/tribe or community (similarity bi ), etc. In all of these types of bias, the observed characteristics of the other agent are treated as a proxy (model) for the “quality” of a cultural trait or strategy, and not the trait itself. This creates a framework in which agents

model-based bias: probability of adopting a cultural trait based on the characteristics of individuals who carry this trait. . CODE BLOCK 5.21

. As success is a turtle variable, create it in turtles-own , initialize the values in setup , and update dynamically in go .

Because we haven’t linked success with any particular value of the cultural trait, you’ll see how, in different runs, it trends toward either 0 or 1 in the population.

177

PA RT I I : L E A R N I N G TO R U N

may erroneously copy traits that do not carry an advantage only because a successful individual happened to have them—similar to how people tend to copy the fashion choices of celebrities even though their probability of becoming rich and famous thanks to new shoes is nil.

mutation: a random change of an element in the genome. Here used to denote a random change in the value of a cultural trait.

Boolean: a variable with only two possible values (e.g., TRUE or FALSE, 0 or 1, heads or tails). Also called a binary variable. . CODE BLOCK 5.22

M U TAT I O N , I N N OVAT I O N & E R R O R

The roots of the cultural evolutionary framework lie in genetic evolutionary theory, from which it inherits many concepts. A good example is mutation. Most cultural transmission models will include a small chance (usually in the vicinity of 0.001) of a trait randomly changing its value. This may be coded as a separate process or included in the copying algorithm as a “copy error probability.” In a cultural context, cultural mutation may represent an instance of individual learning (an innovation) where a new value of a trait is “discovered” as the emergence of a completely new cultural trait or a random change in the value of an existing one. Innovation can also mark a random loss of a trait. Depending on how cultural traits are represented, mutation may flip the value of a Boolean trait (e.g., 0 to 1) or modify it if the trait is represented as a continuous value (e.g., 1.10 changes to 1.09). In the latter case, the size of the change also needs to be specified, either as a fixed amount or by drawing from a distribution. to mutation-boolean ask turtles [ if random-float 1 < 0.001 [ ifelse cult1 = 0 [set cult1 1][set cult1 0] ] ] end to mutation-continuous ask turtles [ if random-float 1 < 0.001 [ set cult1 random-normal cult1 0.1 ] ] end

178

Chapter 5: Exchange Algorithms In the second example above, random-normal takes the current value as the mean and a standard deviation as a fixed parameter and returns a random number from within that probability distribution. In Xue (2013), the size of the cultural mutation (i.e., the standard deviation) was also modeled as a trait that was subject to mutation. This small shift resulted in some very unexpected dynamics and important conclusions regarding the evolution of cultural variability.

Parameters such as probability of mutation or the standard deviation can be set with a slider in the INTERFACE tab.

C U M U L AT I V E C U LT U R A L E V O L U T I O N

So far all of the examples involved one or a few cultural traits passed from one individual to another. These basic building blocks can be used to construct highly complex models leading to cumulative cultural evolution. One of the most common ways of expanding the scope of these models is giving agents a string of traits or adaptations (think of this as a “cultural genotype”). turtles-own [ cultgen ] to setup ... crt n-agents [ ... set cultgen n-values 5 [ i -> one-of [0 1] ] ] ... ] Agents can then assess their fitness, similarity to each other, attractiveness, etc. on the basis of their cultural genotypes. To compare two lists where the position of each item is significant, we can use Hamming distance (Bookstein, Kulyukin, and Raita 2002). Imagine we have two lists representing two agents’ cultural genotypes: 0

1

1

0

1

1

0

1

0

1

We can calculate the difference matrix by placing 1 whenever the two items of the list differ and 0 when they are the same.

. CODE BLOCK 5.23

Hamming distance: metric used to compare two sequences of the same length, which sums the number of differences in each position. . Other similarity measures that can be used for comparing sequences are Edit distance and Jaccard distance.

179

PA RT I I : L E A R N I N G TO R U N

1

. CODE BLOCK 5.24

Model: Patagonian Hunter–Gatherers by Barceló et al. If it is the assemblages being compared, then the Brainerd–Robinson coefficient of similarity is a well-established choice (Peeples 2011; Peeples and Haas 2013). You can find alternative implementations and other cultural transmission algorithms in the Model Zoo list at the end of the chapter.

Model: Prestige Trade by Graham . Model: Cultural Trade by Carrignon et al. 180

1

0

0

0

Hamming distance is the sum of these differences. In this example, it is equal to 2 (i.e., 1 + 1 + 0 + 0 + 0) since only the first two elements of the lists differ from each other. In NetLogo this can be implemented as: to-report hamming-distance [ list1 list2 ] report length remove true (map [[?1 ?2] -> ?1 = ?2 ] list1 list2) end Hamming distance can be used to help agents determine whether they are close enough culturally to cooperate or whether the set of adaptations codified in the list is actually advantageous in a given environmental setting (here the cultural genotype would be compared to an ideal sequence representing a perfect adaptation). For example, Barceló et al. (2015) used a cultural genotype to model alliances and territoriality among Patagonian hunter–gatherers. This is only one of the many ways to model some aspects of cumulative cultural evolution—here we have provided key algorithms to serve as building blocks for more complex models. However, some recent reviews and applications of cultural transmission can help shed light on the approaches used here. Eerkens and Lipo (2007), for example, provide an argument for using cultural transmission models to understand changes in material culture over time. These approaches are employed by Crema, Kandler, and Shennan (2016) and simulated to examine the ways that design motifs of Neolithic pottery change over time. These simulations complement mathematical models by Kandler and Laland (2009) that examined changes in cultural diversity and look at the impact of independent invention on traits in a population. O’Dwyer and Kandler (2017) further examine neutral evolution’s impacts on culture and simulate how critical innovation in the form of anti-novelty bias is in cultural evolution over time. Finally, Henrich (2001) suggests that biased transmission is responsible for most cultural change. Turning back to the topic of trade, Graham (2005) has combined economic and cultural exchange frameworks into a model of economic exchange where agents build their reputation and only trade with partners of similar status (prestige bias). Carrignon, Brughmans, and Romanowska

Chapter 5: Exchange Algorithms (2020) similarly combined economic interactions with cultural transmission during which traders learn commercial strategies from each other. Cultural evolution studies is a rapidly expanding field in computational archaeology and other disciplines, such as ecology (Smolla et al. 2016). It is worth understanding the basic premises of the framework and following new developments. Much of the cultural evolutionary literature is based on numerical modeling rather than ABM, but with a little practice, most numerical models can be easily converted to ABM and expanded upon to address new questions. PUTTING TOGETHER A MODEL OF C U LT U R A L T R A N S M I S S I O N

To help you solidify many of the above concepts, we will examine a model by Premo (2014). His abstract model of cultural transmission examined the shifting patterns of artifact frequencies through time. The model follows a population where unbiased transmission occurs between generations of agents. The copying of cultural variants from the older generation to the younger generation occurs at random (i.e., it is not parent-to-offspring) at a rate of 1−µ with copying errors occurring with a probability of µ. There is no horizontal transmission. At each step the older generation dies and a new generation is born, thus changing the frequency of different cultural traits, i.e., artifact types, in the population over time. Let’s look at this model’s code in a little more depth: to learn let teacher one-of turtles with [age = 1] set t1 [t1] of teacher ask teacher [set taughtThisGeneration (taughtThisGeneration + 1)]

Model: Time-Averaging by Premo (2014) ABMA Code Repo:

ch5_teaching

. CODE BLOCK 5.25

if random-float 1 < mu [ set t1 nextNovelVariant set nextNovelVariant nextNovelVariant + 1 ] set color t1 end 181

PA RT I I : L E A R N I N G TO R U N

Figure 5.7. Premo (2014) shows that the number of unique variants, that is, cultural diversity, tends to decrease precipitously over time. While mutation allows for introductions of new traits, these do not persist, leading to an increase in homogeneity over time.

You can find several diversity measures, such as Shannon’s index, in the original version of the Time-Averaging model.

TIP We recommend installing multiple NetLogo versions as needed. One each of the last major versions 4.1.3 and 5.3.1 as well as a recent release of 6.x.x should cover it.

182

Each newly hatched agent picks a random teacher to copy a trait from. Then an agent has a probability of introducing a new variant of a novel trait due to a copy error with a probability µ, which is set by a slider. If you set a low probability of mutation (i.e., µ less than 0.05) and any number of agents, we see that initially the cultural repertoire was highly diverse, as each had a unique variant. Under these parameter values, the model shows a dramatic decrease of diversity over time. Even with randomly mutated traits appearing in the population, they tend not to “stick.” Instead, these traits tend to appear for one or a few time steps, as indicated in the “# of Unique Variants” axis of figure 5.7, and are rarely passed along for more than a few generations. These results may suggest that time averaging of traits can lead to similarly low diversity in assemblages from the process of unbiased transmission. Note that if you open this model in a version of NetLogo other than 5.0.2 (the version Premo used to write it), you will see a message about upgrading the model (fig. 5.8). Usually NetLogo takes care of the changes needed, but sometimes the differences between versions are too great. For older models, it’s sometimes possible to upgrade to version 6.x.x by opening and saving them first in 4.1.x, then 5.1.x, then 5.3.x, and

Chapter 5: Exchange Algorithms

Figure 5.8. If you attempt to open an old model in a newer version of NetLogo, the software will give you this error message. Follow NetLogo’s Transition Guide to ensure that the old model works in your newer version of the software.

only then in 6.x.x. If this doesn’t work, see the NetLogo Transition Guide for help upgrading your models.3 5.3

The SIR Family of Models

Surprising as it may sound, one of the best ways to represent the spread of information over a population is with epidemiological models. Transmittable diseases and cultural traits share many similarities in the way they jump from one person to another. First, there needs to be a form of interaction for the transmission to occur—in epidemiology this usually requires a physical interaction, which until the onset of modern telecommunication technology was also the case for cultural transmission. Second, different variants have different transmission rates and therefore spread at different rates—the common cold and silly memes on social media share the quality of being easily transmissible. Finally, the rate of infection may depend on specific characteristics of groups of agents (e.g., age) which determines their susceptibility. For example, children tend to catch colds and memorize names of dinosaurs with more ease than their parents. 3

An unexpected feature of the COVID-19 pandemic is that we have all acquired an unprecedented level of understanding of epidemiological models. Many of their features (e.g., the R0 number) can be adapted to studying cultural phenomena.

It’s NetLogo convention to mark Boolean variable names with a question mark, such as susceptible? . This also applies to INTERFACE switches since they are either TRUE or FALSE.

https://ccl.northwestern.edu/netlogo/docs/transition.html 183

PA RT I I : L E A R N I N G TO R U N

Model: Susceptible–Infected– Recovered (SIR) . ABMA Code Repo: ch5_SIR . CODE BLOCK 5.26

. CODE BLOCK 5.27

.

You can use even this basic model to see how agent mobility has a dramatic impact on the shape of the infection curve and the final outcomes.

The most commonly used family of models is based on a standard simulation framework known as the SIR (Susceptible–Infectio –Recovered) model (Weiss 2013). Sometimes you’ll see these called SEIR models, with the E equating to “exposed” or some other variant. Originally expressed as a set of differential equations, the SIR framework can be easily translated into ABM, and still provides the base for many sophisticated epidemiological models today (e.g., Hammond et al. 2021). In an SIR simulation, agents exist in one of three states: Susceptible (healthy), Infectious (ill and spreading disease), or Recovered (dead, immune, or back into Susceptible depending on the characteristics of the particular illness) (fig. 5.9). In a cultural context, we can translate this into “potential adopter of a trait,” “carrier of a trait,” and “rejector.” To set up the model, you need a population of agents with three variables: turtles-own [ susceptible? infectious-timer recovered? ] At each time step, a proportion of agents set with a mobility slider moves ( mobility ), and they can also transmit (infect) and recover. The key dynamics of this kind of model are the transmission and recovery mechanisms. This is the simplest representation: to move ask n-of floor (mobility * count turtles) turtles [ rt random 360 fd 1 ] end to infect let carriers turtles with [ infectious-timer != 0 ] ask carriers [ let susceptible-neighbors turtles with [ susceptible? ] in-radius 2

184

Chapter 5: Exchange Algorithms

Figure 5.9. The evolution of an epidemic. Initially the population of infected agents increases rapidly. The system then crosses through an inflection point and the transmission decreases when there is insufficient susceptible population to infect. In this case the decrease is due to acquired immunity but other interventions, e.g., vaccines, can similarly reduce the proportion of susceptible individuals.

185

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 5.27 (cont.)

if any? susceptible-neighbors [ ask one-of susceptible-neighbors [ set susceptible? False set infectious-timer 10 set color red ] ] ] end to recover ask turtles with [infectious-timer > 0][ ifelse infectious-timer > 1 [ set infectious-timer infectious-timer - 1 ][ set infectious-timer 0 set recovered? True set color yellow ] ] end

Most SIR models include a probability, for infected agents, of dying. Try adding an age-specific susceptibility that limits who is open to learning new things. How does this affect the transmissibility of new innovations?

186

To modify the way transmission and recovery proceed, the modeler could add a probability of transmission and recovery to be, for example, randomly distributed throughout the population, or dependent on another variable (such as age, popularity, utility, etc.). The cultural transmission algorithms discussed above are of great use to represent the particularities of the studied process. Similarly, distributing agents on a network instead of along continuous space can change the rate and other characteristics of the spread. You will find these extensions implemented in several models in the NetLogo Models Library, such as, epiDEM Basic, Spread of Disease, or Vir on a Network. The SIR family of models is a highly flexible framework that can be adjusted to almost any problem involving transmission of information at a large scale. Importantly, the concepts involved are quite intuitive,

Chapter 5: Exchange Algorithms and with the recent increase in reporting on epidemiological models in the media, the general understanding is high even among nonexperts. This makes it relatively easy to explain its dynamics to a general social science audience. A pioneering example of the application of a simple SIR model to archaeology is Graham (2006). The author released information on a transport network constructed on the basis of the Antonine Itineraries to investigate the rate of information spread through different Roman provinces. The simulation revealed how in some provinces (e.g., Iberia, Gaul) information spread at a different rate than in others due to the structure of their transport networks. 5.4

Model: The Antonine Itineraries by Graham

Ontology Building & Parsimony

A critical aspect of model development, as important as coding and debugging, is learning how to choose what to code into the model and what to leave out. It is a challenging process, and ideally you want to have the full ontology described before you even start to code. In practice, it often develops throughout the project with elements being added or removed until the last moment before running the simulation. There are two aspects that can help us decide what the artificial world we create should include. The first is your research questions, which should be well developed before you sit down to code. The second is the principle of parsimony. We will look at them in turn. A model is by definition a simplification of reality. It follows from this that any one system can be represented in a multitude of different models, none of which is more “correct” than the others. Think of a city and how it could be depicted on a map as a series of streets and buildings, or as a density map of different economic activities, or as a network of people who live in it. Ultimately, how we want to represent the system will depend on what we want to learn from that representation. If we are interested in traffic and congestion, then the streets/buildings map probably best meets our goals. Less so if we use an SIR model to evaluate the most effective epidemic controls for an urban area. Thus, when deciding what to include in your model, the research questions are the determining factor. The principle of parsimony means that we should strive not to overcomplicate the model to produce the desired output. For example, we could

ontology: the full representation of the model’s world, including names and definitions of entities and their categories and properties, the relationships between entities, and the rules of behavior. parsimony: the idea that a model should have as few details as possible while still representing the modeled phenomenon. Often defined as the Occam’s razor principle.

Research questions are sometimes compared to a knife used to carve the simulation into the desired shape and size.

187

PA RT I I : L E A R N I N G TO R U N

Even a simple model with 5 parameters where 3 values need to be tested for each would require 243 runs. Times 100 to account for stochasticity in the model, and we’re looking at weeks of experiment runs clogging your computer.

188

imagine a trade model where including a number of goods, each with a specific quality and price, might increase the realism of the model. Likewise, we could add the transport cost, divided between the land and the sea routes as well as the season. But would these changes, in fact, enable us to understand the dynamics of commercial exchange better? Or would they just add meaningless noise? It is also often difficult to establish where to stop in the quest for more realism. What about transport on donkeys versus carts? Or tableware traveling as part of foodstuff cargo? In the Brughmans and Poblome (2016) model, the transport cost was not accounted for explicitly, yet the authors demonstrate convincingly that the tableware data collected over the eastern part of the Roman Empire indicates a relatively high level of economic integration in the region. We could go on forever adding more and more details to the simulation. The answer to “Could you make the model do X?” is always yes, but the price of more details comes at the stage of experiment design when we need to run all combinations of parameter values. The number of scenarios tends to increase exponentially, making it difficult not just to properly sweep through the parameter space but also to understand and interpret the results (see ch. 9 for experiment design). Instead, by simplifying the model down to the most parsimonious elements, we can demonstrate the most significant mechanisms that guided the whole system. In future iterations of the model, we can then add new factors, behaviors, or specific data and explore the dynamics further. However, we will only be able to assess their impact if we have a baseline, that is, the most parsimonious model with which to compare these more evolved versions. Another way of thinking about which of all possible elements to include within a model is to decide what set of model elements is both necessary and suffici t to explain the phenomenon you want to study. Each element should be necessary in the sense that if you removed it, the model results would no longer answer your research question. Moreover, the combination of elements in the model needs to be sufficient to produce results that are comparable to the archaeological record. For example, adding subsistence strategy to a cultural transmission model of changes in pottery decorations is probably not necessary, but removing family ties could result in

Chapter 5: Exchange Algorithms a model that is not sufficient to differentiate between vertical vs. horizontal transmission. Upholding principles of parsimony—keeping a model as simple as possible—is one of the best practices of agent-based modeling. By stripping away unnecessary complexity, your model will be easier to examine and easier to reproduce, and can be built upon when new questions arise. In this way, you can see how building simple models of movement, exchange, or subsistence—as we did in the first section of the book (chs. 1–3)—can provide a parsimonious backdrop for many questions related to archaeology: How do exchange mechanisms influence trade, mobility, or demography? The algorithms in this part of the book (chs. 4–6) can be used to build your own models from such a simple base. 5.5

This is one of the best practices of agent-based modeling (known as KISS; see Axelrod 1997).

Summary

In this chapter we looked at the many different ways in which economic and cultural exchange can be modeled. The fields of economy and cultural evolution have produced many extensions to the basic algorithms we have presented here. A deep dive into the literature is warranted whenever a model involves transmission between agents, be it of economic nature or of information. Economy, in particular, is a discipline with long-standing theories, and it is likely that a particular type of commercial interaction you would like to model already has a large body of theory and literature behind it. Finally, we touched on one of the most challenging phases of model development: ontology building. It is one of the most critical pieces of model development. Devising a clear ontology early on will enable better code development and experiment design and analysis, and it will make your task of communicating your results to your audience much easier. In the next chapter, we will return to the topic of subsistence and explore different foraging and harvesting algorithms. We’ll also talk about how to parameterize your model and where to look for realistic parameter values. As you continue, keep in mind the practice of finding theoretical and formal models from other disciplines, as well as the need for well-defined ontology as we begin to parameterize our models. A clear road map will make picking parameter values much easier. E

189

PA RT I I : L E A R N I N G TO R U N

End-of-Chapter Exercises 1. In chapter 3 agents collect resources. Extend the model by allowing them to trade with each other. 2. Now, let them record locations in which they have come across the highest density of resources. They can now exchange this information with each other. Use different cultural transmission algorithms to model that process. 3. If you’re up for a challenge, try using the previous examples and algorithms developed so far to implement a classic model by Geertz (1978). In this model, individuals will establish a relationship with a seller. How does long-term relationship tracking change the economic model? 4. In chapter 4 we suggested an end-of-chapter exercise combining multiple models. Take that exercise and strip it down to the most parsimonious model to answer a question at hand. Is it difficult to remove pieces you already added to your model? Trade & Exchange Model Zoo ▷ The Antonine Itineraries S. Graham. 2006. “Networks, Agent-Based Models and the Antonine Itineraries: Implications for Roman Archaeology.” Journal of Mediterranean Archaeolo 19 (1): 45. doi:10.1558/jmea.2006.19.1.45 Code: http://www.graeworks.net/2013/05/16/antonine-itineraries-abm/ ▷ Cultural Trade S. Carrignon, T. Brughmans, and I. Romanowska. 2020. “Tableware Trade in the Roman East: Exploring Cultural and Economic Transmission with Agent-Based Modelling and Approximate Bayesian Computation.” PLOS ONE 15, no. 11 (November): e0240414. doi:10. 1371/journal.pone.0240414 Code: https://osf.io/s5mdw/

190

Chapter 5: Exchange Algorithms ▷ Market, Edgeworth Box Game, and Shops L. Hamill and N. Gilbert. 2016. Agent-Based Modelling in Economics. Chichester, UK: Wiley. doi:10.1002/9781118945520 Code: https://hamill.co.uk/lynne-hamill/abm-in-economics/models ▷ Mercury Roman Trade T. Brughmans and J. Poblome. 2016. “Roman Bazaar or Market Economy? Explaining Tableware Distributions in the Roman East through Computational Modelling.” Antiquity 90 (350): 393–408. doi:10.15184/aqy.2016.35 Code: https://www.comses.net/codebases/4347/releases/1.1.0/ ▷ Prestige Trade S. Graham. 2005. “Agent-Based Modelling, Archaeology, and Social Organisation: The Robustness of Rome.” The Archaeological Computing Newsletter 63:1–6 ▷ Simple Economy U. Wilensky and W. Rand. 2015. An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. Cambridge, MA: MIT Press, April. Code: https://ccl.northwestern.edu/netlogo/models/SimpleEconomy ▷ Susceptible—Infectious—Resistant (SIR) C. Yang and U. Wilensky. 2011. NetLogo EpiDEM Basic Model. Evanston, IL. Code: https://ccl.northwestern.edu/netlogo/models/epiDEMBasic ▷ Time-Averaging L. S. Premo. 2014. “Cultural Transmission and Diversity in TimeAveraged Assemblages.” Current Anthropolo 55, no. 1 (February): 105–114. doi:10.1086/674873 Code: https://www.journals.uchicago.edu/doi/full/10.1086/674873

191

6 SUBSISTENCE ALGORITHMS: WHY DO SOME SOCIETIES THRIVE WHILE OTHERS FADE?

6.0

Introduction

One of the largest topics in archaeological modeling is human subsistence and the myriad ways in which human groups adapt to different environments. Indeed, some of the defining features of H. sapiens are related to the flexibility in subsistence strategies, such as the ability to develop complex cultural and social solutions to acquire and manipulate what we consume (e.g., using fire, domestication of animals, etc.), to plan for the future, and to provision other members of one’s community. While nonhuman animals do some of this, too—ants farm fungus, corvids store nuts for the future, nonhuman primates provision their young even past infancy—human societies do this at unprecedented scale, do it regularly, and have done it throughout history. Using an agent-based modeling approach, we can examine the relationship between people and their environments, which subsistence strategies were feasible in certain environments, how different food sharing strategies could develop over time, how subsistence and exchange interrelate, and how these can lead to the patterns we detect in the archaeological record. Most subsistence models are built up from the patch level. While much of the prior sections have focused on agent–agent interactions, subsistence questions engage patch–agent interactions (and even patch–agent–agent or patch–agent–patch interactions). This chapter is divided into the core aspects of subsistence models: • • • • •

OVERVIEW ▷ Algorithm zoo: subsistence and resilience ▷ Consumption, subsistence, and resilience strategies ▷ Foraging algorithms ▷ Population dynamics, evolutionary dynamics, and fission–fusion algorithms ▷ Tragedy of the commons ▷ Game theory ▷ Parameterization and model’s input data

general dynamics of resource acquisition; resilience and adaptive strategies; dynamics in foraging behavior; population growth and fission–fusion dynamics; fitness and evolutionary dynamics; and 193

PA RT I I : L E A R N I N G TO R U N

• the Tragedy of the Commons model and fundamentals of game theory. In this chapter, as in previous ones, we show how to code simple fundamental algorithms in multiple ways, working toward more complex models of subsistence. Instead of coding one particular model from beginning to end, we provide relevant sections of published simulations that include subsistence. We begin by covering the Wolf–Sheep Predation model in the NetLogo library. This model forms the basis for several other agent-based models, such as AmphorABM , a model of viticulture in the Pre-Roman Gaul (ch. 9), and Ger Grouper, a model of Mongolian pastoralism, which we also cover here. We introduce the MedLanD models to show how patch degradation can be incorporated into subsistence models. We also cover fission– fusion dynamics from Crema (2013) to show how population dynamics feed off models of subsistence. These fission–fusion dynamics are further explored in several other models, such as the Cardial Neolithic model. Finally, we discuss two important theoretical frameworks that are often considered when modeling subsistence: evolutionary dynamics, such as fitness-based evolution and social dynamics, including the tragedy of the commons and the fundamentals of game theory. You can find the full model bibliography and links to original code at the end of the chapter. Working versions of all models are also available in the ABMA Code Repo.1 We follow these with a discussion on how to parameterize your model, that is, where to find values and their ranges that can be used in your simulations. Parameterization is one of the most critical aspects of model development, as it will impact how your model runs and how you validate it against the archaeological record. This chapter covers quite a lot of ground, but in the end you will have several subsistence models in your repertoire, will understand how and where to build up model complexity in light of data availability, and will begin to examine the robustness of conclusions that emerge from a simulation.

Although there isn’t one canonical textbook for ABM in subsistence studies, Wilensky and Rand (2015) is a good place to start.

Recall that ABMs are particularly useful for computational problems where the agents and environments are heterogeneous. This makes it a great tool for exploring evolutionary processes.

1

194

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch6

Chapter 6: Subsistence Algorithms 6.1

Modeling Resource Acquisition

To model subsistence we must return to economic theory. A basic tenet of economics is that most material resources are limited. In chapter 4, agents targeted cells with a resource they needed, but we did not contend with the depletion of those resources except to mark a cell as “used.” In this section, we will begin to look at how the simple fact of scarcity can impact human behavior. For this, patches will have variables representing the presence/absence or amount of a resource, as well as a way to regenerate, while agents using a patch will need procedures to consume the resources on those patches and from their own stores. The fundamental algorithms that underlie most environmental productivity models can be found in Wilensky’s 1997 model of Wolf–Sheep Predation. Wilensky's model is, itself, an agent-based implementation of the Lotka–Volterra model, which is based on a differential equation. This model illustrates a foundational principle of ecology; namely, that predators and prey oscillate in abundance over time as they engage in trophic interactions. In Wilensky’s implementation, sheep subsist on available grass, while wolves eat available sheep. The feedback between them causes fluctuations of resources (sheep for wolves, grass for sheep) that drive sine wavelike oscillation patterns in their populations. This model can be accessed through the NetLogo Models Library. If you open the code and look at the setup procedure, you will immediately see regeneration times set for grass patches, and that not all patches are productive. Green patches start with the maximum regrowth time, and brown patches have their own grass regrowth clock, which is initialized randomly to avoid all brown patches turning green at the same time (fig. A.4). Next, each entity consumes resources. As the grass grows, sheep eat grass and are, in turn, eaten by wolves. We will start with the grass:

Model: Wolf–Sheep Predation by Wilensky, based on the Lotka–Volterra model . ABMA Code Repo: ch6_wolf_sheep

Choose the sheepwolves-grass model version from a drop-down list in the INTERFACE.

195

PA RT I I : L E A R N I N G TO R U N

Figure 6.0. Screenshot of the Wolf–Sheep Predation model. The population sizes of wolves, sheep, and grass vary over time through linked consumption and regrowth/reproduction cycles. These cycles are known as Lotka–Volterra dynamics.

. CODE BLOCK 6.0

.

The built-in variables color and pcolor are often used to track the current state of the turtle or the patch. They also help to visualize the dynamics of the model.

196

to grow-grass if pcolor = brown [ ifelse countdown 1 [ set energy energy + 1 ] ] end

Chapter 6: Subsistence Algorithms .

to harvest if pcolor = cyan [ set energy energy + harvest-amount set energy energy - harvest-calories if metal >= 1 [ set energy energy + 1 ] ] end to eat-grain set energy energy - 1 end

CODE BLOCK 6.7 (cont.)

.

TIP When testing code, follow each key variable by printing its value in every function to make sure the accounting is correct (e.g., grain does not go into negative values, etc.). INTERFACE plots may also help.

to store-grain set storage storage + energy set energy 0 end At each tick, Gaulish agents choose a fallow field and plant it with grain. Ethnographically, people often hosted beer parties to help with planting costs (e.g., McAllister 2006), so if the agents have wine available, they get an energy boost to reduce the net energy loss from planting. Farmers gain a certain amount of energy from harvested fields. For harvesting, having metal tools helps increase efficiency; thus, if metal is available, agents retain a certain amount of energy (Briggs 2003). Finally, they consume some of their grain, and then store whatever is left (those procedures are in the order listed above in AmphorABM ’s go code). It is important to note that humans are quite particular in that their fate is not always linearly correlated to environmental shifts. We know from history that there were periods during which even the optimal levels of productivity could not maintain human populations. In those cases, we know that other systems were at play to ensure that group’s survival, such as kin and nonkin networks or large-scale trade. In chapter 8, we explore some of the ways in which societal networks can make human groups resilient. Equally important is the agent’s ability to assess the optimal strategy when deciding where to use their energy, for example, during the selection

This model uses colors to differentiate patches and patch states. This is handy when there are multiple agent types and makes it easier to account for all of the changes in foodstuffs/energy/time variables.

205

PA RT I I : L E A R N I N G TO R U N

Figure 6.2. A screenshot of the MedLanD model. Farms cultivate patches as needed, while leaving previously used patches to regenerate in a swidden rotation system. Farms undergo fission if a high energy threshold is reached.

NetLogo is often used as a “simple” version of a model to experiment on while the simulation is developed in a more computationally powerful framework.

206

of a new patch to plant. To understand this, we will switch to a different agent-based model incorporating harvesting and soil fertility. In a study of Mediterranean landscape dynamics and Neolithic farming (MedLanD), Barton, Ullah, and Bergin (2010) developed a model of farming household agents. In their model, agents assess how many plots of land they need based on their household size and the previous year’s yields. They also assess the soil quality and relative location of each patch to make choices about which plots will likely have the greatest yield. The selection algorithm includes the current soil fertility, which degrades with each year of cultivation but replenishes each year that the land is left fallow. The MedLanD ABM also models topsoil erosion and other spatial processes as a result of farming, with greater rates of erosion if land is not left fallow (fig. 6.2). This is done through a tight coupling to the geographic information system GRASS-GIS of Robinson et al. (2018). The main MedLanD model was built in the Java-based DEVS-Suite (Sarjoughian and Zeigler 1998). However, Barton (2014) developed a closely related, though more abstract, NetLogo model. In Barton’s NetLogo version, called Swidden Farming, pcolor is again used to demarcate patch

Chapter 6: Subsistence Algorithms states with shades of green and brown for uncleared forest, active, or fallow fields, and purple and magenta for abandoned or dead farmsteads.2 The choose-land procedure uses a combination of patch and global variables to rank and select new patches to cultivate: to choose-land let hh_num 0 ask households [ set hh_num who ifelse any? other (patches in-radius swidden_radius) with [fertility > 0 and (owner = hh_num or owner = -1)] [ ask one-of ((((patches in-radius swidden_radius) with [owner = hh_num or owner = -1]) with-max [ (fertility * harvest * init_energy / 100) - (farm_cost * init_energy / 100) veg_clear_cost - ((distancexy pxcor pycor) / 5) ])) [ set xval pxcor set yval pycor ] farm xval yval ] [set energy energy - (0.1 * init_energy)] ] end Here, the agent households assess whether there are any available and fertile patches to move to in their search radius. The criteria assessed when choosing the patch with the highest potential yield include fertility , the patch’s energy capacity ( init_energy ), the proportion of the patch that can be harvested ( harvest ) minus all the costs involved: costs of farming ( farm_cost ), preparing the land for farming 2

Model: Swidden Farming by Barton et al. . CODE BLOCK 6.8

Some of these variables are parameters whose values must be derived from agricultural, anthropological, and historical data.

For a link to the code, refer to the Model Zoo at the end of this chapter. 207

PA RT I I : L E A R N I N G TO R U N

Model: Piaroa Swidden Farming by Riris

Chapter 9 describes how to properly document your code for use by others.

( veg_clear_cost ), and the costs of traveling to it ( distancexy ). The household chooses the patch with the highest net energy yield. Riris (2018) built on the concepts of Barton (2014) to develop his own model of swidden agriculture in Venezuela. He investigated mobility ranges and their effects on the pattern and extent of forest regeneration, effectively demonstrating that a high-mobility pattern of swidden farming could result in an Amazonian forest that was indistinguishable from “untouched” forest to observers on the ground. This group of three subsistence models shows that when the internal algorithms of an agent-based model are well conceptualized and described, it is possible to switch not just between coding languages (e.g., Java to NetLogo) but also back and forth between highly empirical models like MedLanD and Piaroa Swidden and more abstract models like Barton's Swidden Farming model. 6.4 Foraging Models

optimal foraging theory: a model of resource acquisition behavior that maximises the net benefit (i.e., after costs have been accounted for).

Model: Patch-Choice by Barton . ABMA Code Repo: ch6_patch_choice

208

While so far we have been considering only farming models, many of the same algorithms at least loosely apply to foraging societies as well. Foraging agents can also select suitable habitat based on patch variables, move location, harvest resources, and expend energy or time on these tasks. There is also a rich literature on human foraging under the umbrellas of optimal foraging theory (Stephens and Krebs 1986) and human behavioral ecology (Winterhalder and Smith 1981). The many papers falling under these headings tend to be quantitative and numerical model-driven, making them an ideal source to draw upon for agent-based model design of human foragers (for a review, see Hawkes, O’Connell, and Jones 2018). This section will use a couple of abstract models by Barton to examine the two most commonly applied optimal foraging theory (OFT) models in archaeology: the Patch-Choice (Barton 2013) and Prey-Choice (Barton 2015) models. PATC H - C H O I C E M O D E L

Imagine you’re standing in front of a bush while picking berries. At the start, the bush will be full and your calories-per-hour return will be high, but as the bush becomes more and more picked over, there will be a point when it is more profitable to leave that bush for the next bush. Mathematically, that point of departure should be when the rate of return on the first bush drops below the average return of the environment (also known

Chapter 6: Subsistence Algorithms as the marginal value theorem; Charnov 1976). This, combined with the cost that is the travel time to the next patch, forms the logic of the baseline Patch-Choice model. To model this, we need the basics already covered in agent harvest, updating patches to have depleted resources, patch regrowth, and so forth. We also need a way to measure the average rate of caloric return for the agent over the last few time steps and the average return for the environment. We can create a slider for the resource-density of the landscape such that when patches are created they have a certain probability of containing food. to setup_patches ask patches [ set pcolor brown if random 100 < resource-density [ set food food-value set pcolor green ] ] end Agents need to track their general experience on the landscape so that they know when their personal rate of return drops below the threshold of the resource-density . To do so, agents will use a rolling history of their food “encounters” over a certain number of previous time steps ( encounter-list ). to forage ask foragers [ rt random 360 forward 1 ifelse food > 0 [ let current-harvest random food set encounter-list fput current-harvest encounter-list

marginal value theorem: a model optimizing an individual’s foraging rate by balancing the diminishing rate in their current patch against the travel time to a new patch. In an ABM, agents should leave when the current patch has a lower foraging rate than the average of their neighbors. . CODE BLOCK 6.9

. CODE BLOCK 6.10 .

A list is the best data structure for this. With each time step, fput adds each new cell’s return to the list and but-last drops the oldest value.

209

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 6.10 (cont.)

ask patch-here [ set food food - current-harvest set pcolor pcolor - current-harvest if food rank-list

. CODE BLOCK 6.11

processing-cost1) processing-cost2) processing-cost3) processing-cost4))

.

Again, lists are the most computationally effective way to process all this information.

create-animals number1 [ set species 1 set food-value food-value1 set processing-costs processing-cost1 set rank position (food-value1 - processing-cost1) rank-list + 1 ] ... Again, one of ABM's strengths is enabling agents to differ from one another. Thus, Barton is able to depart slightly from the classic Diet-Breadth model by incorporating an agent energy level that determines how willing they are to take a lesser-ranked prey (fig. 6.4): to forage let prey one-of animals-here if prey != nobody [ if (energy >= 85 and [rank] of prey = 1) or (energy < 85 and energy >= 70 and [rank] of prey < 3) or (energy < 70 and energy >= 55 and [rank] of prey < 4) or (energy < 55) [ set energy energy + [food-value] of prey ] ] end

. CODE BLOCK 6.12

213

PA RT I I : L E A R N I N G TO R U N

Figure 6.4. Screenshot of the Diet-Breadth model. The hunter agent pursues prey species. The likelihood of the hunter attempting to kill any prey encountered varies depending on how much energy the hunter has left.

Model: Ache Hunting by Janssen & Hill See chapter 4 for the Ache Hunting model’s multilevel mobility algorithm.

The model also plots out a rolling list of recently killed prey and hunter energy levels as the five species randomly walk around the landscape. Greater detail is included in another Prey-Choice model simulating foraging practices among the Ache hunters in Paraguay (Janssen and Hill 2014). They follow a similar approach but also incorporate the additional prey parameters of pursuit time and probability of a successful kill, and different perspecies encounter rates for different habitat types (e.g., meadow, riparian, high forest, etc.). 6.5 Household-Level Production & Population Dynamics The last element often included in subsistence models is population dynamics. While we discussed the death of agents when energy levels drop too low, new agents can also be created. Subsistence models often include procedures for household-level fissioning (splitting), or individual reproduction, when energy levels or local population sizes reach a certain threshold. Depending on the consumption and reproductive parameters, the result may either be a relatively stable oscillation of the population, extinction, or run-

214

Chapter 6: Subsistence Algorithms away population growth. In chapter 4, we introduced the published model Ger Grouper to examine migration scenarios at the population level (Clark and Crabtree 2015). Ger Grouper examined how different levels of variability in the environment impact the survival of households. In the model, households fission when energy levels increase above a certain level. Households extract and consume energy from productive patches and share them according to certain probabilities with their relatives (Clark and Crabtree 2015); see fig. 6.5 in this book). Like in the Wolf–Sheep Predation model, the tension lies in finding a balance between productivity of patches and reproduction within realistic parameter ranges. If agents reproduce rapidly, they may outstrip their environment; if agent harvest is relatively low while environmental productivity is relatively high, the environment may have no impact on agents at all. Although it is possible to model the exact process of marrying and leaving the house and then raising a child (e.g., Kohler, Bocinsky, et al. 2012), in most models it is common to simplify it down to fission–fusion dynamics, such that if a household-agent has enough energy stored it creates a new household, dividing the energy between the parent and the offspring. to reproduce-gers if energy >= 20 [ if random 100 < gerreproduce [ set energy (energy / 2) hatch 1 ] ] end Here, an offspring inherits the parent’s variables. When an agent is asked to hatch, it passes its current values to the newly created agent, so we divide the parent’s energy in two so both end up with half of the original energy. As new households fission from parent households, you may want to add movement commands to the hatch code (e.g., hatch 1 [ move-to one-of neighbors ] ) to ensure the offspring ends up on an appropriate patch. However, note what comes next in the go code to ensure that new offspring aren’t disadvantaged by, for example, having a higher chance of landing on a bad patch. As these agents join the population, we can track

Model: Ger Grouper by Crabtree . ABMA Code Repo: ch6_GerGrouper .

Recall that the Mongolian word ger means yurt-style house.

TIP You can set a label to show the current energy level of agents by adding set label round energy to . the go code. CODE BLOCK 6.13

In some cases, we don’t want an agent to inherit values from the parent (e.g., imagine if there was a variable “age”).

215

PA RT I I : L E A R N I N G TO R U N

Figure 6.5. Screenshot of the Ger Grouper model. Ger agents are displayed on a landscape with patches in different states denoted using “pcolor”. Agent labels show their current energy level.

Model: Fission–Fusion by Crema ABMA Code Repo:

ch6_FissionFusion

The symbol K is used for carrying capacity in many numerical models, such as the Fisher–Skellam–KPP wave of advance model discussed in chapter 4.

how populations grow (or shrink) depending on exogenous dynamics of environmental fluctuations. Ger Grouper explicitly simulates fissioning of households but leaves the fusion part of the dynamic implicit. As seen before, agents could simply die if their energy got too low. Depending on the scenario, this could literally represent a group starving to death, or we could just make the uncoded assumption that if a household was no longer viable, the remaining stragglers might go join another household. This process can instead be modeled explicitly. Crema (2014) explored fission–fusion dynamics in an abstract but highly scalable model. While other models focused on grasping the population dynamics in particular human populations known from the archaeological record (e.g., Kohler and Varien 2012; Crema 2013), this model identifies simple rules driving human groups to expand or contract. In Crema’s model, agents, who represent households, form groups and respond to local environmental conditions (carrying capacity: K). The number of agents on a patch determines agent fitness (ϕ), which in turn is directly related to K. Fitness of agents drives reproduction (ρ), which leads to fission and fusion events. For agents whose individual fitness is lower than a desired threshold, it is advantageous to leave the group to seek a patch with higher productivity. They can then choose to do one of the following three behaviors: • solo , where agents find an empty patch and forage on their own; • fusion , where they find another group and join them; or

216

Chapter 6: Subsistence Algorithms • merge , where they find a nearby agent and set out to an empty patch together. Through these simple rules, Crema was able to demonstrate that some aspects of population spread detected in the archaeological record can be replicated through simple dynamics. While his model was built in R, here we simplify and replicate a small portion of the code to show how the fission–fusion dynamics work. We use the parameter K to determine the maximum energy a turtle has available from a patch. When the patch’s available energy is insufficient to support the number of turtles (i.e., exceeds K), fitness benefits decrease dramatically. While this simplifies Crema’s asymptotically declining fitness, it replicates the general fission and fusion dynamics (fig. 6.6). extensions [ Rnd ] turtles-own [ turtle_energy age ] patches-own [ energy ]

. CODE BLOCK 6.14

to setup ca ask patches [ set pcolor white set energy K ] crt 50 [ set color 15 + (10 * random 12) set age 0 ] reset-ticks end

217

PA RT I I : L E A R N I N G TO R U N

Figure 6.6. Screenshot of the Fission–Fusion model. Agents expand outward from their initial central point. Note the overlapping agents, which have undergone fusion or merge procedures. . CODE BLOCK 6.14 (cont.)

. CODE BLOCK 6.15

218

to go ask turtles [ eat fission reproduce grow-old ] tick end Agents in the model consume resources locally ( eat ), sharing the energy available on the patch, K, among all local inhabitants. Finally, agents age and die with a probability proportional to their age. to eat set turtle_energy energy / count turtles-here end

Chapter 6: Subsistence Algorithms .

to grow-old set age age + 1 if random 100 < age [die] end If there are too many agents on the patch to fulfill their needs, they move away (fission). Agents have a chance to reproduce if they have enough energy. to reproduce if turtle_energy >= 1 [ if random 100 < reproduction [ hatch 1 [ set age 0 rt random 360 ] ] ] end Now that we have coded the environment, the agents, and their population dynamics, we will add the three procedures for fission–fusion. Note that in code block 6.14, we have added the Rnd extension since we will be using a weighted random choice to decide among three types of fission. We will reuse several other code pieces from chapter 4 (e.g., the targeted walk algorithm), so it should feel familiar. to fission if turtle_energy < 1 [ let items [ "fusion" "solo" "merge" ] let weights [ 0.5 0.3 0.2 ] let pairs (map list items weights) let selection first rnd:weighted-one-of-list pairs [ [p] -> last p ]

CODE BLOCK 6.15 (cont.)

The probability of dying is proportional to the age so no agent can exceed 100 years of life.

. CODE BLOCK 6.16

We also discuss the weighted choice, a.k.a. roulette wheel algorithm, on page 223. . DON’T FORGET Add sliders for K and reproduction to the NetLogo interface (range 0 to 30).

. CODE BLOCK 6.17

Add a print pairs command after let pairs if you're not sure how this code works.

219

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 6.17 (cont.)

Note that the probabilities add up to 1. This is not actually necessary, but it helps to make sure the model’s logic is sound. In the model repository we implemented these weights as sliders.

if selection = "fusion" [fusion] if selection = "solo" [solo] if selection = "merge" [merge] ] end to fusion let target min-one-of patches with [any? turtles-here] in-radius 19 [distance myself] if target != nobody [move-to target] end to solo let target min-one-of patches with [not any? turtles-here] in-radius 19 [distance myself] if target != nobody [move-to target] end to merge let friend min-one-of other turtles in-radius 2 [distance myself] let target min-one of patches with [not any? turtles-here] in-radius 10 [distance myself] if target != nobody and friend != nobody [ move-to target ask friend [move-to [patch-here] of myself] ] end

This model demonstrates how individual circumstances and choices shape large-scale population patterns.

220

During the fission events, agents choose from three different outcomes with a probability given by the values [ 0.5 0.3 0.2 ] . Through these three algorithms, coupled with reproduction and death parameters, we can watch the agents expand and contract across the landscape through time. This model can also be used to simulate the changes in

Chapter 6: Subsistence Algorithms the distribution of populations across a landscape in reaction to changes in patch productivity since it is impacted by K. P O P U L AT I O N STA B I L I TY & G R O W T H

In the reproduce and grow-old procedures in our replication of Crema’s model, the parameterization of the population dynamics is quite abstract. Really, we are just comparing the ratio between the two values: probabilities of reproduction and death per time step. If the two are equal, the population will go extinct since available energy would limit reproductive rates. But as reproduction increases relative to death , the population may survive and expand. In other models, the reproduction and death rates are empirically derived, with values data-mined from ethnographic, historical, and other census records of societies. To give an example of how it works in practice, Wren and Burke (2019) looked through records of total fertility rates—the average number of births during women’s lifetimes—in different societies to find a value to use for their reproductive rate. Pennington (2001) reported values between 2.8 and 8.0 births with a median of 4.3, and included a specific example that was ecologically similar to their case study with a value of 4.4. With an estimate of average reproductive years, a little math in setup , and taking into account that their chosen time step represented one month, that worked out to a probability of 1.467% chance of an agent reproducing each month: to reproduce ask turtles [ if random-float 1 < birthrate_month [ reproduce ] ] end

Model: LGM Ecodynamics by Wren and Burke ABMA Code Repo:

ch6_weightedsurvival

. CODE BLOCK 6.18

to check_death ask turtles with [age > 0] [ set deathrate_month birthrate_month if random-float 1 < deathrate_month [die] ] end

221

PA RT I I : L E A R N I N G TO R U N

Wren & Burke based their model on Barton et al.’s Hominin Ecodynamics model.

. CODE BLOCK 6.19

. This is a good example of a linear model, here: y = death_slope × x + death_yintercept. The values for these variables were solved in setup.

Initially, they also set the death rate to the same value such that the overall population growth rate would average out to be 0%. Note the additional condition that only agents with age > 0 are at risk of death. In this model’s go code, reproduction occurs before death, so there are actually more agents (i.e., the agents at the start of that time step plus the newly hatched ones), being subjected to the same probability of death. Without the caveat that newly hatched agents should be excluded, this would result in a net population decline. From this point, a few different possibilities exist depending on the scope of the model. If you have an a priori reason to model a fixed population growth rate, you could just adjust the ratio between the reproductive rate and the death rate such that you have a top-down imposed population growth rate. Using a more bottom-up approach, Wren and Burke (2019) were interested in how the spatially variable ecological conditions might have affected the survival of groups in different parts of their landscape. To experiment with this, they adjusted the probability of death such that the patch suitability values, which ranged from 0 to 1, would affect how likely an agent was to die (fig. 6.7). They assumed an inverse linear relationship between probability of death and suitability and coded in a linear equation to determine the per-patch probability of death: to habitatsuitability_check_death ask turtles with [age > 0] [ if random-float 1 < (death_slope * suitability) + death_yintercept [die] ] end For example, if this equation was applied to agents on the SugarScape hills in ch. 3, the agents at the bottom of the resource hills would be more likely to die, leaving the ones at the top of the hills more likely to have net population growth (fig. 6.7). The fixed probability per patch can also be replaced with a dynamic patch variable and equations to determine rates of reproduction and death, as in Crema (2013).

222

Chapter 6: Subsistence Algorithms

Figure 6.7. Screenshot of the LGM Ecodynamics model. Agents on lighter shaded cells (i.e., higher “suitability”) have a higher probability of surviving, thereby driving increased net population growth in those regions. The structure of the landscape segments the population over space and drives population dynamics.

AGENT FITNESS & EVOLUTIONARY DYNAMICS

Differential rates of reproduction, based on a measured agent attribute, can lead to interesting dynamics of cultural and/or biological evolution. Agent attributes may be thought of as measure of their fitnes , where those with higher fitness have a higher likelihood of reproduction or survivability. How fitness is determined varies widely depending on research questions, but it can either directly or indirectly affect other agent characteristics (fig. 6.8). A simple algorithm makes fitness equal to reproductive probability in a similar but inverse manner to the check_death procedure in code block 6.18: if random-float 1 < fitness [ reproduce ] Another method is to use a weighted choice or roulette wheel approach through the Rnd extension. This will ask some proportion of the agents to reproduce, but we will make it more likely for agents to be asked to reproduce if their fitness is higher: ask rnd:weighted-n-of 10 turtles [fitness] [reproduce] .

fitness: a measure of an agent’s “quality,” usually relative to other agents, such as likelihood of reproduction or survivability in a biological system, or presence of preferred traits or behaviors that bring an economic or social benefit in a cultural system .(see ch. 5). CODE BLOCK 6.20

roulette wheel: an algorithm that selects among multiple outcomes, each with a different probability. As in casino roulette, where getting a red pocket is more likely than a specific number. 223

PA RT I I : L E A R N I N G TO R U N

Figure 6.8. Screenshot of the Roulette Reproduction model. The roulette wheel provides a weighted probability of reproduction based on a fitness measure. The average fitness of the population increases (y-axis) as a single lineage replaces the initially random population over time (x-axis).

. CODE BLOCK 6.21

.

Model: Roulette Reproduction by Wren ABMA Code Repo:

ch6_roulette_rep .

We also used a roulette wheel in the weightedrandom-walk in chapter 4 where agents were more likely to move to a patch with a higher attribute value.

224

As a simple example of cultural evolution, we will build a quick model around the roulette wheel approach to fitness-based reproduction: extensions [ Rnd ] turtles-own [ fitness age ] to setup ca crt 100 [ set fitness random-float 1 set age 1 setxy random-xcor random-ycor] reset-ticks end to go ask rnd:weighted-n-of 10 turtles [fitness] [reproduce] ask n-of 10 turtles with [age > 0] [die] ask turtles [ set age age + 1 set heading heading + 15 fd 1

Chapter 6: Subsistence Algorithms .

ask turtles [ set age age + 1 set heading heading + 15 fd 1 ] tick end

CODE BLOCK 6.21 (cont.)

to reproduce hatch 1 [ set age 0 ] end Here, we assign fitness as a random number in the setup rather than as a characteristic of the environment. The weighted-n-of line asks ten agents to reproduce, but is more likely to ask agents with a higher fitness value. We then kill off an equal number of turtles, though sparing those who just hatched. Let’s examine the effects this has on turtle demographics. In the INTERFACE, add three plots to measure: count turtles , mean [fitness] of turtles , and mean [age] of turtles . Run the model for about 500 ticks and examine the plots and agent population. You should notice first that the population size remains constant; our plot is just a check to make sure the model is doing what we expect it to do. The fitness plot will show that the fitness of the population steadily increases (fig. 6.8. The lower-fitness individuals are chosen to reproduce less often by the roulette wheel, yet they die just as often, so their lower fitness value does not get passed on to the next generation with as high a frequency as the more fit turtles. The third plot shows that the average age of agents quickly rises and then stabilizes at age 10. While some agents will be lucky and live to 50 ticks or so, since the death rate is constant and random, it is highly unlikely that an agent will live to be 100. To summarize, with this simple model we have mechanisms that produce a stable population size, a reasonable age structure in our population, and agent attributes that increase when under active positive selection. If

Note how fitness determines the probability of reproduction while death is equally likely for everyone. Over time this leads to changes in the average fitness in the population. Line plots of avaerages are easiest here, but fitness and age could also be bar-plot-based histograms if you needed to see the variability at each time step rather than the trends over time.

225

PA RT I I : L E A R N I N G TO R U N

The probability of dying is related to the number of times an agent underwent the check-for-death procedure. Although at each time step the probability of dying is the same, those agents that lived 11 years had 10 more chances of dying compared to a 1-year-old agent. We used a similar approach in chapter 1 to show color inheritance in the Y&B Diffusion Model.

Model: Cultural Hitchhiking by Ackland et al.

. CODE BLOCK 6.22

the fitness attributes were genetically inherited, then this would be a simulation of biological evolution under natural selection; however, if that attribute represented a cultural trait, we could equally be modeling cultural evolution. In that case, we could add in some transmission of cultural traits (see sec. 5.2 in the previous chapter). Whether genetic or cultural, the fitness value was the attribute under direct selection. However, what do you notice about the agents’ colors over the course of a run? Since we did not assign a color when we created the turtles in setup , they were randomly assigned. We also did not assign a new random color within the reproduce procedure, so this means that the hatched agent inherits their parent’s color. Color has no direct connection to fitness in this model, but the colors assigned to agents with higher fitness values are more likely to reproduce, leading rapidly to only one or two colors being represented in the agent population. We can think of color as representing any other attribute of a population that “hitchhikes” along by accident. For example, Ackland et al. (2007) published a study looking at cultural traits like language or neutral genetic markers, and how they may be carried along a diffusion wave with an advantageous cultural trait like farming. Add a small additional line to your code to introduce small mutations (random increases or decreases) in the value of these attributes. From this simple addition, evolutionary dynamics can emerge from the underlying combination of population dynamics, random inheritance, and selection: to reproduce hatch 1 [ set age 0 let mutation_direction one-of [-1 1] set color color + (1 * mutation_direction) ] end In the hatch code, we first randomly choose whether the mutation will increase or decrease the value, then adjust the color inherited from the parent agent by a small amount (brighter or darker color). Fission models also usually include mobility algorithms since “child” agents move to a new cell to avoid over-exploiting the parent’s patch. A

226

Chapter 6: Subsistence Algorithms

Figure 6.9. A screenshot of the Cardial Spread model. Detailed parameters, including birth and death rates, fissioning thresholds, mobility behaviors, and ecological conditions (lighter shades), control the spread of the Cardial Neolithic (darker shades).

good example of a model that integrates subsistence and mobility is the leap-frog model of Cardial Neolithic dispersal discussed in section 4.5 of chapter 4. Bernabeu Aubán et al. (2015) model villages of farmer agents each with their own local village-population size variable. The model uses a while loop such that each of the people , which individually are not agents but just numbers in the village-population variable, is subject to a probability of birth and death. If the village population reaches a specified population size, it marks itself as ready to fission, and the child village moves on according to one of several movement algorithms (fig. 6.9): to farmer-subsistence let people village-population let life-cycled 0 while [life-cycled < people] [ if random-float 100 + 1 < farmer-birth-rate [ set village-population village-population + 1 ] if random-float 100 + 1 < farmer-death-rate [ set village-population village-population - 1 ] set life-cycled life-cycled + 1 ]

Model: Cardial Spread by Bergin

. CODE BLOCK 6.23

227

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 6.23 (cont.)

Model: Multilevel Population Dynamics by Gauthier

This R model can be replicated in NetLogo using the LevelSpace extension.

Using symmetrical (triangular or hexagonal) lattice removes many of the distance issues discussed in sec. 4.3.

if village-population > max-farmer-per-patch and village-population > farmer-fission-hh-size [ set time-to-fission? true ] ... end As discussed in chapter 4, an early stage of model development involves selecting whether an agent is an individual, a household, or a village; that is, the scale of the model’s dynamics. Some subsistence models incorporate multilevel interactions within a single model. Gauthier (2019a) uses three nested models: one for individuals, one for households, and one for settlements. Each has its own dynamics, and the outputs of each level interact with the others. For example, individuals have age-specific fertility rates, which vary depending on the amount of food available within that individual’s household. The population of a household affects the food production rate of that household, and if a household’s population increases above a certain threshold, one individual may leave to form their own household (i.e., fission). At the settlement level, the model is a cellular automata where neighboring cells (in this case a hexagonal lattice) may be occupied as settlement populations grow beyond their local carrying capacity (Gauthier 2019b). 6.6 Tragedy of the Commons

The tragedy of the commons is a phenomenon that extends well beyond collective agreements in small-scale agrarian populations.

228

So far we have focused on the interactions between the environment and agents. However, the interactions among agents in such a system can be equally rich. Let’s start with introducing one of the most famous models of group interaction over limited resources: the tragedy of the commons (Hardin 1968). For centuries, an area of public land known as the commons was an emblematic feature of the British countryside. This was land that belonged to everyone. The tragedy of the commons refers to a model of how the use of such common resources can be negotiated. It is a well-known paradox that by optimizing self-interest, individuals can drive the system to a collapse

Chapter 6: Subsistence Algorithms where it serves no one at all. If each farmer grazes as many cattle in the commons as they can (maximizing their own short-term returns), the result will be a barren patch of land where no grass can regenerate. This paradox occurs because the gain from using the commons goes to an individual farmer, while the cost of the damage from overgrazing is shared among all farmers. How to prevent the inevitable outcome of collapse depends on the group’s ability to negotiate social contracts, thus bringing us to the vast topic of modeling human cooperation and the theoretical, mathematical framework behind it, known as game theory. Schindler (2012) implemented the classical version of the tragedy of the commons (fig. 6.10. Here we will simplify it even further. Open a new model and code the setup: • Set up a world with two breeds: cows and herders living in the world of green patches. • Use sliders to set the initial number of each breed (default: 10 cows and 5 herders). • Create cow variables: owner and forage and assign one of the herders to each cow’s owner variable. • Create herder variables: now_cows and past_cows and set now_cows to each herder’s cow count .

Model: Multi-Agent System of the Tragedy Of the Commons (MASTOC) by Schindler ABMA Code Repo:

ch6_tragedy_comm

Use with [ owner = myself ] to count herders’ cows.

In the go procedure, the cows graze, the herders can add cows after they evaluate their stock, and grass regrows. We also include a stop condition so that the model’s run ends when tragedy strikes the commons (i.e., the grass is so depleted that the cows die). Before looking at the following code blocks, think about how you could implement the graze procedure using the variables you have created and what we have covered so far in this chapter. How will you track the cows’ forage and mark patches as eaten? How will you stop cows from trying to graze in depleted patches? How will the patches recover?

It is good practice to work out the structure of key algorithms, like graze , in pseudocode. At this point, you should be able to come up with a working solution even if it isn't the same algorithm as our version in code block 6.25.

229

PA RT I I : L E A R N I N G TO R U N

Figure 6.10. Screenshot of the MASTOC model. A group of herders and their toorapidly-increasing cow population. Note that one herder’s cows ran out of available grass and died.

. CODE BLOCK 6.24

.

to go graze evaluate-stock grass-regrowth if not any? cows [stop] tick end Here, each time step represents one day and uses a while loop to have cows repeatedly move to grass patches and forage until they meet their day’s food requirement (set by a slider cow-forage-requirement with values between 0 and 100) or until the grass runs out. If they cannot meet their energy needs, they die.

230

Chapter 6: Subsistence Algorithms .

to graze ask cows [ set forage 0 ] while [max [ forage ] of cows < cow-forage-requirement and any? patches with [ pcolor = green ]] [ ask cows with [forage < cow-forage-requirement] [ if any? patches with [ pcolor = green ] [ move-to min-one-of patches with [ pcolor = green ] [ distance myself ] set pcolor black set forage forage + 1 ] ] ]

CODE BLOCK 6.25

ask cows [ if forage < cow-forage-requirement [ die ] ] end Note that unlike in some of the previous models, when energy was a continuous variable, patches here only have a single unit of grass and are immediately marked as depleted (through set pcolor black ) when a cow grazes on them. Next, we have herders evaluate their stock and add more animals to the pasture if they did not lose too many cows during the previous day. To establish this, they compare the number of cows they have now, now_cows , with that in the previous time step, past_cows . If some of their cows died in the previous step, that means that there was not enough grass for everyone. The unselfish thing to do would be not to add any more animals. Herders have a variable selfishness (set with a slider), which determines how many cows need to die before they become concerned enough not to add any more to the common pasture.

TIP Don’t expect to be able to write the whole model out in one go. Build up the complexity of your procedures bit by bit.

231

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 6.26

DON’T FORGET Add to the INTERFACE a selfishness slider with values 0–10 and a grassregrowth-rate with values 0–1, increment 0.01.

. CODE BLOCK 6.27

Add a few plots showing the number of grass patches, cows, and active herders to trace the evolution of the system.

232

to evaluate-stock ask herders [ set past_cows now_cows set now_cows count cows with [owner = myself] if now_cows = 0 [set color red] if now_cows >= past_cows - selfishness [ let mycows cows with [owner = myself] if any? mycows [ ask one-of mycows [hatch 1] ] ] ] end Finally, the grass regrows at a rate set by a slider. Since the grass is a single energy unit (marked as green or black), we regrow patches using a probability of regrowth rather than increasing by even increments. Accounting is easier here, since only black patches are asked to regrow and they cannot grow past a max-grass limit. to grass-regrowth ask patches with [pcolor = black] [ if random-float 1 < grass-regrowth-rate [ set pcolor green ] ] end In the evaluate-stock procedure we have asked herders whose cows have died to turn red. If you now run the model under different combinations of cow-forage-requirement , grass-regrowth-rate , and selfishness , you can see how many herders can take advantage of the common land. See if you can find a parameter combination that results in a lasting stable system instead of the herders driving the cow population to extinction.

Chapter 6: Subsistence Algorithms GAME THEORY

The tragedy of the commons emerges from agents’ interactions in which each agent tries to maximize their own utility in effect competing over a limited subsistence resource. In this case, the game is simple: the more cows, the higher the individual payoff up to a point when grass gets completely depleted and no one can take advantage of it anymore. You can easily imagine how this kind of situation will lead to a social contract in which individual payoff is constrained to a solution sustainable for the whole community over long term. This in turn creates a situation in which agents can follow two strategies: cooperate or defect. This kind of framework of interaction falls under the scope of game theory. Game theory is a family of mathematical models of interactions between agents trying to optimize their individual utility while outwitting their opponents (Bonanno 2018). The most basic of all game-theoretical games is the Prisoner’s Dilemma (Axelrod 1980; Poundstone 1993). Imagine two gang members caught by the police. They are separated and can either betray their colleague (defect) or stay silent to protect them (cooperate). If they both defect, their prison sentences will be ten years each; if they both stay silent, they will be sentenced to two years. Yet if only one of them defects, the betrayed partner gets a five-year sentence while their deceitful colleague goes free. The problem is set in this way to show that although the optimal solution of the system is for both to stay silent (a total of four years of incarceration), individually, betraying the colleague holds the highest potential reward. Cooperate Defect

Cooperate

Defect

2 yrs/2yrs free/5 yrs

5 yrs/free 10 yrs/10 yrs

Now, this is a single instance of the situation, but in the real world we make such decisions repeatedly, which means that the system evolves over time and reputation becomes important. Also, consider how this game would play out in a space where agents are neighbors spread over an area and free to choose a strategy: defect or cooperate. It pays to cooperate if one is among other cooperators. However, a single defector can easily take advantage of their sincere neighbors, causing them to switch and start defecting. This dynamic is captured in the Prisoner’s Dilemma Basic Evolutionary model, which you can find in the NetLogo Models Library (Wilensky 2002).

game theory: a mathematical framework studying models of interaction between competing agents, usually rational decision makers.

Model: Prisoner's Dilemma by Wilensky

233

PA RT I I : L E A R N I N G TO R U N . CODE BLOCK 6.28

We initiate all patches with either “cooperate” or “defect.” patches-own [ cooperate? score ] to setup clear-all ask patches [ ifelse random-float 1.0 < (66.6 / 100) [set cooperate? true set pcolor yellow] [set cooperate? false set pcolor red] ] reset-ticks end

. CODE BLOCK 6.29

The slider defection-award takes values between 0 and 3, with a 0.25 increment.

234

The agents (i.e., patches) then interact and calculate the payoff of this interaction score , which they will use to determine how to behave in the next round. to go ask patches [interact] ask patches [select-strategy] tick end To calculate the payoff, agents simply count the number of cooperating neighbors if they are one of the cooperators, or multiply that number by a defection-award (set by a slider) if they are a defector. At each time step, agents assess who was the most successful agent (i.e., the neighbor with the highest score) in their neighborhood and copy that agent’s strategy.

Chapter 6: Subsistence Algorithms .

to interact let total-cooperaters count neighbors with [cooperate?] ifelse cooperate? [set score total-cooperaters] [set score defection-award * total-cooperaters] end

CODE BLOCK 6.30

to select-strategy set cooperate? [cooperate?] of max-one-of neighbors [score] ifelse cooperate? [set pcolor yellow][set pcolor red] end If you set the value of defection-award to close to 1.5, you’ll find an interesting equilibrium of constantly shifting areas dominated by either defectors or cooperators. This is just a simple application of the most basic model in game theory, a continually growing field of mathematics. There has been very limited application of it in archaeology, with only a handful of models taking advantage of this powerful framework (Kohler, Cockburn, et al. 2012; Crabtree et al. 2017). 6.7

Parameterization, Realism, Abstraction & Heterogeneity

As you were building the subsistence models, you might have noticed that in many places the code required specific numbers—parameters—rate of growth, size of the yield, number of days between harvests, etc. These are different from variables, i.e., individual attributes of the agents that dynamically change over the course of a run, such as age, or energy level. Parameter values must be carefully selected in the process known as parameterization. The task of parameterization involves selecting values and ranges for all the parameters in a model before running experiments. In practice, this involves some combination of selecting ranges derived from the archaeological or ethnographic records, making up values that seem logical, or picking arbitrary ranges like 0 to 100. While often challenging, being forced to select

variable: attribute of an agent, patch, or the world that can change over the course of a simulation run, such as age, fitness, grass, or number of agents alive.

parameterization: the process of selecting appropriate parameter values and value ranges for a model before running experiments.

235

PA RT I I : L E A R N I N G TO R U N

emulation-driven models: data-driven models encompassing a high degree of realism and precision. Commonly validated against archaeological datasets.

exploration-driven models: usually theory-driven models, showing a high degree of abstraction and generality. Commonly validated against stylized facts or not validated at all.

236

values is a key advantage of the ABM approach, because it forces formalism. Terms like “rapid,” “efficient,” or “close” need to be replaced with values indicating, for example, how rapid the change of subsistence strategy occurs, how efficient a new subsistence strategy is, or whether “close surroundings” means a 5 or 50 km radius. Models often surprise us in terms of how responsive they are to certain parameters, regardless of our intuition regarding their importance or role in the model’s dynamics (Romanowska 2015b). As an example, in the Wolf–Sheep Predation model the grass growth rate has an impact on the population of wolves (if it is too high, they go extinct first; if it is too low, they . . . also go extinct first), even though wolves do not eat grass themselves. The models discussed in this chapter vary widely in their level of abstraction versus empiricism. Of course, all models are simplified representations of the real world, since by definition a model is an abstraction. However, some models attempt to be closer to our empirical understanding of a given phenomenon, while others are more abstract and focus instead on the dynamics of a modeled system. Premo (2010) referred to the different goals of models: emulation, where the modeler’s goal was to test specific hypotheses by using empirically derived parameter values, and exploration, where the modeler was focused on theory building through understanding the dynamics of a simpler and more abstract model. In emulation models, parameter values are meticulously derived from data and their ranges closely coupled with each other in respect to the scale (e.g., energy consumption is matched to the harvest period). For example, in a population dynamics model we could determine age-specific fertility rates using literature on demography and have the probability of death correspond to the Siler hazard equation (Gurven and Kaplan 2007). Importantly, though, once one of the parameters is pegged to a real-world value, others need to follow suit. Otherwise, you risk losing the realism and precision you achieved because of the arbitrariness or uncertainty of even one other parameter. For example, having exact ranges for crop yield, calorie consumption per person, and storage capacity is meaningless if the number of people per household consuming the crop is unrealistic. In contrast, exploration-type models usually operate without reliance on exact parameter values. More often, parameters are varied along wide but arbitrary ranges to explore dynamics under a wide range of conditions.

Chapter 6: Subsistence Algorithms What is usually more important is the relative relationship between the values (e.g., predators derive twice as much energy from sheep than sheep derive from grass). Compared to the wide variety of algorithmic choices in mobility models or modes of cultural transmission, subsistence models tend to be fairly similar in algorithms: agents extract resources from patches, patches regrow, agents live, reproduce, and die depending on their success in gaining energy. However, the empirical basis for the parameterization of these models can be highly realistic and detailed. Rainfall records, soil quality, erosion factors, reproductive probabilities from ethnographically recorded fertility rates and age structures, daily grams of meat protein needed per person, and stored food rotting rates have all been intricately measured and incorporated into one subsistence model or another. 6.8

Summary

Combining all of the algorithms we have covered here—from having patches with varying productivity, degradation rates, harvesting algorithms, storage capacities, and energy accrual and costs—can create the base of a model that can be used to examine many social phenomena. Indeed, the combination of these simple algorithms creates the basis for most models that examine subsistence, with only small variations for modeling farming versus foraging societies. The simple versions we coded here can be used to examine any number of scenarios where their subsistence strategy is key to understanding the society you study. Many of the more complex agent-based models of human societies are built on top of subsistence models. For example, the Village Ecodynamics Project (VEP) has developed a suite of agent-based models using sophisticated subsistence algorithms combined with other dynamics of human society (Kohler and Varien 2012). From a base of algorithms that calculate spatial and temporal variability in productivity, the VEP team has examined a wide range of topics, including: • Modeling the domestication of turkey to examine when Ancestral Pueblo people would have switched from primarily hunting to provisioning with turkey and maize (Bocinsky 2011).

237

PA RT I I : L E A R N I N G TO R U N

• A public goods game, where cooperative use of public goods leads to increases in agricultural productivity and the development of withingroup hierarchy (similar to the tragedy of the commons; see sec. 6.6; Kohler, Cockburn, et al. 2012). • A model of how between-group hierarchy could form in regions with unpredictable agricultural productivity (Crabtree et al. 2017). • The development of specialization in small-scale societies, allowing for specialist farmers and specialist hunters, among others (Cockburn et al. 2013). • How cultural learning through social networks was impacted by variability in landscape productivity over time (Mokom and Kobti 2015). • The exchange of maize as the basis for the development of social networks, which then formed the basis for exchange in all of the above models (we will build a simplified version of these models in ch. 8; Crabtree 2015). The array of models built from the VEP’s base subsistence model demonstrates the utility of building models from the ground up. Even though all the aspects are tightly interconnected, the productivity of the landscape impacts population size, where agents are located, and all sorts of dynamics of human interaction, so it is a good idea to introduce them into the model one by one. By following this paradigm of gradually layering complexity, the Village models have become a cornerstone for agent-based modeling in archaeology. Subsistence models often incorporate external variability, from stochastic rainfall to dynamically degrading soils; in section 6.2, you learned how to incorporate simplified versions of these shifting variables. These types of variables can be quite complicated, especially if you are using realistic models or weather station data. Again, keep your research questions in mind as you choose what to include and use the principles of parsimony to guide your research. The same applies to defining parameter ranges and values that will then be tested later in experiments (see ch. 9). Note how almost all of the models in this chapter examine one specific hypothesis. Even though their authors were well aware that the lives of past people had many aspects, they represented them using the simplest model possible that still

238

Chapter 6: Subsistence Algorithms incorporated the necessary variables to examine their hypotheses in question. Finally, we show how we can understand the resilience of past societies based on how agents respond to changing conditions in the environment. Agents bounce back from the brink of extinction thanks to planning ahead (e.g., storage), adaptability (e.g., changes in mobility), or social structures (e.g., social contracts). Subsistence algorithms provide a strong base for understanding the function of past societies; the algorithms we present you with here can be built upon to examine additional questions about resilience, vulnerability, and the evolution of socionatural systems. E End-of-Chapter Exercises 1. How would you model stochastic (as in once every ten years) productivity shortfalls that many agricultural societies prepare for? 2. Past peoples engaged in multiple different types of sustenance. Model farmer–hunter agents who require not just farmed calories but hunted protein as well. How would that impact the model dynamics? 3. Should other types of necessities be included as well? How would water or fuel needs be included in a model of subsistence for an agent? How can you balance all of these different needs within the code? 4. In the Patch-Choice model, we only included a random-walk. Add an option for a target-walk, and compare the average return and the frequency of movement for the random-walk versus the target-walk. Subsistence Model Zoo Many of the models below are also available in our code repository. ▷ Ache Hunting M. A. Janssen and K. Hill. 2014. “Benefits of Grouping and Cooperative Hunting Among Ache Hunter–Gatherers: Insights from an Agent-Based Foraging Model.” Human Ecolo 42, no. 6 (August): 823–835. doi:10.1007/s10745-014-9693-1 Code: https://doi.org/10.25937/66d6-kz70

239

PA RT I I : L E A R N I N G TO R U N

▷ AgModel L. Barton and I. I. T. Ullah. 2016. “Computer Simulation and the Origins of Agriculture in East Asia.” Presented at the Seventh Worldwide Conference of the SEAA June 8–12, 2016, Cambridge/Boston, MA, USA. Boston, MA. Code: I. I. T. Ullah. 2015. Agmodel: Version 0.3. doi:10.5281/ZENOD O.17551 ▷ AmphorABM S. A. Crabtree. 2016. “Simulating Littoral Trade: Modeling the Trade of Wine in the Bronze to Iron Age Transition in Southern France.” Land 5, no. 1 (February): 5. doi:10.3390/land5010005 Code: https://comses.net/codebases/c310d351-b629-46ec-a29e-eb365aaa08b4/ ▷ Cardial Spread J. Bernabeu Aubán et al. 2015. “Modeling Initial Neolithic Dispersal. The First Agricultural Groups in West Mediterranean.” Ecological Modelling 307 (July): 22–31. doi:10.1016/j.ecolmodel.2015.03.015 Code: S. Bergin. 2019. The Cardial Spread Model. CoMSES Computational Model Library. https://www.comses.net/codebases/5278/ releases/1.1.0/ ▷ Cultural Hitchhiking G. J. Ackland et al. 2007. “Cultural Hitchhiking on the Wave of Advance of Beneficial Technologies.” Proceedings of the National Academy of Scienc 104, no. 21 (May): 8714–8719. doi:10.1073/pnas. 0702469104 Code: https://www.pnas.org/content/suppl/2007/05/29/0702469104. DC1 ▷ Diet-Breadth C. M. Barton. 2015. Diet-Breadth Model from Optimal Foraging Theory (Human Behavioral Ecolo ). https://www.comses.net/codebases/ 2225/releases/1.1.0/ 240

Chapter 6: Subsistence Algorithms ▷ Fission–Fusion E. R. Crema. 2014. “A Simulation Model of Fission-Fusion Dynamics and Long-Term Settlement Change.” Journal of Archaeological Method and Theory 21 (2): 385–404. doi:10.1007/s10816-013-9185-4 Code, original in R: https://github.com/ercrema/fissionfusion2014 ▷ Ger Grouper J. K. Clark and S. A. Crabtree. 2015. “Examining Social Adaptations in a Volatile Landscape in Northern Mongolia via the Agent-Based Model Ger Grouper.” Land 4, no. 1 (March): 157–181. doi:10.3390/ land4010157 Code: https://comses.net/codebases/27f01923-3884-48ca-81ca-55739f976dc0/ ▷ LGM Ecodynamics C. D. Wren and A. Burke. 2019. “Habitat Suitability and the Genetic Structure of Human Populations during the Last Glacial Maximum (LGM) in Western Europe.” PLOS ONE 14, no. 6 (June): e0217996. doi:10.1371/journal.pone.0217996 Code: https://doi.org/10.25937/na38-tj46 ▷ MASTOC - A Multi-Agent System of the Tragedy of the Commons J. Schindler. 2012. “A Simple Agent-Based Model of the Tragedy of the Commons.” In ECMS 2012 Proceedings, edited by K. G. Troitzsch, M. Moehring, and U. Lotzmann, 44–50. ECMS, May. doi:10.7148/2012-0044-0050 Code: https://www.comses.net/codebases/2283/ ▷ MedLanD C. M. Barton. 2014. “Complexity, Social Complexity, and Modeling.” Journal of Archaeological Method and Theory 21, no. 2 (June): 306– 324. doi:10.1007/s10816-013-9187-2 Code: NetLogo 4.2 version, https://doi.org/2286.0/oabm.3826

241

PA RT I I : L E A R N I N G TO R U N

▷ Multilevel Model of Population Dynamics N. Gauthier. 2019a. Multilevel Simulation of Demography and Food Production in Ancient Agrarian Societi : A Case Study from Roman North Africa. Preprint. SocArXiv, August. doi:10.31235/osf.io/5be6a https://osf.io/5be6a Code: https://github.com/nick-gauthier/Silvanus ▷ Piaroa Swidden P. Riris. 2018. “Assessing the Impact and Legacy of Swidden Farming in Neotropical Interfluvial Environments through Exploratory Modelling of Post-Contact Piaroa Land Use (Upper Orinoco, Venezuela).” The Holocene 28, no. 6 (June): 945–954. doi:10 . 1177 / 0959683617752857 Code available in article’s supplementary material. ▷ Patch-Choice C. M. Barton. 2013. Patch-Choice Model from Optimal Foraging Theory (Human Behavioral Ecolo ). https://www.comses.net/codebases/ 2224/releases/1.0.0/ ▷ Swidden Farming C. M. Barton. 2014. “Complexity, Social Complexity, and Modeling.” Journal of Archaeological Method and Theory 21, no. 2 (June): 306– 324. doi:10.1007/s10816-013-9187-2 Code: https://doi.org/2286.0/oabm.3826 ▷ Wolf–Sheep Predation U. Wilensky and W. Rand. 2015. An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. Cambridge, MA: MIT Press, April. U. Wilensky. 1997. NetLogo Wolf-Sheep Predation Model. Evanston, IL. Code: https://ccl.northwestern.edu/netlogo/models/WolfSheepPredation

242

N OT E S

PART III: LEARNING TO

FLY



7 M O D E L I N G W I T H S PAT I A L DATA : BRINGING THE GIS WORLD TO ABM

7.0

Introduction

There are many intuitive reasons for making a model spatially explicit. Human activity occurs within space and landscapes, and more often than not the characteristics of those landscapes will impact their activities (see landscape archaeology: David and Thomas 2016; Rossignol and Wandsnider 1992; Verhagen 2012). In his first law of geography, Tobler (1970, p. 236) states that “everything is related to everything else, but near things are more related than distant things.” This basic principle, also known as spatial autocorrelation, generally applies to human behavior as well. People who are closer to each other are more likely to interact and, as a result, share characteristics (Ramachandran et al. 2005). Until the dawn of modern communication and transportation technologies, these interactions usually happened across small distances—in the local environment of individuals. Space and the cost of traversing it are fundamental limiting factors to human activity. Physical geographic systems, whether in natural or constructed environments (e.g., cities), provide opportunities as well as constrain the movement and interactions of people within them (Banks et al. 2008). Accounting for space is often necessary if we want to understand how certain micro-level processes lead to large-scale patterns; for example, traffic jams can develop from individuals acting to optimize their own travel (Raney et al. 2003). Similarly, while social dynamics usually play a central role in archaeological models (Binford 1962), the dynamics of human–environment interaction are commonly invoked to explain mechanisms governing past societies. Indeed, the entire field of socionatural or natural–human systems examines the impact of these types of dynamics. These cultural adaptations,

OVERVIEW ▷ Types of spatial data ▷ Handling GIS data in NetLogo ▷ Modeling spatial interactions ▷ Finding GIS data ▷ Artificial landscapes ▷ Code optimization with the Profiler extension

247

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

The latest GIS in ABM textbook is Crooks, Heppenstall, and Malleson (2018).

Creating an abstract landscape may be possible using NetLogo code (see O’Sullivan and Perry 2013) or may require a separate GIS package.

248

in turn, can have dramatic impacts on local ecosystems through the consumption of resources, burning, seed dispersal, and other ways in which human groups take advantage of various ecosystem services (Bird and Nimmo 2018; Crabtree, Bird, and Bird 2019), such as through land clearance for agriculture, horticulture, or other activities (Crabtree, Vaughn, and Crabtree 2017). However, this does not necessarily mean that all models need to be, or should be, placed within an as-true-as-possible representation of a landscape. A thoughtful list of relevant factors should be selected and worked into the model to ensure that the final output is legible and useful. We have already come across the concept of parsimony, paring down the available cornucopia of information until only the bits that are most essential remain (see ch. 5). This rule is fundamental for building models, including the spatial representation in our simulation. As with all models, it is vital to understand the reference system you are studying in order to know how to incorporate spatial constraints adequately and whether to add realistic geographic information or limit the model to an abstract spatial representation. It is, however, a good rule of thumb that realistic geographic information should only be added in the later phases of model building, and only after the model dynamics are very well understood. Otherwise, irregular behavior or interactions between variables can get lost in the heterogeneity that is introduced by realistic spatial data. Instead of jumping in with a detailed topography dataset from day one, it is a good practice to simplify its main characteristics and use that simplified representation to develop agents’ dynamics. Perhaps the landscape can be represented as, for example, a strip of water to the north, a middle strip of agricultural land, and a strip of mountains in the south (see AmphorABM in ch. 6 or SugarScape in ch. 3). This will allow you to understand, for example, what happens on the “boundary” between regions and control for potential bugs in the code— something that would be much more difficult to notice with rugged and irregular spatial distributions that characterize real landscapes. Equally, creating artificial landscapes where certain features are controlled for can be a much cleaner approach than uploading raster maps of real geographies. Imagine you are interested in how patchiness of resources impacts a group’s foraging strategy. Simulating landscapes with

Chapter 7: Modeling with Spatial Data precise characteristics (e.g., 10 clusters but with a different degrees of clustering) is a powerful method in experiment design. All of these questions—of how the micro-level processes of human– environment interaction can lead to macro-level signatures across space and time—link strongly with the theories of complex systems discussed in the introduction, and after working through these exercises you will see how they fold neatly into the agent-based modeling paradigm. Further, you will see how the coupling of geographic information science (GIS) and ABM can provide a powerful framework for answering new questions. Throughout this chapter we will discuss a number of examples where an explicit modeling of space is particularly useful. These are divided into four categories on the basis of what is affecting what (table 7.0). We will use a simple model of a forager moving around the landscape picking up stone raw material to make tools as our GIS landscape-based model. It is a replication of Neutral Procurement, by Brantingham (2003). Davies et al. (2019) coded the replication and published it along with a step-by-step tutorial, which we follow and expand on here. We will also discuss the topic of code profiling and optimization, the first step toward the final stages of model development: experiment design and running (ch. 9).

The “S” in the acronym GIS can stand for both “Systems,” referring to the software, and “Science,” referring to the broader approach to geographic data.

Model: Neutral Procurement by Brantingham

Table 7.0. Matrix of possible interactions between agents and patches that are modeled in explicit space.

7.1

Bringing GIS Data into NetLogo

In chapter 1, we imported images to use as maps by converting their color into patch variables that agents can sense and react to. That was a simple yet effective way of dealing with spatial data. However, anyone with some spatial data experience likely recognizes its limitations. For example, we 249

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

avoided using a coordinate reference system, leading to a somewhat inaccurate representation of distance as well as distortion of the shapes of landmasses; further, it may have been difficult to pinpoint an exact location. In this section, we will improve upon the representation of spatial data in NetLogo models, and then learn to manipulate that spatial data in the next section. As the purpose of this book is to teach you to write agent-based models, we only cover the basics of geographic information science theory here; a dedicated GIS text will provide a more thorough background and in-depth discussion of GIS theory and methodology. NetLogo’s GIS capabilities are found within the GIS extension, which we can enable by adding at the top of the model code:

We also created artificial landscapes by leveraging geometrical operations to get well-defined spatial structures, such as hills or barriers (ch. 4). We recommend Conolly and Lake (2006) and Gillings, Hacigüzeller, and Lock (2020) for archaeology-specific guides to GIS. . CODE BLOCK 7.0

extensions [gis]

Some extensions, like GIS and Rnd, are included with NetLogo. Others must be downloaded separately using the EXTENSION MANAGER in the TOOLS menu.

The two basic types of GIS data structures are raster and vector. Raster data is gridded spatial information that is roughly equivalent to the patches in NetLogo. Vector data is stored as lists of coordinates that define points, lines (i.e., a series of connected points), or polygons (i.e., a series of points connected to form a shape). NetLogo handles each type in a particular way. R A ST E R DATA

NetLogo can only read the ASCII raster data format, so you may have to use GIS software, such as QGIS, to transform your data if it comes in any other format. The .asc file starts with a small preamble that defines the corner (here in decimal degrees), shows the number of columns and rows of data, the cell size, and what value represents no-data (fig. 7.0). If your data is missing any of this information, NetLogo will not read the file. We can import a raster file, for example, containing elevation values of our landscape, dem.asc , by first creating a global variable to hold the data elevation-dataset , and then loading the file into it.1

ASCII files can be viewed

and edited in any text editor, (e.g., Notepad). If the file is missing any of the necessary information, simply type it in.

1

250

You can find all code and example datasets from this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch7.

Chapter 7: Modeling with Spatial Data

Figure 7.0. Format of an example raster data file formatted as an ASCII (.asc). Here the rows of 0s represent cells at sea level as this corner of the map is ocean.

TEST

globals [elevation-dataset] to setup set elevation-dataset gis:load-dataset "dem.asc" end

CODE BLOCK 7.1

.

ABMA Code Repo: ch7_gis

NetLogo now recognizes the raster data file but does not yet know how to translate it to a patch variable. First, we have to establish the coordinate reference system of our data, that is, its projection. This information has to be imported in WKT format (see table 7.1). Table 7.1. Projections that are available in NetLogo, and a corresponding example of correct and incorrect projection formats.

251

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

The best way to do this is to have NetLogo import a properly formatted .prj file to set the projection.2 Add the following line before loading your data:

TEST CODE BLOCK 7.2

gis:load-coordinate-system "dem.prj" I M P O R T I N G PATC H L A N D S C A P E S F R O M R A S T E R D ATA

In chapter 1, we manually adjusted the dimensions of the world to match the imported data. You should do that here as well by opening the dem.asc file in your text editor of choice to check its ncols and nrows ,3 then adjusting NetLogo’s MODEL SETTINGS to match. However, if your raster’s dimensions are too fine or too coarse using the GIS extension, we can also automatically stretch our raster data (fig 7.1) (e.g., if it was too fine a spatial resolution for our purposes) to our chosen patch landscape dimensions by setting the world envelope to the size of our raster dataset:

This is similar to GRASS GIS’s approach of setting the spatial extent and cell size with g.region .

TEST CODE BLOCK 7.3

gis:set-world-envelope gis:envelope-of elevation-dataset Next, we want to copy the raster values of our elevation data over to a patch variable. Create a patch variable patch-elevation , then add the following to the setup code to (1) apply the raster data to the patch vari-

TEST

able and (2) adjust pcolor according to their elevation value:

CODE BLOCK 7.4

patches-own [patch-elevation]

You’ll get a warning GIS Extension Warning:

to setup ... gis:apply-raster elevation-dataset patch-elevation

datasets previously loaded... if you click on setup . Just ignore it.

252

2

The website spatialreference.org has WKT .prj files for every kind of projection, or see the following link on how to make ArcMap create a compatible .prj file: https: //support.esri.com/en/technical-article/000012439.

3

Notepad++ (for Windows) is a good open-source text editor that supports some code highlighting: https://notepad-plus-plus.org

Chapter 7: Modeling with Spatial Data TEST

let mx gis:maximum-of elevation-dataset ask patches [ set patch-elevation ( gis:raster-sample elevation-dataset self ) ifelse patch-elevation > 0 [ set pcolor scale-color green patch-elevation 0 mx ][ set pcolor blue ] ] end

CODE BLOCK 7.4 (cont.)

Rather than setting all patches to the same color, scale-color uses patch-elevation to read a pcolor from a gradient between 0 and the maximum elevation stored in the temporary variable mx . If there was more than one raster dataset of different sizes and we wanted an envelope big enough to contain them both, we could use:

DON’T FORGET Add patch-elevation

gis:set-world-envelope gis:envelope-union-of gis:envelope-of elevation-dataset gis:envelope-of vegetation-dataset However, this can create problems if the two raster datasets do not have the same cell resolution, if their grids do not line up perfectly, or if the spatial resolution of your raster dataset is too fine or too coarse for your chosen ABM spatial scale. In all these cases, you should choose your world size first, then the imported data can be resampled during import (fig. 7.1) using a resampling method set by gis:set-sampling-method before gis:apply-raster . For better-looking results, use "nearest_ neighbor" for categorical data and "bilinear" for continuous data. gis:set-sampling-method vegetation-dataset "NEAREST_NEIGHBOR" gis:set-sampling-method elevation-dataset "BILINEAR"

TEST

Repeat the code lines to load multiple rasters into different patch variables. Keep in mind that NetLogo’s memory requirements will increase rapidly.

and later patch-quarry to patches-own . TEST CODE BLOCK 7.5

Bilinear will average several adjacent cells, whereas nearest neighbor will just take the closest cell value.

. CODE BLOCK 7.6

. Skip this example code if you’re only adding the elevation raster. 253

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 7.1. An example raster (left) could either be resampled to a finer-resolution landscape (top right, small dashes) or to a coarser-resolution patch landscape (bottom right, large dashes).

It is likely that NetLogo will run out of memory if you try to load a really large raster landscape into your model. In this case, you have two choices: By default, NetLogo uses 1024m or 1 gigabyte of memory. This is rarely enough for large or multiple rasters.

1. Resample the data to a coarser grid size as we just described (fig. 7.1); or 2. Increase the amount of memory your computer is allocating to NetLogo. This requires modifying the NetLogo.cfg file stored in the NetLogo program folder.4 I M P O RT I N G P L A C E S W I T H V E C TO R DATA

The second basic type of spatial information is vector data. NetLogo will only read a vector shapefile format, so again you may have to use a GIS program to change formats first. Vector data is read into NetLogo similarly to raster data, but you have the option of turning those data into either 4

254

See https://ccl.northwestern.edu/netlogo/docs/faq.html, and scroll to the question, “How big can my model be? How many turtles, patches, procedures, buttons, and so on can my model contain?”

Chapter 7: Modeling with Spatial Data agents or patch variables. The easiest method is to create a patch variable that records the presence or absence of a vector feature. globals [elevation-dataset quarries-dataset] patches-own [patch-elevation patch-quarry]

TEST CODE BLOCK 7.7

to setup ... set quarries-dataset gis:load-dataset "quarries.shp" ask patches [ if gis:intersects? quarries-dataset self [ set patch-quarry true set pcolor red ] ] end This method is quite simple as gis:intersects? only asks if something in the quarries dataset, which is a VectorDataset type, is in the same spatial position as that patch. It works for any type of vector feature—points, lines, or polygons. However, if two quarries (points) fell on the same patch, the code would only mark that patch once. To correct this, we will use a second method that works directly with the vector data structure. To make this work, we have to read through the data, which are stored in a fairly complicated set of nested lists in the vector file, to find the actual coordinates of the points’ locations (fig. 7.2). The first step is still to use gis:load-dataset as before, but the process diverges after that. Table 7.2 shows the structure of the shapefile. Notice that the coordinates are buried deep within the VectorFeature (fig. 7.2).

See the GIS Extension manual, VectorDataset Primitives section, for other topological primitives.

See Chapter 7 in the ABMA Code Repo for step-by-step details on how to manually peel off the VectorFeature data structure's layers.

Table 7.2. A reconstituted spatial and attribute table of the quarries shapefile.

255

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 7.2. A visualized workflow for working with the VectorDataset’s data structure. Boxes indicate the data types and other text represents NetLogo primitives. Arrows indicate that the data type or output is a parameter of that primitive.

TEST CODE BLOCK 7.8

TEST CODE BLOCK 7.9

256

Type in the console: gis:location-of (first first gis:vertex-lists-of (first gis:find-features quarries-dataset "ID" "10.0") ) observer: [-57.70706490103701 32.12431606519094] To turn this into some useful code to actually load at setup , we first create a new breed of agents called quarries as well as some quarry variables to hold the attribute data, and then put all of the steps above inside of a foreach loop. breed [ quarries quarry ] quarries-own [ id name ]

Chapter 7: Modeling with Spatial Data TEST

to setup ... let points gis:feature-list-of quarries-dataset foreach points [ quarry-point -> let location gis:location-of (first first gis:vertex-lists-of quarry-point) let temp_id gis:property-value quarry-point "ID" let temp_name gis:property-value quarry-point "Name" create-quarries 1 [ setxy item 0 location item 1 location set size 2 set shape "circle" set color red set id temp_id set name temp_name ] ] ... end

CODE BLOCK 7.9 (cont.)

The foreach primitive loops through each point in the list and uses the temporary variable quarry-point to hold each VectorFeature in turn (fig. 7.3). We also add two additional lines to extract the property-values of each point and assign them to the quarriesown variables of id and name (see also fig. 7.2). P PE ER RC CE E II V V II N NG G R R AA S S TT E ER R & & V VE EC C TT O OR R D D AATTAA

Once the the data data have have been been copied copied into into NetLogo’s NetLogo’s architecture architecture as patches patches or agents, you you can can then follow follow the the methods methods you you learned learned in in previous previous chapchapters to have have the the agents agents move move and and interact interact with with those those data. data. First, First, initialize initialize agents in Weneed needto tocreate createthem them as as a different breed inthe the setup setup (fig. (fig 7.3). 7.3. We because we we already already have have one one breed breed of of agents—the agents—the quarries. quarries.

257

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 7.3. Imported GIS raster representing an island and vector data representing stone quarries (black dots).

TEST CODE BLOCK 7.10

TEST

DON’T FORGET toolkit is a turtle variable that needs to be initialized in turtles-own .

breed [foragers forager] ... to setup ... ask n-of 1 patches with [ patch-elevation > 0 ] [ sprout-foragers 1 [ set size 8 set shape "person" set color yellow set toolkit [ ] ] ] Now agents can interact with space in several ways. Although the following won’t end up in our final model, for example, they could perceive the elevation in order to walk downhill using:

258

Chapter 7: Modeling with Spatial Data TEST

to go-down-hill ask foragers [ let next min-one-of neighbors with [patch-elevation > 0] [patch-elevation] move-to next ] end Or agents could look for the closest quarry patch (i.e., using the patch version of quarries, code block 7.7) to approach with a directed walk: to walk-quarry ask foragers [ let nearest-quarry min-one-of patches with [patch-quarry = true] [distance myself] face nearest-quarry fd 1 ] end

CODE BLOCK 7.11 TEST

In Davies’ model, agents were restricted from going above a certain elevation-threshold .

TEST CODE BLOCK 7.12 TEST

Note that we have not included code to stop agents crossing water if they are at the coast. Can you modify the code to fix this?

As you can see, combining GIS data with the mobility algorithms we learned in chapter 4 can lead to a richer and more nuanced model capable of asking and answering different types of questions than its more abstract versions. By modeling space in a realistic way, our agents have very well-defined and specific opportunities and constraints, which may explain some of the features of the archaeological record. By embedding agents in a “real” landscape, we can examine specific contexts corresponding to real past landscapes, thus focusing on past people who used to live in a particular place. In the two examples above, a patch variable influences agent movement either by being an agent’s target or by constraining the agent’s movement choices (patch–agent). In the following sections, we will discuss examples of GIS use in an ABM where other types of interactions occur: agent–patch, agent–agent, and patch–patch.

259

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

7.2 Agent–Patch Interactions

The random walk mimics the idea of embedded procurement, as agent mobility is not connected to quarry locations (Binford 1979; Brantingham 2003). TEST CODE BLOCK 7.13

Note that this is written to query the shapefile directly. Can you re-write this to use the quarry agents from code block 7.9?

Agent–patch interaction is often a primary focus of archaeological agentbased models. There are two ways agents typically interact with patches beyond just reading a patch value: they either take something away from it or deposit something into it. The former may include collecting lithic resources, harvesting plants, or reducing the number of fish in a lake. We discussed these in detail in the subsistence chapters (chs. 3 and 6), so here we will focus on the second mode, which was only briefly explored (ch. 5): agents leaving material traces of their behavior by depositing objects on patches. Material traces left behind by past peoples, such as lithics, potsherds, or architecture form the basis of our knowledge of past societies. Thus, a common approach in archaeological ABMs is to model the agents leaving behind some record of their activity (e.g., Kohler and Varien 2012). We can then export a complete in silico artifact spatial distribution for comparison to a region’s archaeological record. First, though, our agents need to acquire some materials to leave behind. Here we will switch our agents’ movement to a random walk and then allow them to acquire resources from quarries that they encounter. to go ask foragers [ move-to one-of neighbors with [ patch-elevation > 0 ] if patch-quarry = true [ reprovision-toolkit ] ] end to reprovision-toolkit let t gis:property-value first (filter [q -> gis:contained-by? q patch-here] (gis:feature-list-of quarries-dataset)) "ID"

260

Chapter 7: Modeling with Spatial Data TEST

while [length toolkit < 100] [ set toolkit lput t toolkit ] end The gis:property-value extracts the "ID" numbers of the quarries (see table 7.2) from the vector file. In this case, our quarries only have an ID number and a name, but they could also contain other attributes that could impact tool acquisition, such as average nodule size, cortex ratio, flakeability, or other indicators of quality (for a worked example, see Davies, Holdaway, and Fanning 2018). Next, we want our agents to drop some of their tools to create a simulated archaeological record. This could occur during specific activities, but here we will have them drop a random tool at each step. Add the following to the setup code inside the ask foragers [ ] . Write the discard-tools below as a separate procedure: to go ... if length toolkit > 0 [ discard-tools ] ...

CODE BLOCK 7.13 (cont.)

TIP Add a turtles-own [ toolkit ] to the top of the code and set toolkit [ ] to the sprout code in the setup to initialize that variable as a list.

TEST CODE BLOCK 7.14

to discard-tools let i random length toolkit ask patch-here [ set assemblage lput (item i [toolkit] of myself) assemblage ] set toolkit remove-item i toolkit end The first line of discard-tools selects a random number up to length toolkit to act as the position along the toolkit list to be 261

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

TEST CODE BLOCK 7.15

TEST

For more on testing techniques, see chapter 8.

DON’T FORGET Add assemblage and assemblage-size to patches-own and initialize them in setup . assemblage should be a list.

TEST CODE BLOCK 7.16

262

dropped. The next part adds that tool’s original quarry ID to the patch’s assemblage variable. Last, we remove that same tool from the agent’s toolkit. Here, the key to avoiding errors is using i first to define the tool, then copy it to the patch’s assemblage, and finally delete the tool from its original location. It’s worth running a good set of tests when manipulating multiple lists, as it is a common source of errors. Next, we will visualize the patch assemblages by adding a display-assemblages procedure: to display-assemblages let mx max [length assemblage] of patches ask patches with [length assemblage > 0] [ set pcolor scale-color red (length assemblage) 0 mx ] end Here we simply use the length of the assemblage list as the number of tools on the patch. Note that using pcolor to visualize this data will overwrite the elevation pcolor , so make a separate button for it or create a separate display-elevation procedure and a SWITCH vizassemblage? to toggle between displays. Alternatively, you can create a slider, TIME-LIMIT, and use it to stop the simulation and trigger the visualization at the end of the run. We can also write a procedure to export the patch assemblage sizes to a new raster dataset that can be then analyzed in any GIS software. Since we aren’t including a file path, the exported file will be written to the model’s directory. to write-assemblages ask patches [ set assemblage-size length assemblage ] let assemblage-dataset gis:patch-dataset assemblage-size gis:store-dataset assemblage-dataset "assemblages.asc" end

Chapter 7: Modeling with Spatial Data Let’s test whether targeted mobility changes the spatial distribution of the simulated archaeological record. In short, we want to know how the archaeological record would look if foragers made sure they always had tools in their toolkit rather than walking around with empty proverbial pockets much of the time. We can create a switch on the INTERFACE tab called random-walk? to test each mobility option (discussed in ch. 4) without having to rewrite the model or make multiple copies of it. Replace the move-to line in go with a conditional test: ask foragers [ ifelse random-walk? [ random-walk ][ target-walk ] ... Then we’ll add code for the two alternative movement types, which should be familiar from chapter 4. to random-walk move-to one-of neighbors with [patch-elevation > 0] end to target-walk ifelse length toolkit < max-carry * 0.1 [ let t min-one-of patches with [patch-quarry = true] [distance myself] face t ifelse [patch-elevation] of patch-ahead 1 > 0 [ move-to patch-ahead 1 ][ random-walk ] ][ random-walk ] end

TEST CODE BLOCK 7.17

TEST CODE BLOCK 7.18

What would happen if we just told agents to move to the nearest quarry without specifying that their toolkit should be getting empty first?

263

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

DON’T FORGET Define the new slider max-carry in the INTERFACE tab and set its range to 0–100. Adjusting code for contingencies often occurs as you discover your agents walking off the map or picking up more weight than they should be able to carry.

torus: a doughnut-shaped landscape topology where an agent going off the top will appear at the bottom, and when traveling out one side will reenter from the other.

The new target-walk is a bit longer since it requires some contingencies. First, we set a conditional with a 10% threshold of their toolkit max-carry length. If the agent’s toolkit is almost empty, they will move toward the nearest quarry; otherwise they will walk randomly. Also, because we are working with an imported landscape—in this case, one with coastlines—there is a possibility that agents will get stuck facing the nearest quarry but be unable to get there because a body of water is in their way. Thus, we add another test ifelse [patch-elevation] of patch-ahead 1 > 0 that allows the agents to make a random step and get themselves unstuck if needed (for more complex coastal landscapes, a stronger unstuck contingency may be required, such as longer random steps or following the coastline). This is an issue known as edge effects. Agents may behave differently (e.g., get stuck) when they reach the edge of the world, a coastline, or another barrier. For an abstract landscape, we may be able to wrap it into a torus, essentially removing the edge effect all together. However, in any realistic landscape or an island context, edge effects are built into the model—agents should not venture off the littoral into the deep water or disappear off the northern border of Utah to reappear on its southern border. If edges are not taken into account in the building of the model, then this can become problematic and skew the results. Designing specific algorithms, such as the one written above, can help to avoid these challenges. In the next two chapters, we will learn more about how to conduct large numbers of experimental runs and compare the outputs, but for now we can just visually compare the two exported raster maps (fig. 7.4). A G E N T – A G E N T & PATC H – PATC H I N T E R A C T I O N S

See chapter 8 for use of network structures rather than Euclidean proximity for agent–agent interaction.

264

The two remaining types of interactions are agent–agent and patch– patch interactions. Agent–agent interactions are useful if agents are directly interacting with one another based on proximity or other spatial characteristics. These include cases of agents reproducing with nearby agents, only moving to unoccupied patches, and passing items to other agents that require using primitives such as in-radius , any? turtles , or min-one-of turtles [distance myself] . The accounting of spe-

Chapter 7: Modeling with Spatial Data

Figure 7.4. Sample results of the ABM with random-walk (left) and target-walk (right). Note that target-walk covers a larger area, showing how reprovisioning can lead to archaeological material being more distributed, even though the agent does random-walk most of the time in both scenarios.

cific items requires much of the same code in agent–agent as it does in agent–patch interactions: to pass-artefact let t min-one-of other foragers in-radius 3 [distance myself] let i random length toolkit let passed? false if t != nobody[ ask t [ if length toolkit < max-carry [ set toolkit lput (item i [ toolkit ] of myself) toolkit set passed? true ] ] ]

TEST CODE BLOCK 7.19

TEST

You need to increase the number of foragers to minimum two for this procedure to work. Call it just before discard-tools in go . See ABMA Code Repo for the working example. TEST The temporary variable passed? helps control which parts of the code should run. Here, the agent should not remove a tool from their toolkit if they haven’t passed it to another agent.

if passed? [ set toolkit remove-item i toolkit ] end

265

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

See the Ants model in the NetLogo Models Library for a diffusion algorithm.

TEST CODE BLOCK 7.20

Calling this once in setup would be much more computationally efficient than repeating the distance measure each time an agent needs the (unchanging) information.

Review the other GIS examples in the NetLogo Models Library to see the breadth of applications.

266

Lastly, there are many instances where patches interact with each other. For example, certain resources, such as a forest, may only grow next to patches with such resources already present, or an item dropped by an agent may spill onto neighboring patches. For example, Riris (2018) modeled the anthropogenic impact of swidden agriculture on tropical forest in Venezuela (see ch. 6). In his model, the rate of forest regrowth in a cell is directly related to the type of vegetation surrounding it. When the cell’s neighbors consist of primary forest, it is more likely to be colonized by pioneering species than one encircled by other fallowed plots. There are also pragmatic reasons to model interactions between patches. Combining patch variables for future use in a model, rather than repeatedly calculating them on the fly, is a good way to save computational time. For example, we might want patches to always know how far they are from the nearest source of a resource such as a quarry or water, so that agents do not have to repeatedly calculate the distance for themselves: to calc-water-distance ask patches with [patch-elevation > 0] [ let p min-one-of patches with [patch-elevation 0] would already be much faster. In the second 271

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

version, the number of patches asked to perform the task will be equal to the number of agents, likely fewer than 40,000. In addition, the if any? turtles-here question does not need to be asked at all, since it is always going to be true when it is the turtle asking, so we can skip that step, which also saves a bit of computational time. To quantify a model’s processing speed in a comprehensive manner, we need to find out which parts of the model are run, how many times, and how long each part takes. This is the purpose of NetLogo’s Profiler extension.12 To enable it, add the following to the top of your model’s code:

TEST CODE BLOCK 7.23

extensions [profiler] Next, add a button to the INTERFACE of the model, name it PROFILER, and then in the COMMANDS box of the button enter:

TEST CODE BLOCK 7.24

setup profiler:start repeat 30 [go] profiler:stop print profiler:report profiler:reset

TEST

The code here is copied directly from NetLogo’s Profiler Manual.

set up the model start profiling run a procedure stop profiling view the results clear the data

This is assuming you have set up your model in the standard way, as we have in this chapter, with the initialization procedure called setup , and the iterating part of the model called go . Now when we push the button, it will run the model through 30 ticks of the model and then output the processing time results into the COMMAND CENTER of NetLogo.

TEST CODE BLOCK 7.25

BEGIN PROFILING DUMP Sorted by Exclusive Time Name Calls Incl T DISPLAY-ELEVATION 30 2000.473 RANDOM-WALK 30 0.887 GO 30 2002.080

Note that times are listed in milliseconds. Headers actually have (ms) but we trimmed them for space.

12

272

;; ;; ;; ;; ;; ;;

Excl T Excl/calls 2000.473 66.682 0.887 0.030 0.720 0.024

https://ccl.northwestern.edu/netlogo/docs/profiler.html

Chapter 7: Modeling with Spatial Data TEST

Sorted by Inclusive Time GO 30 2002.080 DISPLAY-ELEVATION 30 2000.473 RANDOM-WALK 30 0.887 Sorted by Number of Calls GO 30 2002.080 DISPLAY-ELEVATION 30 2000.473 RANDOM-WALK 30 0.887 END PROFILING DUMP

CODE BLOCK 7.25 (cont.)

0.720 2000.473 0.887

0.024 66.682 0.030

0.720 2000.473 0.887

0.024 66.682 0.030

The results are structured in three tables, which is really just one table re-sorted by each of the table’s columns. Each row represents a model procedure that was called at least once. The first column is the number of times that procedure was called or asked to run. The second is the “Inclusive Time” in milliseconds for that procedure, or the total time the model spent within that procedure and the procedures it called (e.g., the inclusive time for go is the total runtime minus setup ). The second column is the “Exclusive Time,” which is the total time spent just on that procedure without any of the procedures it called. The last is the exclusive time per call (rather than summed over all the calls). The Exclusive Time column is the most useful in terms of finding out where the computational bottlenecks are, since it tells you exactly which part of the model has taken the most time overall. If you have designed your model such that everything happens within one big go procedure, you will not get very interesting results here. To make the most of PROFILER, you need to break up the model into separate procedures, as we have done above (i.e., random-walk , target-walk , reprovision-toolkit , and discard-tools ). This is good practice for coding anyway, since it helps to see the overall structure of the model in go , almost like a table of contents (see ch. 2). For this model, we have only a single agent, and in 30 ticks it is possible our agent moved without encountering a quarry, so change the repeat 30 in the PROFILER button code to a higher number, like 200, to make sure that all the procedures are run. This time, turn

We focus on profiling go since the setup procedure is run only once.

Writing out code as separate procedures is known as modular code development (see sec. 2.4).

273

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

random-walk? off and viz-assemblages? on, and click the PROTEST CODE BLOCK 7.26

FILER

button again.

Sorted by Exclusive Name DISPLAY-ASSEMBLAGES TARGET-WALK GO DISCARD-TOOLS RANDOM-WALK REPROVISION-TOOLKIT

Time Calls Incl T Excl T Excl/calls 200 802731.319 802731.319 4013.657 200 15.293 12.510 0.063 200 802759.149 8.599 0.043 195 3.300 3.300 0.017 188 2.784 2.784 0.015 6 0.638 0.638 0.106

You can easily see from this table (just the Exclusive Time) that display-assemblages is the part taking the most time, and it is called every tick. For the sake of this example, we wrote the displayassemblages procedure like this: TEST CODE BLOCK 7.27

TEST CODE BLOCK 7.28

274

to display-assemblages-slow ask patches with [ length assemblage > 0 ] [ set pcolor scale-color red (length assemblage) 0 (max [ length assemblage ] of patches) ] end Within this procedure we have asked every patch ( ask patches ) to assess every other patch ( max [length assemblage] of patches ). While it does work, this is a ridiculously computationally expensive way to do something as simple as updating the patch color. A better way is like this (which is what we did earlier in the chapter; see code block 7.15): to display-assemblages-faster let mx max [ length assemblage ] of patches ask patches with [ length assemblage > 0 ] [ set pcolor scale-color red (length assemblage) 0 mx

Chapter 7: Modeling with Spatial Data TEST

] end DISPLAY-ASSEMBLAGES-FASTER 200 1094.816 1094.816

CODE BLOCK 7.28 (cont.)

5.474

On our test computer this took more than 4, 013 ms per call the first way and only 5.4 ms the second way. Even faster methods would be to make a patchset called land in setup to exclude the water and only ask land to update color (0.4 ms), or to have your agents update the pcolor of the patch when they drop a flake (0.2 ms). Both of these methods have the advantage of most patches not being asked to do anything for most ticks, which greatly reduces the processing time. It might have taken a bit of creativity and time to code, but your model is now 20,000 times faster. If you’re unsure which of your coding methods is going to run faster, then make a new button to run them both. On the INTERFACE, make a new button, call it profile-procedures , and do the same as before but with go replaced by the name of your various procedures: ;setup profiler:start repeat 30 [ display-assemblages display-assemblages-faster ] profiler:stop print profiler:report profiler:reset When you click the PROFILE-PROCEDURES button, it will give you specific timings of those two procedure options without the rest of your model getting in the way. A few other common things to fix when trying to speed up your NetLogo model: 1. INTERFACE plots: While necessary, plots take a lot of computational time; they update when tick is called, so their computational time is included

We don’t provide the code for these even faster methods—try to work it out on your own. Depending on the model, you may need to comment out setup from the PROFILER button code,

and run the model for a while before starting PROFILER. For example, maybe you’re testing something that happens only after the agent population has grown to a certain size. CODE BLOCK 7.29

Note that we have commented out setup. So, use the SETUP button and then run the model forward in time to make an assemblage to display before pushing this button.

If the procedures you’re testing are turtlespecific—like consume or move —then you will need to add ask turtles into the button’s code.

275

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

in the GO section of the PROFILER report. Add a plots-on? switch to the INTERFACE, and if plots-on? to the plot update TIP If your model takes more than an hour to run, be concerned. The next step, experiment design and running, is likely to be an uphill battle.

code so that you can turn them off when they’re not needed. 2. Output to COMMAND CENTER and text files: While show , type , and print are useful for debugging, make sure to comment out those lines when debugging is complete, as writing to COMMAND CENTER or output files slows things down a lot. 3. Doubled asking: If you inadvertently nest ask turtles in another ask turtles , then each turtle will ask every other turtle to do something. This is a not only time consuming but also likely to be wrong. ask foragers [ target-walk ] ... to target-walk ask foragers [ ... ] end

NetLogo will catch this error with Only the observer can ASK the set of all turtles. if you just use the default turtle breed, but not if you’ve created other breeds.

276

This last point is a horrible bug that you may make when breaking up code into separate procedures. The code looks right at first, but upon closer inspection you can see that every agent asks every other agent to perform the task because the ask turtles line was repeated in the go code and in the target-walk procedure it calls. In the PROFILER report, you will see that target-walk is called far more times than it should be. Although these general guidelines are great to make your model run faster, sometimes none of them help; the algorithm just takes time to run. It may be worth checking if an alternative implementation of that algorithm might be quicker. For example, there are plenty of ways to code a random-walk (ch. 4) with many subtle differences in coding and in timing. What may have looked like inconsequential differences between different implementations may take double the computational time (or more). If you have thousands of agents and/or thousands of

Chapter 7: Modeling with Spatial Data time steps, then shaving off even milliseconds for each one will make a large cumulative difference. Benchmarking the timings of algorithm versions using profile-procedures makes it easy to determine which implementation is the fastest and can help you to choose accordingly. However, a famous saying in computer science is “Premature optimization is the root of all evil,” attributed to Donald Knuth (1974). This means “Don’t try to make your code fast too early.” There is a standard sequence of actions for software development: write the code, make it work, test it, profile it, and only then try to optimize it. Trying to make the code as efficient as possible from an early stage of a project can be tiresome, can lead to unnecessarily complicated code, and is often completely unnecessary. For example, in our stone procurement model, setup is quite slow, but there is little point in optimizing the setup procedure because it is run only once. Equally, trying to guess what is slowing down your simulation without profiling your code is likely to be a waste of time. 7.6

benchmarking: a computer science term for measuring the computational speed of an algorithm. Often done before and after a change to the code or to compare different algorithms.

Summary

When building an agent-based model, a tight or loose coupling of the GIS to the ABM may be called for, depending on the questions being asked (Crooks et al. 2019). Following Davies et al. (2019), this chapter used a loose coupling, where data are prepared in a GIS and loaded into NetLogo (e.g., the digital elevation model and quarry points). If the model output is spatial (e.g., distribution of pottery or locations of model’s settlements), data can be uploaded again to a GIS for analysis. Since GIS software generally does not deal well with temporal data, the pipeline of switching between a GIS platform and NetLogo is often the best solution. A tight coupling would involve a close integration between the modeling platform and the GIS platform, as in the MedLanD project described in previous chapters (Robinson et al. 2018). This is certainly possible with NetLogo, thanks to the R extension, which enables NetLogo to be run from the R programming environment (R Core Team 2019), which also provides a powerful way to do GIS analysis, for instance, with the raster (Hijmans 2019) and SP (Bivand, Pebesma, and GomezRubio 2013) packages. Similarly, you can run NetLogo using Python via

277

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Binder and do your spatial data analysis in, for example, Jupyter Notebook (Graham 2018). Many new books on geographic information science (e.g., Huang 2017; Crooks et al. 2019) devote entire sections to coupling GIS and ABMs. While it is not necessary to have strongly coupled software to create a good model, appropriate methods are available if your research project requires them. GIS data and ABM feel like a logical fit, but as with all modeling, we need to take care only to model what is necessary for our research questions. In this chapter we have covered how to import both raster and vector data types into NetLogo’s patch and agent environment. Raster data are fairly simple, since NetLogo’s patch landscape is essentially a raster data structure already. The vector data architecture is a little (okay, a lot) more complex, but once a shapefile of point data is converted into an agentset or a patch variable, we can return to our familiar modeling approaches. The dynamics of human–environment interactions are a mainstay of archaeological research. Modeling these dynamics comes down to asking yourself two simple questions: What is acting upon what? What is the nature of that interaction? The answers depend on the system we model and our research questions. While gaining GIS skills is a whole new area of expertise, it pays off in the long term. E End-of-Chapter Exercises 1. Create an alternative visualization which calculates diversity as the number of unique elements in each patch’s assemblage list, then export this as an ASCII raster. 2. Go to the Pattern and Process website and download the Point Process model.13 You will need to install the Gradient extension.14 Explore the model and learn how to generate different numbers of clusters with different degrees of clustering.

278

13

https://patternandprocess.org/2-6-point-processes-with-clustering

14

See instructions here: https://ccl.northwestern.edu/netlogo/docs/extensions.html.

Chapter 7: Modeling with Spatial Data 3. Combine the code from the Point Process model with different movement algorithms from chapter 4. Explore which one gives the most divergent results depending on the clusters’ properties. 4. Find a freely available topography dataset of an area of interest and import it into NetLogo. Integrate it with the SugarScape model developed in chapter 3 so that it runs on a realistic landscape. 5. In the NetLogo Models Library, find the Tijuana Bordertowns model. It is a great example of an artificially created urbanscape. Explore the model and its parameters. Further Reading ▷ J. Conolly and M. W. Lake. 2006. Geographical Information Systems in Archaeolo . Cambridge, UK: Cambridge University Press. doi:10.1017/CBO9780511807459 ▷ A. T. Crooks et al. 2019. Agent-Based Modelling and Geographical Information Systems. London, UK: Sage Publishing. https://ww w.abmgis.org ▷ I. Romanowska et al. 2019. “Agent-Based Modeling for Archaeologists: Part 1 of 3.” Advanc in Archaeological Practice 7 (2): 178– 184. doi:10.1017/aap.2019.6 ▷ B. Davies et al. 2019. “Combining Geographic Information Systems and Agent-Based Models in Archaeology: Part 2 of 3.” Advanc in Archaeological Practice 7, no. 2 (May): 185–193. doi:10. 1017/aap.2019.5 ▷ B. Huang. 2017. “Agent-Based Modeling.” In Comprehensive Geographic Information Systems, edited by T. J. Cova et al. Amsterdam, Netherlands: Elsevier ▷ D. O’Sullivan and G. L. W. Perry. 2013. Spatial Simulation: Exploring Pattern and Process. Chichester, UK: John Wiley & Sons, September. https://patternandprocess.org/

279

8 MODELING WITH RELATIONAL DATA: RELATIONSHIPS AND EXCHANGE USING NETWORK SCIENCE

8.0

Introduction

In chapter 1, we mentioned the three main functions of modeling: hypothesis testing, data exploration, and theory building. Often there are no firm boundaries between these, and most models combine these different functions. In some cases archaeologists may want to understand the past of a specific small community—for example, traders in a provincial Roman town. Other times, we may want to uncover regularities defining human groups that span time and space—for example, the impact of taxation on large-scale integrated economic systems. Both of these examples will use theory and data; both will test hypotheses. However, the Roman case will be much more precise (e.g., the full size of the town can be modeled) and perhaps realistic (e.g., traders will have limited information). In the second case the model may be more abstract, making the results more generalized, that is, applicable to many different countries and time periods and potentially more tractable, meaning that the dynamics and interactions are better understood. Bullock (2014) has visualized the trade-offs among realism, generality, precision, and tractability that all models face (fig. 8.0). Any one model cannot be highly realistic and precise while also covering a wide range of cases. Think of a map: very precise hiking maps are also highly figurative and never cover a large area, while the realistic (e.g., satellite) map of your entire country would leave you scrambling to find the nearest supermarket or even some of the smaller towns. Similarly, it is not possible to create a simulation that is realistic, gives precise predictions, and covers a wide range of cases. The final direction on the trade-off triangle—tractability—denotes our ability for to understand the mechanisms and explain the results. This means not just showing that factor

OVERVIEW ▷ Theory to data modeling spectrum ▷ Working with relational data ▷ Tutorial on NetLogo’s Network extension ▷ Fundamentals of network science ▷ Testing code

tractability: a feature of models denoting how easy it is to understand the internal dynamics, interactions between processes, and causality chain that leads to the patterns in output.

281

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 8.0. The modeling trade-off between precision, realism, generality, and the additional dimension of tractability. It is not possible to optimize all factors, so the modeler must decide which dimension to sacrifice. Adapted from Bullock (2014, fig. 3).

It’s easy to add new parameters and processes into a model to increase its realism, but reckoning comes when the modeler needs to explain the results. Nontractable models are often referred to as “black-box” models. data-driven models: models maximizing realism and precision, incorporating detailed data and often used to predict future outcomes.

Recall the emulation and explanation types of models defined by Premo we discussed in 6.

282

X increases output Y but being able to trace, step by step, the chain of causality that leads from one to the other, therefore bringing to light the full mechanism driving this relationship. Highly realistic models are often not highly tractable because they usually serve a different purpose, such as prediction. On the other hand, simple models usually have easily understandable dynamics but may not be that useful in the real world (Taghikhah, Filatova, and Voinov 2021). Data-driven models geared toward prediction are often designed with one case in mind—they often maximize precision and realism, yet are difficult to generalize toward other systems and may be low in tractability, especially when the mechanisms driving the modeled processes are not well known. For example, in public health, agent-based models built on theories and data of human behavior are used to predict outcomes of the spread of specific diseases, as we recently have seen in the COVID-19 pandemic (Lorig, Johansson, and Davidsson 2021). They often include realistic GIS maps, detailed population data, and very specific characteristics of a certain disease. These highly precise and realistic models may not be easy for the lay reader to unpack due to the elaborate combination of algorithms and parameters, yet even they are often built up from the simple theoretical framework of SIR models. In-

Chapter 8: Modeling with Relational Data depth research, model building, and testing are required to create these highly intricate (precise and realistic) agent-based models (Hammond et al. 2021). On the other end of the spectrum, physicists are famous for constructing models maximizing generality and paying less attention to the applicability of these abstract representations to “the real world.” A famous joke says that, given a chance, a physicist will start their inquiry with the statement “consider a perfectly spherical cow in a vacuum . . .” This is not to say that other disciplines do not engage with highly general theory-building models; when developing a hypothesis, all scientists need a tool to understand the repercussions of the proposed mechanism. Theory-driven models (sometimes called “subjunctive” or “what-if” models) provide predictions for a range of outcomes that can help refine our understanding and direct future research. Many archaeological simulations fall in the category of explanatory models, where the underlying dynamics of the system are not certain or can even be entirely unknown, yet we want to explain the endpoint of a process. Tractability of these kinds of models is therefore important since we want to answer the question “What is the explanation for . . . ?” This means that understanding the ways that parameters interact is paramount and finding the most parsimonious model is key for developing understanding. The second most common category of archaeological simulations are models that test hypotheses. These tend toward realism and precision. They can be focused on testing what mechanism was at play or examining how particular circumstances led to specific events in the past. In both cases, tractability is key. Here, realism is necessary to establish plausible causal links, while a certain level of precision is indispensable so that the results can be compared with archaeological data. Although there is no prescribed way to evaluate whether a model has the right level of complexity built into it, it is worth keeping in mind at all times the well-known statement attributed to Albert Einstein (Sessions 1950): “Everything should be as simple as it can be, but not simpler.” We discussed parsimony in more depth in chapter 5, since the concept is important for developing a model’s ontology. Model parsimony links strongly with the data we put into our simulations and the data we validate them against. Due to the inherent limita-

Check out Spherical cow on Wikipedia. It is an established scientific concept. theory-driven models: models maximizing generalism, usually exploring relationships and causality and often used to explain phenomena. Subjunctive models tackle the question, “What would happen if . . . ?”

Explanation lies at the heart of the majority of archaeological models. Our research questions usually begin with “Why?” or “How?”

283

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Chapters 4–6 provide an overview of established theoretical frameworks and well-established models.

network science: branch of science concerned with relational data and its collection, management, analysis, interpretation, and presentation (Brandes et al. 2013).

284

tions of the archaeological record, it may not be immediately obvious what kind of data would be generated as a result of a known phenomenon, if any. Frequently, we hypothesize a general process that might have driven the dynamics of past societies that, in the absence of writing, is only theoretically plausible and might have left behind only circumstantial archaeological evidence. In these situations, we would want to develop a model closer to the theory-driven end of the spectrum as it will enable us to make leading steps toward identifying what kind of data or data pattern we should look for. These are often built up from first principles and are frequently based on theories developed in other disciplines. Since archaeological inquiry concerns virtually all aspects of the past, the pool of base models we can draw from extends over all scientific disciplines concerning human groups—demography, economics, sociology, political science, epidemiology, and others. Thus, it is a good strategy to pick up an existing base model from one of these related scientific fields, critically adapt it to your research context, and then examine how it would play out in our models of the past. The in silico archaeological record it generates in the process can then be compared against the physical archaeological record to establish whether the baseline scenario we just tested could be offered as a feasible explanation. Often, the key aspects of past systems we are interested in studying are relationships. These relationships may manifest in similarities between assemblages at different sites, ceramic decorations, trends in architecture, presence of exotic goods, or written mentions. In all cases, data that include relationships need to be treated with robust methods developed to deal with their peculiarities. One of the frameworks used for relational data is network science. By representing relationships in the form of a network, we can dramatically simplify our models and make them more robust. In this chapter, we will use a theoretical model from Crabtree (2015) to demonstrate how to incorporate general theories of exchange into a simple NetLogo model. We will also follow and expand on a tutorial for calculating network statistics by Brughmans (2016) to demonstrate how to use the network extension in NetLogo.

Chapter 8: Modeling with Relational Data 8.1

Theories on Exchange

In 1972, Sahlins published his theories on economics in small-scale societies. They have been recently embraced by many anthropologists attempting to understand how nonmonetary societies establish rules for survival (Crabtree 2015; Hegmon 1989; Kobti 2012). Each of these specifically model exchange between individuals via a relational network rather than just spatial proximity. Anthropological theorists differentiate between exchange and trade (Sahlins 1972). Exchange is a broader term with diverse interpretations that incorporates all kinds of exchanged goods, services, and ideas. The term trade is often used as a narrower version of exchange, frequently involving money as an intermediary and in a market-based context (Renfrew and Bahn 2017, 374–376). Monetary-based transactions can ensure that an individual (or group of individuals) gains income that they then can use to purchase other objects; nonmonetary-based exchange is generally related more to necessities and thus better reflects relationships and group cohesion. In the absence of direct observation of how small-scale societies in the past functioned, these theoretical models of exchange provide a basis for testing how exchange could lead to societal growth, ensure greater survival during years of hardship, or enable group cohesion. Sahlins (1972) defined four types of nonmarket-based exchange: • • • •

exchange: the giving of one object and receiving of another, usually in the same type, and especially goods, services, or ideas. trade: exchange that involves money as intermediary and is market-based.

pooling of resources; generalized reciprocal exchange network; balanced reciprocal exchange network; and negative reciprocity.

Pooling refers to when an individual shares their resources among all participants. In households, there will often be more individuals present than there are providers, so resources may be pooled to a head of household and redistributed equally to household members. Pooling generally comes with no expectation for immediate reimbursement but considers long-term implications. For example, while we may not expect a fouryear-old to supply for the family, when the child is grown she may be expected to take care of her parents. Pooling is always reserved for very close kin, and is generally kept at small groups of people as it is diffi-

pooling: type of exchange where resources are shared among all.

285

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

generalized reciprocal exchange networks (GRN): type of exchange where individuals share their surplus with their kin when asked.

balanced reciprocal exchange networks (BRN): type of exchange where individuals may lend to others but expect to be paid back by the individual who borrowed from them.

negative reciprocity: a type of exchange where an individual takes advantage of another without any intention to repay the debt.

286

cult to scale up, though some societies do pool resources even for larger camps (Bird and Bird 2008). Generalized reciprocal exchange networks (GRN) extend beyond the limited sphere of the in-group that pooling refers to. In generalized reciprocal exchange, an individual will share with relatives if the individual has surplus. Unlike pooling, where sharing is always assumed, in GRN the relative will only ask when they fall short. However, assistance will always be given if there is surplus (albeit sometimes grudgingly), with the idea that the giving individual can always rely on others if they fall short. Sahlins suggests that this will only occur with closely related individuals—siblings, parents, children, first cousins, uncles, and aunts. Otherwise, exchange falls into the next category. Balanced reciprocal exchange networks (BRN) link any individual to any other individual, but generally follow a reputation network. If an individual falls short and needs to borrow, they will be expected to pay back in kind when requested by the lender. If they are unable to pay back, their standing drops, and the borrower will be unlikely to be able to borrow in the future. If individuals share information, you can imagine that the reputation of the borrower would suffer more widely, incentivizing the borrower to repay their loans. The final type of exchange, negative reciprocity, refers to trying to receive something without having to give back for it. It can refer to things like raids on other groups, or tricking an individual into giving something for nothing, thus always benefiting the recipient at the detriment of the giver. In subsistence-based societies with nonmarket exchange, these types of exchange networks appear to be the backbone to how societies function. Thus, they provide a useful theoretical platform for modeling how exchange networks could have worked in the past, how they may provoke growth and increase resilience, and what the underlying social structure may be when one type of exchange is more prevalent over another. Building these rules into a simple model, we will work through the NetLogo Network extension to create a theory-driven model, similar to the model presented in Crabtree (2015). We will model pooling, GRN, and BRN to demonstrate how these three types of networks can interact together or in various combinations.

Chapter 8: Modeling with Relational Data 8.2

Sahlins’s Model of Exchange

We will start modeling the pooling algorithm by creating multiple breeds representing four different households who can then exchange goods— here we will exchange pots.1 Open NetLogo and a new blank model. Create four breeds, named lineageA through lineageD , at the start of the model. As with the GIS extension in chapter 7, we will be using an extension called nw (short for Network) instantiated at the top of our code.2 We also need to create turtles-own variables (which apply to all breeds), that is, a head of household variable to know who to pool resources toward and a pots variable to keep track of the resources. Also, give turtles variables called BRN-list and reputation , that will be needed later. Next, we create our setup procedure, building in our lineages. to setup clear-all create-lineageAs create-lineageBs create-lineageCs create-lineageDs

Extensions are an easy way to boost NetLogo functionality. Model: Sahlins’s Model of Exchange by Crabtree ABMA Code Repo:

ch8_networks .

CODE BLOCK 8.0

.

1 1 1 1

[create-households [create-households [create-households [create-households

"A"] "B"] "C"] "D"]

reset-ticks end to create-households [name] set label (word "head of household" name) set head who setxy random-xcor random-ycor set pots 1 set color blue set reputation 0.95 set brn-list (list)

1

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch8

2

Find the full extension list, including complete documentation for the Network extension, on NetLogo’s website: https://ccl.northwestern.edu/netlogo/docs/nw.html.

DON’T FORGET When initializing breeds, NetLogo requires both a plural and a singular name. TIP Here we pass an input name to the procedure create-households , in our case, this is the name of each lineage: “A,” “B,” etc.

287

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY . CODE BLOCK 8.0 (cont.)

let N random 15 + hatch N [ rt random-float set label (word set pots random

1 360 fd 1 "lineage" name "s") 5

] end

DON’T FORGET Create a switch called pooling? on the INTERFACE. . CODE BLOCK 8.1

.

Alternatively you can write the procedure calls to repay-BRN ... end without anything inside. NetLogo will just pass over them without triggering the debugger.

Here we create one individual, label them as head of household, and then place them randomly in the landscape. We then choose a random number between 0 and 15 and hatch that many additional individuals around the head of household; note the + 1 , which ensures that the family is always 2 or more for pooling purposes. This creates a random number of individuals the head will have to “provide” for. Repeat this procedure for lineageB, lineageC, and lineageD so that we can have four families in our society. The following go procedure includes everything we will write in this chapter, though we will leave several procedures commented out for now (note the semi-colons): to go produce-pots ;repay-BRN ;reputation-update if pooling? [ pool-resources ] ;if GRN? [ GRN-exchange ] ;if BRN? [ BRN-exchange ] consume ask turtles [set size pots] tick end Agents will produce and consume pots, and exchange them by either pooling or engaging in generalized reciprocal exchange (GRN) or balanced reciprocal exchange (BRN). We can imagine that maize or any other food

288

Chapter 8: Modeling with Relational Data substance would be traded within pots, but since pottery is a durable archaeological good, we use these as proxy for the traded substance. To help our visualization of the flow of goods, at the end of go , we ask the agents to adjust their size based on their current pot count. We will model changing numbers of produced and consumed resources because exchange is influenced by scarcity and abundance, so having heterogeneity in the number of objects per individual in the group is necessary: to produce-pots ask turtles [ let M random 3 set pots pots + M ] end The consumption of pots can stand in for consumption of the resource that was inside, natural breakage of ceramics, or just attrition, and will act to reduce the ability of individuals or households to stockpile ceramics. to consume ask turtles [ let B random pots set pots pots - B ] end To write our first exchange procedure, pooling, we begin by asking the agents within a lineage to produce pots, and then give all of those pots to their head. The head of the household will then redistribute pots to each individual in their lineage, ensuring an even distribution. to pool-resources ask turtles with [head != who] [ ask turtle head [set pots pots + [pots] of myself] set pots 0 ]

. CODE BLOCK 8.2

. CODE BLOCK 8.3

. CODE BLOCK 8.4

289

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY . CODE BLOCK 8.4 (cont.)

.

The rounding primitives, floor and ceiling , ensure that you don’t divide pots or humans into fractions. In some cases, it requires additional code to deal with the remainder.

ask turtles with [head = who] [ let my_turtles turtles with [head = [who] of myself] let share floor (pots / count my_turtles) while [pots > share] [ ask min-one-of my_turtles [pots] [ set pots pots + 1 ] set pots pots - 1 ] ] end Here the head of the household is given all the pots, and then iterates through their family group, giving a pot to each member, until all pots are distributed. This means that sometimes some individuals in the household will receive fewer pots, but this will be random. Set up and run the model at this point and see how the agents’ sizes, representing their pot count, fluctuates with each time step. 8.3 Network Models

network: a set of entities (nodes) connected through a set of relationships (edges or links) that represent any type of relationship, from kinship and friendship to trade flows and material culture similarity. topology (in ABM): the relative organization of space/geometry in which agents operate. This may be a 2D plane, cylinder, torus, or network.

290

Network science has become an increasingly common approach in archaeology (Brughmans 2010), thanks to the multitude of applications and relatively simple analytical methods. In ABM, networks provide a topology alternative to the standard spatial approach in cases where relationships matter more than the spatial location. A good example is a peer network—your friends may live on the other side of town, yet you interact with them more often than some of your neighbors living in the same apartment block. In those cases, a network is a more appropriate representation of your relationships. The two components of a network, often referred to as a graph, are nodes and edges. Nodes are the individual entities represented (e.g., individuals, groups, towns), while edges are the connections between them (e.g., friendships, alliances, roads). Edges can be directed or undirected, depend-

Chapter 8: Modeling with Relational Data ing on whether their relationship is symmetrical. If two archaeological assemblages A and B are linked because of similarity, that similarity is the same, whether looking from A to B or B to A, so an undirected graph is used. On the other hand, directed edges can be used to represent a one-way link, such as a one-way street or a link representing feeding behavior (e.g., a forager eats a plant). Bidirectional edges mean that the link between the two nodes is reciprocated, such as a two-way street, mutual friendships, or an exchange relationship. What the edges and nodes represent, their direction, and how the connections are established depends on your research questions. This could be informed by empirical research, simulated according to a specific process such as preferential attachment, or formed at random. Here we will model nodes as individual people and edges as the exchange relationships between them. Network science comes with a wealth of tools to generate networks with different structural properties. There are several network types formed through a randomized process that are often used as null hypotheses (Brughmans 2016). Here we will use the Erdős-Rényi random graph model (Erdős and Rényi 1960). In an Erdős-Rényi network, we randomly choose two nodes from all possible nodes and connect them as a pair; this process is repeated until the model reaches the number of edges defined by the user, forming a network (Newman 2010; Brughmans 2016). We use random networks in several circumstances: when the exact connection doesn’t matter (e.g., because the agents are initially identical), when we don’t know anything about the modeled network so the best bet is to model it as a random one, or when we’re interested in how different social networks would perform and need a baseline. In our model, we examine an Erdős-Rényi network to examine whether observed networks differ from randomly created networks (the null hypothesis). We will connect pairs of agents but limit the edges to the out group, meaning that we will not connect two nodes of the same lineage, though we do allow nodes to have multiple edges. In NetLogo, edges are called links , and they can be used in a similar way to turtles (Brughmans 2016). We will name our links’ breed edges to be consistent with network science lingo. At the top of your code, below turtles-own , add:

nodes: the entities in a network (the dots). edges: the relationships between the entities in a network (the lines).

Erdős-Rényi network: a network, also known as a graph in network science, created by repeatedly connecting two random nodes with an edge until the specified number of edges is reached.

291

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY . CODE BLOCK 8.5

. CODE BLOCK 8.6

.

Try creating a list of lineages ["A" "B"...] and use foreach to sum up all of the possible links rather than counting each lineage’s links in turn before adding them together.

undirected-link-breed [edges edge] Next we will create the generalized reciprocal exchange network, GRN-setup , called from the setup procedure to initialize the network. to GRN-setup let Aconnections count turtles with [ breed = lineageAs ] * count turtles with [ breed != lineageAs ] let Bconnections count turtles with [ breed = lineageBs ] * count turtles with [ breed != lineageBs ] let Cconnections count turtles with [ breed = lineageCs ] * count turtles with [ breed != lineageCs ] let Dconnections count turtles with [ breed = lineageDs ] * count turtles with [ breed != lineageDs ] let totalLinks (Aconnections + Bconnections + Cconnections + Dconnections) repeat (target-density * totalLinks / 2)[ ask one-of turtles with [count edge-neighbors < count turtles with [breed != [breed] of myself]] [ create-edge-with one-of other turtles with [breed != [breed] of myself and edge-with myself = nobody] ] ] end Because we randomly create the number of individuals in each of the lineages, we must calculate the total number of connections each lineage

292

Chapter 8: Modeling with Relational Data

Figure 8.1. Default network layout in NetLogo. Members of each of the four lineages cluster around the head of household.

could possibly have ( let Aconnections... ). We then sum each of these numbers together to get the total possible number of links and divide by two because edges are undirected. Since we want to control the density of the network, we create a slider to represent the proportion of this maximum number of edges, TARGET-DENSITY: 0 represents no edges, 0.5 represents half the maximum number of edges, and 1 represents all possible edges. We then loop over a process where a random agent creates a link to someone outside their household, thereby building up a generalized reciprocal exchange network link by link. According to Sahlins, these would be distant kinship ties, so what we are doing is creating a network of individuals who may count themselves as somewhat related and be willing to offer assistance when called upon, without expectation for direct repayment. Add GRN-setup at the end of your setup procedure after you have populated all your lineages (fig. 8.1). One aspect of network models is their ability to quickly communicate the dynamics of a system using visualizations. NetLogo includes a few layout- primitives for helping to rearrange the network. Some, like layout-spring , must be run many times using repeat before they settle into a stable configuration. Here we will just use the simpler layout-

directed edges: one-way connection, such as a predator eating a prey (trophic networks). undirected edges: two-way connection, such as a reciprocal relationship. DON’T FORGET Add a slider, TARGET-DENSITY, to the INTERFACE tab, with values 0–1 and increment of 0.05.

TIP Turn off horizontal and vertical wrapping using the SETTINGS button on the INTERFACE to improve the visualization.

293

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 8.2. Rearranging a network to be in a circular layout. Here the target-density is lower than in the previous figure, resulting in fewer links overall.

. CODE BLOCK 8.7

.

Changing a network’s layout doesn’t change its structure. It’s only a way of visualizing it. The process we will run on the network is unaffected by the layout. sort turtles according to their who works because of the order we created them.

294

circle to help visualize the link density, though we will keep the lineages together by sorting the turtles according to their who number. Near the end of setup , after GRN-setup , add: layout-circle sort turtles 10 The sort turtles 10 sets the order and spacing of the nodes in our network. If you change the number to something smaller, like 5, you will note the network has a smaller radius. If you leave out sort , the agents will be in a randomized order and not near their lineage members. Adjust target-density and hit setup a few times. You’ll see how the network changes with greater and lesser density of edges. Now that the network is arranged, we can code the actual generalized reciprocal exchange algorithm. Write the following code, add a GRN? switch to the INTERFACE, and uncomment the GRN-exchange line from the go procedure:

Chapter 8: Modeling with Relational Data .

to GRN-exchange if any? turtles with [pots < 2 and any? edge-neighbors with [pots > 0]] [ ask one-of turtles with [pots < 2 and any? edge-neighbors with [pots > 0]] [ if random-float 1 < exchange-probability [ set pots pots + 1 ask one-of edge-neighbors with [pots > 0] [set pots pots - 1] ] ] ] end In this piece of code, agents request a pot from one of their connections and exchanges given a set probability. If the counterpart has any pots left, the exchange takes place. This is a simple way for agents to create a network and exchange resources within that network. You can expand it by, for example, assessing biases in choosing an exchange partner or by analyzing economic mechanisms of when to exchange and when not to. In network science, many metrics explore the position and connectedness of a node within the network, measuring, for example, how central a node is in comparison to its neighbors. While we tend to use R or Python to analyze our model results (see ch. 9), NetLogo does have built-in abilities to perform simple network analyses using the Network extension. This allows you to calculate network measures on the fly and spot-check the model’s functionality before running an entire experiment. We will use a reporter to calculate the average degree of the network and then display it in the INTERFACE tab (fig. 8.3). Average degree measures how many connections an individual node has on average (Newman 2010; Brughmans 2016). For example, a network of 10 nodes and 20 edges will have an average degree of 2 if it is a directed network, or an average degree of 4 if it is bidirectional. Here we follow Brughmans’s (2016) calculations for reporting average degree in a NetLogo model. Add the following reporter to your code:

CODE BLOCK 8.8

For the code to work, you need to return to the INTERFACE tab and create an exchangeprobability slider, set between 0 and 1, with increments of 0.05. For more algorithms relevant to different types of exchange, see chapter 5.

average degree (networks): the average number of edges per node in a network.

295

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 8.3. Adding a REPORTER as a monitor to show the average degree of the network. . CODE BLOCK 8.9

to-report report-av-degree let av-degree sum([count edge-neighbors] of turtles) / (count turtles) report av-degree end We can then display average degree in the INTERFACE tab. Return to the INTERFACE and add a MONITOR. Write report-av-degree in the REPORTER box, and call it Average Degree in the DISPLAY NAME box.

TIP There are many types of statistical measures in network science. We recommend Mark Newman’s book Networks: An Introduction. Note that primitives from the extension start with nw:

. CODE BLOCK 8.10

296

Change the number in the DECIMAL PLACES box from the default to 2, and click OK. Now every time you hit SETUP, you’ll see the average degree of the network. If you change target-density , the average degree will change (fig. 8.3). The NetLogo nw extension is extremely useful for running other network statistics without the need to calculate them by hand as we do above for average degree. We have already added the network extension at the top of the code, so to freely use its functionality we only need to tell it what are the nodes and what are the edges. At the end of your setup procedure, type: nw:set-context turtles edges

Chapter 8: Modeling with Relational Data

Figure 8.4. Three example networks showing average degrees of 5, 10, and 16 (close to maximum). Note that the density increases nonlinearly.

Here, we tell the nw extension that turtles are nodes (first context) and edges are edges (second context). If you only wanted to calculate the network of a specific breed, you would input that for the first context. All is set up now to calculate the average shortest path length of the network. Average shortest path length measures how many steps, on average, it takes to get from any one node to any other node using the shortest route (Newman 2010). Networks with low average shortest path length are known as small-world networks, because it is easy to get from any one node to any other node. Type at the very end of your code: to-report average-shortest-path-length report nw:mean-path-length end Back on the INTERFACE tab, add another MONITOR, and in the REPORTER box enter average-shortest-path-length . The average shortest path length reporter will not work if any of your nodes are isolated (i.e., have no trading partners) as the metric cannot be calculated and your monitor will report false . Finally, let’s explore the betweenness centrality of the nodes. In network analysis, betweenness centrality measures the number of shortest paths that cross a node; at the graph level, it averages these measurements for the whole network. It’s a useful measure for examining how well the network is connected. If measured for a single node, it shows its position with respect to the rest of the network. Add another monitor to the INTERFACE, name it “betweenness” in the DISPLAY NAME, and write in the REPORTER box:

average shortest path length (networks): the mean number of steps between all pairs of nodes in a network. . CODE BLOCK 8.11

. If you repeatedly get “false,” it’s likely that there aren’t enough connections for all of the nodes in the network to be linked in. Increase your targetdensity to make more connections. betweenness centrality of a node (networks): the number of shortest paths between all pairs of nodes that cross through the node.

297

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY . CODE BLOCK 8.12

.

betweenness centrality of a network (networks): the average betweenness centrality of all nodes of a network.

. CODE BLOCK 8.13

The x-axis of the histogram shows the degree, while the y-axis shows the number of nodes that have that degree.

298

mean [nw:betweenness-centrality] of turtles Now your network model will display the average betweenness of the network. Try different target-density values and see how they impact the three network measures we have monitors for. Feel free to explore the other types of network measures available from the nw extension manual and follow the instructions there to examine outputs like eigenvector centrality, clustering coefficients, and other measures. While monitors are useful for seeing summary statistics at the network level, plots are useful for examining their full distribution. To better understand the difference we will create a plot of the degree distribution across the agents in our model. In the INTERFACE tab, create a new plot and name it “Degree distribution,” change it to a BAR plot, and write the following code in the PEN UPDATE COMMANDS box (fig. 8.5): let max-degree max [count edge-neighbors] of turtles set-plot-x-range 0 (max-degree + 1) histogram [count edge-neighbors] of turtles You should now see a histogram displaying the frequency of the agents’ degrees (the number of edges) in their generalized reciprocal exchange network. Note that this plot will only change on setup, since we do not allow for adding or subtracting edges in the GRN. This will change when we introduce the BRN exchange. Finally, create another plot to track the distribution of pots. This plot will be much more dynamic, since at every time step the number of pots an individual has will change as a result of pooling, generalized reciprocal exchange, discard/breakage, etc. As above, add a new plot, name it “Number of pots,” and change its mode to a BAR plot (histogram). Use the following code in the PEN UPDATE COMMANDS box:

Chapter 8: Modeling with Relational Data

Figure 8.5. Creating a customized plot for degree distribution of the entire network.

.

let max-pots max [pots] of turtles set-plot-x-range 0 (max-pots + 1) histogram [pots] of turtles

CODE BLOCK 8.14

Run the model a few times to see how the histograms change. If you modify the target-density of your network, the degree distribution and the number of pots will change accordingly. Finally, we will code one more exchange type identified in Sahlins’s theories of exchange: the balanced reciprocal exchange network (BRN), which is based on reputation and requires in-kind payback. We will simplify it by assigning a reputation to agents that will decrease if they fail to pay back their debts. In reality, reputations may differ depending upon who is assessing them, but for this model reputation will be held constant and visible for all agents. Write a new procedure using the following BRN exchange algorithm:

299

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY . CODE BLOCK 8.15

DON’T FORGET Add another 0-to-1 slider for exchangeprobability-BRN .

DON’T FORGET Remember to uncomment BRN-exchange from go and add a switch for BRN? on the INTERFACE.

. CODE BLOCK 8.16

300

to BRN-exchange if any? turtles with [pots < 2] [ ask turtles with [pots < 2] [ if random-float 1 < reputation and random-float 1 < exchange-probability-BRN [ let lender one-of turtles with [pots >= 2] ask lender [ set pots pots - 1 ] set pots pots + 1 set BRN-list lput [who] of lender BRN-list create-edge-with lender ] ] ] end The above code follows a similar logic to the GRN algorithm. An agent that is running out of pots has a probability of assessing whether their reputation and is sufficient to ask for a loan. If it is, that agent then asks another agent for a pot. The lender’s who number is added to the list so that the agent can remember who to return pots to. You will note that the requesting agent can ask anyone in the world to exchange with; this roughly follows Sahlins’s logic that BRN exchanges will be with anyone, regardless of their relation to you. Finally, we create an edge with the lender to update our social network. The global reputation of an agent will depend on how often they borrow, and whether they pay back the lender. Write a procedure that updates the reputation: to reputation-update ask turtles [ ifelse length BRN-list > 0 [ let R ( 0.05 * length BRN-list )

Chapter 8: Modeling with Relational Data .

if reputation - R > 0 [ set reputation reputation - R ]

CODE BLOCK 8.16 (cont.)

] [ set reputation 0.95] ] end In the above code, an agent sets their reputation to 0.95 if they do not currently owe pots to anyone; it is not quite 1 to enable a small probability that a BRN exchange would be turned down. For every entry on the list, we decrease reputation by 5%, making it so that agents will be penalized for borrowing too frequently. Finally, to make this exchange “balanced,” the agents need to have a method for paying back their lenders. Add another procedure: to repay-BRN ask turtles [ if length BRN-list >= 1 [ while [length BRN-list >= 1 and pots > 1] [ set pots pots - 1 let lender first BRN-list ask turtle lender [ set pots pots + 1 ] ] ] ] end

Notice that agents’ reputation cannot fall below 0.

. CODE BLOCK 8.17

In this algorithm an agent assesses their list of debts and, as long as they have more than one pot that they iterate through their list, repays their lenders. The interaction between this and the reputation algorithm means that once a debt is paid off, reputation will be reassessed and set to reflect the current number of debts. When running this model multiple times, you can see how some individuals end up with more pots while others end up with fewer pots, leading 301

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Run the model with different combinations of exchange strategies (pooling, GRN, BRN) switched on. How do the network measures change?

to an increase in inequality over time. Now imagine that death was tied to whether or not you had any pots, and that children of agents inherited their network connections. In her model, Crabtree (2015) explored how that would impact agents’ survival. She demonstrated that pooling within a household, GRN among relatives, and BRN tied to reputation in a wider community increased agents’ survival chances by buffering them from catastrophic events such as droughts. Although this is a largely theory-driven model, by comparing the simulated populations to the real archaeological populations, Crabtree demonstrated that the exchange networks theorized by Sahlins would have structured the real Ancestral Puebloan society. The applications of both network science and ABM in archaeology are promising and the number of publications is slowly growing (Brughmans 2013). Crabtree (2015) built a more complex version of the above model to examine how exchanges impact survival for the Ancestral Pueblo of southwestern Colorado in the Village Ecodynamics Project agent-based model. Brughmans and Poblome (2016) represented the eastern Roman Empire as a network of markets; Graham (2006) used the Antonine Itineraries as a baseline transport network for modeling the spread of information; Graham (2009) developed a model of interpersonal relationships in ancient Rome based on prestige and gift exchange; and Crabtree (2016) used networks and simulation to examine the beginnings of the wine industry in southern France. In more abstract frameworks, Cegielski and Rogers (2016) used networks to model how individual behavior leads to formation of chiefdoms, and White (2013) combined networks with cultural transmission. Network approaches combined with agent-based modeling provide a useful method for examining the many different ways in which past peoples were connected and to further refine our understanding of how relationships shaped their lives. 8.4 Code Testing You have now written quite a few agent-based models and undoubtedly have come across many code errors in the process. At the early stages of acquiring coding skills, the majority of problems come from incorrect syntax, such as missing brackets or wrong data types being passed (e.g., a primitive asks for an agentset and is given a number instead). These kinds of errors,

302

Chapter 8: Modeling with Relational Data even if frustrating, are easy to catch thanks to NetLogo’s built-in debugger and will dramatically drop in frequency after only a few months of coding practice. Much more difficult to catch are errors in the logic of the code. They represent a situation in which there is a discrepancy between what the code does and what the modeler’s intentions are. In most cases, they will not be caught by a debugger, so a good testing strategy is necessary to ensure that the results we present are not an artifact of buggy code. Here we will describe a testing workflow that combines a few of the techniques that can be used to find and remove bugs from your models.

NetLogo has a suite of options for observing agents and patches. Right-click on a turtle and you will find INSPECT, WATCH, and FOLLOW in the drop-down menu.

V I S UA L I Z AT I O N

The strategy we’ve been deploying all along is simple visualization. If your agents do not move when they should move, then you know there is something wrong with the code. Similarly, you can spot-check whether their behavior is correct by inspecting a few randomly chosen agents over the course of the simulation. Throughout the book, we have done quite a lot of reporting onto the INTERFACE using monitors and plots and inspecting the variables of individual turtles by right-clicking on them. These are exceedingly useful for checking that the dynamics of the model makes sense. And in many cases you can use the COMMAND CENTER to spot-check the simulation. For example, you can write mean [reputation] of turtles a few times during the execution of the model to see whether its value is within a reasonable range. Often we build plots just as a form of testing, and then remove them when finalizing the project. For example, in our case it may be worth plotting the pots distribution for each lineage separately to ensure that each lineage has pots, something you may miss if looking at all the turtles at once.

Copy-pasting code segments is an extremely common source of bugs.

P R I N T STAT E M E N T S & M A N UA L T E ST S

Even if everything looks fine, that is not a guarantee of error-free code. As we develop the code, we need to go through each algorithm step by step to ensure that it does what it is supposed to do. This is the strategy we discussed in chapter 2: armed with pseudocode, follow the logic of each procedure and insert print statements when necessary. For example, if we want to as-

303

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

. CODE BLOCK 8.18

TIP It’s easier to perform this type of test if you limit the number of agents.

304

sure that a given procedure is called the expected number of times, we can check it this way: to repay-BRN print count turtles print count turtles with [length BRN-list = 0] ask turtles [ if length BRN-list >= 1 [ print "Turtles with debts" print "1" while [length BRN-list >= 1 and pots > 1] [ print "repaying is happening!" set pots pots - 1 let lender first BRN-list ask turtle lender [ set pots pots + 1 ] ] ] ] end The first two print statements will give you the number of turtles that should engage in the repay-BRN procedure (total number minus turtles with no debts). If it’s the same as the number of “1”s printed to the COMMAND CENTER, then your code is proceeding the right way. In addition, we check that the repaying is actually happening by inserting another print statement into the repayment code block. It is important to do that after all conditionals to ensure that there are in fact turtles that fulfill the condition. If the COMMAND CENTER does not print the “repaying is happening!” statement, we will need to investigate why it is that no agents have enough pots to pay off their debts. Similarly you can check that the procedure is performing correctly by checking its status and all the variables involved before and after the execution.

Chapter 8: Modeling with Relational Data .

to repay-BRN ask turtles [ print brn-list if length BRN-list >= 1 [ while [length BRN-list >= 1 and pots > 1][ print "-----------" print pots set pots pots - 1 print pots let lender first BRN-list print [pots] of turtle lender ask turtle lender [ set pots pots + 1 ] print [pots] of turtle lender ] ] ] end Here we check that the number of pots before and after the exchange is correct. The examples given here may look simplistic, but the whole point of a bug is that you aren’t aware of it, so testing even the simplest of procedures is necessary. Don’t forget to remove the print statements after testing, as they consume a lot of computational power.

CODE BLOCK 8.19 .

You can also test the “accounting” by checking that the total sum of the pots before and after the transaction remains the same.

TIP You might have noticed the print "-----------" line. This is a handy way to visually separate each iteration of the code.

EXTREME SCENARIO TESTING

The previous testing strategies are performed during code development. Once the model is written, we can focus on its general workings. For example, it is worth running the simulation with values that are outside of the normal range to probe the robustness of the model’s logic. What happens if there are only two agents? Or just one? Or none? What if we set the target-density to 0 or to 1—does the model still run? What happens if an agent doesn’t have anyone to trade with or has two equally good partners to choose from? When running extreme scenarios, it is a good practice to test what happens if values are set to 0, 1, a negative number, and a very

305

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

large number. It usually provides insight into the behavior of the model in situations that may be rare but still possible.3 ASSERTIVE TESTS

As you develop your code, the interactions between procedures become increasingly complex, making it difficult to identify problems. With each new procedure, we may be introducing unintentional behavior into procedures that were developed and tested long before. Building assertive tests into the code is one of the best ways to maintain control. For example, instead of printing the number of pots of each agent, as we did in the previous section, you can test whether the total number of pots before and after exchange is the same.

. CODE BLOCK 8.20

to go ... let sumPots sum [pots] of turtles repay-BRN

.

The primitive type is like print but does not make a new line so you can write several variables and strings together. Also check the show and word primitives.

if sumPots != sum [pots] of turtles [ print "We've lost some pots in exchange!" type sumPots type " " print sum [pots] of turtles ] ... Assertive statements will alert you to when a problem appears only in a very specific situation, that is, the model runs fine except when a rare circumstance happens. These are some of the most difficult bugs to catch since they are unlikely to pop out when you do spot checks. Moreover, these situations may occur when you run a large parameter sweep of your model, aborting a run that may be critical for analyses (see ch. 9). You can also use assertive statements for a so-called reality check. Generating numbers describing the systems as a whole (e.g., total number of exchanged pots) can

Another simple yet powerful testing technique is to ask a colleague to do a code review of your model.

3

306

It is extremely rare but nevertheless possible that there’s a bug in the NetLogo base code. Testing extreme case scenarios once landed one of the authors on a path to a bug in a core Python library while another author found an issue in NetLogo’s in-radius primitive. In those cases, you need to submit an issue to the developers so that they can patch the code: https://ccl.northwestern.edu/netlogo/help.shtml#reporting-bugs.

Chapter 8: Modeling with Relational Data help us to ensure that the artificial world we have created does not exhibit idiosyncrasies. These may not necessarily be code errors but rather unintentional behaviors of the model. If four families of about ten people each exchange 5,000 pots over one tick, we know that this is not a plausible model. Assertive statements help in catching such cases. Finally, a bit of calculator mathematics is needed to check that the probabilities that we have built into the model are consistent with our expectations. For example, in a model including demography, you can print the number of new babies versus the total number of turtles to ensure that your 5% probability of producing an offspring is at approximately the correct probability. Probabilities have a tendency of becoming increasingly dynamic if numerous conditions need to be met. For example, if on top of your 5% probability of producing offspring, agents also need to be in spatial proximity to another agent, then these two probabilities interact. When the population is small, the probability of being in close proximity to another agent is low, but 200 time steps later, when the number of agents is much higher, the probability will increase. This means that the actual probability of producing an offspring changes over the course of one run. Sometimes this is fine or irrelevant for the results; sometimes it is not. Either way you need to identify and control for these kinds of dynamics. Ultimately, the best (while time-consuming) method of assuring the correctness of a model’s results is replication by another researcher (Edmonds and Hales 2003). If done independently, this has a high potential of finding even the most hidden flaws in logic or hidden code bugs. It is also worth spending some time replicating colleagues’ models to ensure that the self-correcting nature of scientific inquiry is maintained. Designing, running, and interpreting a simulation are some of the hardest tasks in research, and because of the formal nature of the work, they are much more exposed to scrutiny than many other types of research. Transparency is the best way to ensure the integrity of our work, even if it leads to inevitable “oops” moments. Digital archaeologists can be harsh critics, so it is worth keeping some perspective on one’s own and others’ work. Plenty of the current archaeological models may turn out to be flawed in one way or another, but they are nevertheless useful in pushing our understanding forward.

These are only a few debugging techniques, so we strongly recommend exploring this topic further to learn about more robust methods such as test-driven development and unit testing.

replication: a reimplementation of a model by another researcher to verify the original model’s correctness.

307

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

8.5 Summary Building agent-based models up from theoretical frameworks developed in adjacent disciplines can help us refine our understanding of complex phenomena. Even in the archaeological record, where we may not be able to observe social processes directly, models that incorporate established theories can aid in helping refine our understanding of the past. Further, by formally modeling these theories, we can test them and advance our theoretical understanding. This is an important consideration when tackling the complexity of many social and natural systems. Simple explanations do not hold water for most systems in the present, so it is equally unlikely that they would do so for the past. Deploying formal methods enables us to start from simple explanations and then continue building on them, getting closer and closer to the complexity of peoples’ lives 200, 2,000 or 20,000 years ago. We also briefly introduced the field of network science. By using the nw extension and established mathematical principles of network statistics, we can evaluate how the structure of social (and other types of) networks might have impacted past communities. These techniques enable us to simplify complex phenomena in a well-developed and mathematically sound framework. Network science is incredibly useful for anyone studying complex systems because their properties and structure are very often described and analyzed using network measures. Their applications to social sciences have been truly paradigm shifting, and they have potential to do the same for archaeology. E End-of-Chapter Exercises 1. We hard-coded in the radius of the network in our model layout circle sort turtles 10 . How could you change this to be dynamic, so that the radius automatically updates when you change the size of the window? 2. In many cases we do not want isolated nodes in our network. Use the properties of the mean-path-length primitive to develop an algorithm that adds a minimum number of edges necessary to ensure that the graph is complete.

308

Chapter 8: Modeling with Relational Data 3. Repeating the same code to calculate the number of links of four breeds is tiresome, especially if you decide to increase the number of lineages. Can you redesign the GRN-setup procedure? 4. Using a set of switches in the INTERFACE, examine how each of these exchange algorithms works. What is the distribution of pots with just pooling, with GRN, or with BRN? How do pooling, GRN, and BRN impact the average degree, betweenness, and shortest path measures? 5. Remember the profiler from chapter 1? The model developed above could be made more computationally efficient. Run the profiler and think about how can you improve its performance. For example, do you have to repeatedly query all turtles to then only have those with pots > 1 perform actions? Further Reading Network science is its own discipline, so there are dozens of books and articles to recommend. Here are a few of our favorites. ▷ L. Borck et al. 2015. “Are Social Networks Survival Networks? An Example from the Late Pre-Hispanic US Southwest.” Journal of Archaeological Method and Theory 22 (1): 33–57. doi:10.1007/s10816-014-92365 ▷ T. Brughmans. 2010. “Connecting the Dots: Towards Archaeological Network Analysis.” Oxford Journal of Archaeolo 29, no. 3 (July): 277–303. doi:10.1111/j.1468-0092.2010.00349.x ▷ T. Brughmans, A. Collar, and F. Coward. 2016. The Connected Past: Challeng to Network Studi in Archaeolo and History. Oxford, UK: Oxford University Press. ▷ T. Brughmans and M. Peeples. 2017. “Trends in Archaeological Network Research.” Journal of Historical Network Research 1 (1): 1–24. https://jhnr.uni.lu/index.php/jhnr/article/view/10

309

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

▷ S. A. Crabtree. 2015. “Inferring Ancestral Pueblo Social Networks from Simulation in the Central Mesa Verde.” Journal of Archaeological Method and Theory 22, no. 1 (March): 144–181. doi:10.1007/ s10816-014-9233-8 ▷ T. Evans. 2016. “Which Network Model Should I Use? Towards a Quantitative Comparison of Spatial Network Models in Archaeology.” In The Connected Past: Challeng to Network Studi in Archaeolo and History, edited by T. Brughmans, A. Collar, and F. Coward, 149–173. Oxford, UK: Oxford University Press. ▷ T. Froese, C. Gershenson, and L. R. Manzanilla. 2014. “Can Government Be Self-Organized? A Mathematical Model of the Collective Social Organization of Ancient Teotihuacan, Central Mexico.” PLOS ONE 9 (1): e109966–e109966. doi:10.1371/journal.pone.0109966 ▷ C. Knappett, T. Evans, and R. Rivers. 2011. “The Theran Eruption and Minoan Palatial Collapse: New Interpretations Gained from Modeling the Maritime Network.” Antiquity 85 (329): 1008–1023. doi:10. 1017/S0003598X00068459 ▷ M. E. J. Newman. 2010. Networks: An Introduction. Oxford, UK: Oxford University Press. ▷ A. L. Barabási. 2016. Network Science. Cambridge, UK: Cambridge University Press. ▷ M. O. Jackson. 2008. Social and Economic Networks. Princeton, NJ: Princeton University Press. For a truly thorough bibliography, see: https://historicalnetworkresearch.org/bibliography/#Archaeology.

310

N OT E S

9 DATA A N A LYS I S : L E V E R A G I N G DATA SCIENCE TO EXPLORE ABM RESULTS

9.0

Introduction

Throughout this book we have explored how modelers use data. We validated a model’s dynamics by comparing it to archaeological datasets (chs. 3 and 4); we made sure that the model’s mechanisms were reasonable and justifiable given the knowledge of human behavior based on data (ch. 5); and we brought in both spatial data (ch. 7) and relational data (ch. 8) to incorporate into our models as input. In this chapter, we will talk about a different type of data—data that describes not the real world but the one we created in our simulation. Every model goes through the phase known as experiment design, which generates this artificial data. We will examine how to generate and analyze model outputs that will turn this whole endeavor into publishable science. Let’s say you just watched 10,000 agents interact with each other and with their environment for 10,000 time steps, and you have a feeling that you know what is happening. But can you demonstrate it? Most of all, how can you convince your readers, who are most likely not going to run your model themselves, that your intuition is correct? The task now is to demonstrate empirically that a given pattern occurs reliably under certain conditions; that specific factors, encoded as parameters, result in distinct outputs; and that you can explain why it happens. We will go through the process step by step using the set of questions in table 9.0 as our guide. We will: 1. Look at the types of data that a model can collect and export and at methods for understanding model dynamics; 2. Examine how to put a model through its paces to generate the range of data needed for analysis; and 3. Explore how to use NetLogo’s BehaviorSpace tool to undertake parameter sweeps in an efficient fashion.

OVERVIEW ▷ Principles of experiment design ▷ Tutorial in NetLogo BehaviorSpace ▷ Calibration, sensitivity analysis, and parameter sweep ▷ Analyzing output data in Excel, R, and Python ▷ What is emergence? ▷ Documentation and dissemination of ABMs

experiment design: the final phase of the modeling process in which the modeler experiments on the modeled world by running the simulation in different configurations (scenarios). Computational approaches, including GIS and statistical methods, are all used to analyze artificial data in the same way they would be applied to real-world datasets.

313

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY Table 9.0. The questions in experiment design and analysis addressed in this chapter.

What kind of artificial data do I need to collect? How it generated? How long should I run my model for? When and how should it stop? How to collect and export data? Should it be done at every step, at regular intervals, or at the end of the simulation run? Do I need to run two alternative scenarios (scenario comparison) or a range of slightly different scenarios (parameter sweep)? How will I vary my parameters? What rang do I want to test? How many tim do I need to run each scenario? Do I need to run all parameters, or can I hold some constant? How can I analyze the relevant data? And how quickly can I learn R or Python? Do I need to know why the results are the way they are? How can I explain the process behind the recorded trends? Do my model exhibit emergence? How do I document the code and what do I need to include in the publication?

scenario: a particular combination of parameter values used to set up the model. . run: one iteration of a scenario. . sweep: shorthand for “parameter sweep.”

314

section: 9.1 section: 9.1 section: 9.1 section: 9.2

section: 9.2 section: 9.2 section: 9.3 section: 9.4 section: 9.5 section: 9.6

We will be talking about some important methods in the experiment-design phase of simulation development, such as sensitivity analysis, calibration, and full parameter sweep, also known as the exploration of the phase space. A set of well-designed experiments can make or break a model, so it is important to get it right if we want to present robust results to a scientific audience (Lorscheid, Heine, and Meyer 2012). Before we address these questions, let’s quickly run through some of the terms we use in this chapter. A scenario is a singular setup of the model with set values for each of the parameters—think of it as a precisely defined world. With different values of parameters, this world will be slightly different. A run is one iteration of a scenario. If your model is stochastic, you will be conducting multiple runs of each scenario, each with its own random seed (fig. 9.0). Finally, a sweep is a set of multiple

Chapter 9: Data Analysis

Figure 9.0. The relationship between a scenario, a run, and random seeds. One scenario represents the artificial world governed by specific parameter values. For each scenario we perform multiple runs, which use different random seeds, to simulate multiple alternative but equally possible trajectories of the model.

scenarios, each with slightly different parameter values, repeated over multiple runs to account for a model’s stochasticity. We will also demonstrate some basic steps in data visualization using three separate data analysis frameworks, so that we can generate publishable figures. Finally, we will talk about the fundamentals of open science and why it matters to be as transparent as possible in one’s research process. One of the most important aspects to writing a model is the peer review and publishing of your code so that it can be reused. In this spirit, throughout the book we have used agent-based models published by our colleagues in archaeology and beyond. Publishing one’s code is important, as it helps in model refinement and development and in demonstrating the ways that models (of any kind) can and should be reviewed by other scientists. With each iteration of this process, we build on previous work, advancing our understanding of the past and helping to develop better methods—ultimately leading to better science.

Note that some authors (somewhat confusingly) use “a simulation” to mean “one run of the simulation.”

315

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

9.1 Running Models At a certain stage in the research process, there comes a point when you need to stop the primary code development and actually run the model, and run it a lot. The goal at this stage is to fully understand the dynamics of the model by manipulating the input parameter values and observing how the model reacts under a wide variety of scenarios. We discussed parameterization, where you select specific values or ranges for each input parameter, in chapter 6. Before we examine how to undertake this process more systematically, we will examine how to collect and export different types of data from your model. The Gaulish wine model that we introduced previously, AmphorABM (Crabtree 2016),1 is a good test case because it began with a simple archaeological observation: namely, that in late Bronze Age southern France, Etruscan wine amphorae were replaced by Greek amphorae. The model tests what aspects of trade, population dynamics, and/or wine preference could have influenced that transition in pottery types. To test this, the author generated a range of different types of model outputs and compared them to the archaeologically observed patterns.

One author (CW) once spent a month designing and experimenting with many different toy landscapes and output measures to tease apart a confusing part of his model’s dynamics. The experiment-design phase can take up to 40% of the total time of a modeling project. ABMA Code Repo: ch9_AmphorABM_analysis

W H AT DATA TO C O L L E C T ?

Our first step in examining AmphorABM will be establishing what kind of data we want to collect from the model. Do we want to count the number of people, the amount of wine they produce, or the number of amphorae they store it in? Are we interested in the spatial distribution of Greek versus Etruscan winemakers? Or perhaps we need to record the rate of change? Unfortunately, there are no right and wrong answers here. However, in most cases, the two guiding criteria for collecting artificial data are research questions and the archaeological data available to us. If the initial question is, What w the maximum amount of wine that could be produced in th area under certain conditions?, then we need to calculate how much wine our agents produce. If we asked, How quickly would Greek wine replace Etruscan wine if people had different levels of preference for the former?, then recording the proportion between the two

DON’T FORGET You’ll need to generate some artificial data for validation purposes as well.

1

316

You can find all code written in this chapter in the ABMA Code Repo: https://github.com/SantaFeInstitute/ABMA/tree/master/ch9

Chapter 9: Data Analysis over time, or the time step at which there is more Greek than Etruscan wine available, is the right way forward. Bringing the archaeological record into play may help us here. If we need to know Under what conditions the density of viticulture in different parts of the studied area consistent with the archaeological record?, we will need to record the presence/absence of winemakers on each patch and its changes overtime. This is also a good moment to consider the quality of the archaeological record and the biases it inevitably involves. Can we depend on the spatial distribution of the archaeological record we are comparing to? Or is that distribution mostly a result of a recent road construction? Is the number of amphorae a good proxy of the amount of wine produced in the region? Or are we missing all of the local wine because it was stored in perishable containers? Sometimes it is possible to overcome some of these issues by focusing on relative rather than absolute numbers. If there is no reason to suspect that the proportion of local vs. exported wine changed over time, then amphorae can be treated as a relative proxy for the total production. Often, the only data patterns that are robust enough are presence/absence or general trends such as increase, decrease, sudden change, or a plateau. This is obviously not ideal, but ultimately we need to work with the data that is available to us at the current moment rather than trying to guess what future discoveries may bring. If the patterns of the archaeological record change significantly in the future, so will our interpretations regarding the processes that led to its creation, leading to more opportunities to build agent-based models. HOW LONG SHOULD YOU RUN THE MODEL?

The first important point of experiment design is: How do you know when to stop the model? Most models are stopped either after an arbitrary number of ticks (e.g., after 500 years), or when the model has reached a point of equilibrium. Arbitrary stop conditions are usually justified with the research context. For example, in AmphorABM , the Romans arrive after 500 years, changing the dynamics, so it makes 500 ticks a reasonable stopping place. A point of equilibrium is reached when the model comes to a fixation, that is, does not exhibit any new behavior. A rule of thumb is to stop the model when we can no longer learn anything new from it. It might be quite

Sometimes you can use one data pattern to normalize another. For example, contrasting the number of households vs. the number of amphorae could give us a rough wine consumption per capita.

point of equilibrium: a moment in the simulation run when the model stabilizes and nothing new can be learned from it.

317

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

TIP Population dynamics often cause the death of all agents under a wide range of parameters. Don’t be alarmed when this happens in your model.

coefficient of variation: the variance divided by the mean of a variable.

. CODE BLOCK 9.0

DON’T FORGET While NetLogo will always export a PNG image, we have to write in the .png extension as a part of the filename.

318

clear when this happens —because, for example, all agents have died—but often it is a bit subjective. In the Wolf–Sheep Predation model from chapter 6, for example, equilibrium is reached when the oscillations between predator and prey numbers stay within a certain magnitude; they do not ossify at one number but fluctuate relative to each other in a stable state. This model may never stop, because under this condition it is always changing, but we aren’t learning new information from it. This state—of a model fluctuating consistently around a stable mean value or increasing until infinity—is fairly common. Quantitative analysis can help determine how long you need to run a model in these cases. Rather than just eyeballing it, ten Broeke, van Voorn, and Ligtenberg (2016) suggest calculating the coeffici t of variation to determine when a model run has gone long enough that the full variance has been captured. To calculate coefficient of variation (CV) you divide the standard deviation by the mean of a specific output measure. However, to assess variance and mean of each population, we will need a long-term record of their population sizes. In the Wolf–Sheep Predation model we could create a new sheep-pop global variable, initialize it as a list in setup , and add the value of count sheep to this list each tick using lput . The plotting command would thus be: plot standard-deviation sheep-pop / mean sheep-pop The sheep population dynamics oscillate widely and somewhat unpredictably with default settings, and vary per run due to the stochastic elements of the model. However, the CV of sheep-pop is nearly always stable by the 2,000th tick of the model. Again, this feels a little subjective since we are still eyeballing the point when the CV of sheep-pop becomes stable, but we can add another 500 ticks to be sure that the model is no longer changing beyond this point. In most models where the resource landscape is a limiting factor, that is, there is a carrying capacity, the population size will eventually find an equilibrium point. H O W & W H E N TO E X P O RT T H E DATA ?

Now that we have designed the run and decided on the artificial data, we need to extract that data from the model. There are several methods to export output data from a NetLogo model. You can export the VIEW or any plot by right-clicking on it. For repeated export, NetLogo offers a variety

Chapter 9: Data Analysis of primitives that usually start with export- and require a filename as a parameter. To export an image of the map, just use the primitive exportview : export-view "my_map.png" Using the primitive word , we can also string together a combination of text and parameter values to come up with a more useful and meaningful filename: to export-my-data export-view (word "harvest" harvest-amount "_winepreference" weighted-trade-choice "_" date-and-time ".png") end When word has more than two parameters, you must wrap the whole string in parentheses. The parts without quotes are parameters, but the value of those parameters will become part of the filename, so "harvest" harvest-amount would become, for example, harvest20 . If you’re exporting multiple plots from the same scenario that have the same parameter values and therefore the same filename, you need to come up with a unique name; otherwise, they will overwrite each other and you’ll be left with the image of only the last run. The date-and-time variable provides uniqueness since each run finishes at a slightly different time. Any plot that is a part of your NetLogo interface may be exported with export-plot "plotname" "filename.csv" , where "plotname" comes from the NAME box you filled in when you created that plot. Note that plots are exported as actual data in comma-separated values (CSV) format, not as an image of NetLogo’s plot. We will come back to how to visualize and analyze these data later in the chapter. For now, just make sure that your filename ends in .csv. You can export data during the run or once the simulation is finished. Asking the model to create outputs takes quite a lot of computational power, as we saw using PROFILER in chapter 7, so limit your output to the end of a run whenever possible.

. CODE BLOCK 9.1

. CODE BLOCK 9.2

You can also use the primitive random to generate unique filenames.

To change the plot name, right-click on it and choose EDIT. Write the new name in the NAME box.

319

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

You could call the export-my-data procedure: • • • •

at any point with a button on the INTERFACE; every tick by putting it at the end of the go procedure; every n number of ticks using remainder in go ; or at the end of the simulation within a stop condition.

Perhaps you want to get a sense of how something like the agents’ spatial distribution changes over the course of a run, but every tick would be excessive. In this case, add the following to the end of go to export the view . CODE BLOCK 9.3

Change 100 to 5, 10, 1,000, or whatever frequency of output works best for your model.

only every 100 ticks: if remainder ticks 100 = 0 [export-my-data] If you only need to export data at the end of the simulation, do it within a stop condition in the go procedure. Make sure that the export commands come before stop or the model will stop before exporting anything.

CODE BLOCK 9.4

Note that this is equivalent to exporting a line plot of plot total-amphora .

320

if ticks = 500 [ export-my-data stop ] To generate output directly from the code, simply use the file-open , file-print , and file-close primitives to create your own exportable data table. To have the best of both worlds, you can record a value throughout the simulation and then export that data at the end of the run. For example, in chapter 3 we coded in the creation of the archaeological record over the course of the simulation. There was no need to export anything per tick; we just waited for the occupations to accumulate and then examined one map at the end. In AmphorABM , we might be interested in the total amount of amphorae created during a run. For this we just need to add a new total-amphora to globals and, within each procedure where farmers produce their wine, add a line to increase the total-amphora count accordingly (i.e., harvestWineEtruscans , after set EtruscanWine. . . , add set total-amphora total-amphora + 10 , then repeat for the

Chapter 9: Data Analysis Greeks. This counter will then accumulate over the course of the run, and we can export that variable’s value once at the end of the simulation. Alternatively, you could initialize a list globals [total-amphora-list] and fput the total number of amphorae to it at every tick by calling the following in go : to collect-data set total-amphora-list fput total-amphora total-amphora-list At the end of the run, you’ll have a record of how many amphorae were used at each time step. Be aware that the setup of a model often creates an initial burn-in (or warm-up) phase that is quite unlike the middle of a run, and therefore may not be representative of your model’s dynamics. For example, the landscape might be completely untouched or all the agents might be at age 1. This may unrealistically increase harvest rates right at the start of a run or negatively affect reproduction dynamics since no agents are of age to reproduce yet. In AmphorABM , you may notice a rapid death of Etruscans at the 84th tick (assuming default settings). This is caused by the Etruscans all being born on the day of their arrival and having the same life expectancy (Etruscanarrival + life-expectancy = 84). We often discard data from the burn-in period when we collect the long-term output variables. This is easy to do with a simple conditional if ticks > 1000 [collect-data] . Again, how long of a burn-in period to use will require some experimentation and a thorough understanding of your model’s dynamics. 9.2

Running Experiments with BehaviorSpace

We talked about parameterization in chapter 6, and how to use the literature to select an appropriate range of values for each parameter. But once you have several parameters, each with their own range of values, you need a systematic way of testing them all. This is called a parameter sweep and is usually run by holding most of your parameters constant while incrementing the value of one parameter at a time, which you then repeat for all the other parameters. To do this manually would be time-consuming and la-

. CODE BLOCK 9.5

warm-up/burn-in period: the opening phase of the model’s run when the dynamics can be affected by the initialization.

TIP Initializing variables with random values (e.g., random age between 0 and 60) helps to limit the impact of initial conditions. A rolling list, using a combination of fput and but-last , will also discard the burn-in data. parameter sweep: systematically testing a range of values for several parameters, i.e., scenarios to determine the range of outcomes.

321

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

phase space: often multidimensional space of all possible states of the model.

hard-coded: entering a parameter value directly into the model’s code rather than as an adjustable parameter.

TIP The experiment name will end up in the default filename for the output files, so be more creative than “experiment1.”

DON’T FORGET Every additional parameter multiplies the runs needed. Ten iterations of eleven runs is 110 runs and 1,210 runs with a second parameter added. This number tends to go up really quickly. Recall that we use to indicate that you should select an appropriate value to enter here.

322

borious, so we will use NetLogo’s BehaviorSpace tool, found in the TOOLS menu. It allows you to systematically run your model through a parameter sweep and collects the input and output values into a table for export. A sweep of your model’s parameters is necessary to fully understand the dynamics of the model and to evaluate how the inputs are connected to the model outputs. The multidimensional space of all possible states of the model is known as the phase space. It is rarely possible to exhaustively sweep the parameters to reveal the full phase space of a model; instead researchers usually focus on the most promising area. We will first describe how to perform a parameter sweep and how to produce plots from the output, then we will return to describing the process of analyzing and interpreting the results of your simulation in sections 9.3 and 9.4. The first step to using BehaviorSpace is to make sure that the parameters you’re interested in are not hard-coded in the code but are part of the INTERFACE as sliders, choosers, and switches. For example, instead of calling crt 10 , you can have a slider init-agents and use crt initagents . BehaviorSpace only uses the parameters from the INTERFACE to run experiments, so it needs that slider. If BehaviorSpace tries to adjust a variable that is hard-coded using set within the CODE tab, NetLogo will overwrite it or report an error. For example, in AmphorABM , the proportion of patches that are mines is currently hard-coded in the setup and needs to be replaced with a slider. In AmphorABM , open BehaviorSpace (fig. 9.1) from the TOOLS menu, and create a new experiment. BehaviorSpace automatically lists all the INTERFACE parameters with their current value in the form of, for example, ["weighted-trade-choice" 50] . A guide below the parameters box shows you how, for each parameter, you can do any of the following: • Enter a single value: ["weighted-trade-choice" 50] . • Run for specific chosen values: ["weighted-trade-choice" 25 50 75] . • Increment up through a range by a set amount: ["weightedtrade-choice" [0 10 100]] , where the additional brackets include , , . Assuming all other parameters only have one value selected, the first scenario in the above list will only run the model once, the second will

Chapter 9: Data Analysis

Figure 9.1. Example BehaviorSpace EXPERIMENT dialog box for AmphorABM. The top two variables show different ways of setting parameters for different runs of the model. “Metals?” lists the variable values, while “weighted-trade-choice” has extra square brackets to set up an incrementally increasing variable. Note also the boxes for REPETITIONS, MEASURE RUNS..., and FINAL COMMANDS to export a plot to a CSV file.

323

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

seed: an initial number input to a (pseudo)random number generator used to allow for reproducibility in stochastic models. Check out the Random Seed Example in the NetLogo Models Library.

TIP If you define a reporter, the column header in the output data file will be labeled using the reporter itself.

behaviorspaceexperiment-name is another primitive useful for filenames, if you plan to use the same directory for the output files of several experiments. However, the REPETITION NUMBER

box does not have an associated variable.

For really large numbers of runs, use multiple computers to run BehaviorSpace many times simultaneously. Merge the outputs afterward, but be careful not to overwrite files.

324

run it three times, and the third will run it eleven times (i.e., from 0 to 100, increasing the value by 10 each time). If you then choose to vary a second parameter, it will run through both with every combination for each. If your model is stochastic, you will also have to run it multiple times to establish the central tendency and variance in the outputs. Enter the number of iterations, such as 10, in the REPETITIONS box. Make sure SETUP COMMANDS has setup and GO COMMANDS has go . For reproducibility, you should include a seed for the random numbers generator as one of the parameters. This can be easily done with the random-seed primitive and a slider to give the generator the initial input. NetLogo leaves the output measures entirely up to you, but it includes count turtles as an example. The output measures can be anything that is structured as a reporter, each placed on a separate line. For example, you could just enter total-amphora on the line below count turtles . Since we might modify the length of the run and will still want to compare the total-amphora , we may choose to switch that to total-amphora / ticks to get an average number of amphorae created per tick. You can also define a reporter in the main code as a to-report procedure and then call it from BehaviorSpace. AmphorABM has hard-coded stop conditions, but if it didn’t, those could be entered in the STOP CONDITION box as not any? turtles or by entering 500 in the TIME LIMIT box at the bottom. Likewise, if you did not code export commands per tick or every 100 ticks, you could put commands like export-view into the FINAL COMMANDS box, again each on a separate line. Make sure to use word with your parameter values to create unique filenames for your exported files. If you have multiple runs of each scenario, add behaviorspace-run-number to the filename so that each iteration does not overwrite the previous ones. Click OK to save your experiment, save your model as well, and then run your experiment. Before it starts, you have the option to turn off the view, plots, and monitors, which will speed up your experiment’s runtime. We recommend TABLE OUTPUT, which we’ll use later in the chapter for a brief analysis, though both TABLE and SPREADSHEET OUTPUT contain the same data.

Chapter 9: Data Analysis Lastly, NetLogo will auto-detect the number of processing cores in your computer and recommend that you run your experiment’s runs in parallel across all of these cores to minimize the time needed to conduct the experiment. HOW MANY TIMES SHOULD YOU RUN A SCENARIO?

Earlier, we simply put 10 in the REPETITIONS box, but how many iterations of a scenario are necessary depends on how much variance your model produces. You may have to do a few trial sweeps to assess that. In general, it’s better to run the model more times rather than fewer. In most cases, you will be looking at the order of 100 rather than ten runs per scenario. The coefficient of variation procedure described in section 9.1 may also be used to determine how many repetitions of each scenario are needed to capture the range of variation in the model’s dynamics. In this case, the analysis would have to be conducted outside of NetLogo, since we cannot compare the results of multiple runs within a run. However, we can use BehaviorSpace to run a large number of runs that export a final value, then calculate the coefficient of variance of these multiple runs to see when adding more runs no longer modifies the CV, as done by Gravel-Miguel et al. (2021, check the supplementary information for details).

TIP If you want to use your computer while your experiment is running, leave one core open so you still have processing capacity left.

M O D E L C A L I B R AT I O N & S E L E C T I O N

A full parameter sweep may be computationally impossible depending on the number and range of your parameters, the complexity, or the runtime of your model. The first strategy to deal with this problem is to go through a time of reckoning and reduce the parameter space to those that are actually relevant. Each additional parameter you include increases the dimensionality of the model, making the analysis a magnitude more complex. A second, and complementary, approach is calibration. This method involves using data to evaluate whether certain parameter values produce reasonable output values (Romanowska 2015b). Most archaeologists should be familiar with how tree ring sequences are used to create calibration curves for radiocarbon dating. Again, we know that the Gauls did not all die, so any parameter range that leads to their extinction can safely be ruled out, as can

calibration: using an external data source to reduce parameter ranges to a narrower and more plausible set.

325

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Use the DUPLICATE button to copy the original experiments, then change only the required value to ensure that you have correctly set up the new experiments. Introducing errors while manually entering parameter values is terribly easy.

reproduction rates that lead to implausible population densities. Very robust parameter estimation and calibration techniques can be found in modeling literature, and we recommend getting to know at least a few of them (Thiele, Kurth, and Grimm 2014). While we recommend always running a parameter sweep to make sure you understand the model’s dynamics, your research questions may also require running alternative scenarios representing different hypotheses. For example, you can run a scenario in which different types of wine merchants trade with each other, and another one in which they only trade with their own kin. Scenario comparison can be done in BehaviorSpace with, for example ["metals?" true false] , or by creating a few specific experiments. Before moving on to the next section, run AmphorABM with ["weighted-trade-choice" [0 10 100]] , ["metals?" true false] , and three repetitions per parameter combination in BehaviorSpace. Make sure to uncheck the MEASURE RUNS AT EVERY STEP box since we only need to collect results at the end of the simulation. For the output reporters, include count turtles and total-amphora . Also export the Wine plot at the end of each run using a filename that includes the varying parameter values and behaviorspace-run-number so that the plots do not overwrite each other (fig. 9.1). 9.3 Working with BehaviorSpace Output Data

The spreadsheet format is known as long data format, while the table one is wide.

326

Both BehaviorSpace export formats—spreadsheet and table—are saved in the portable, open, and plain-text comma-separated values (CSV) file format. The table format is structured in two parts. The top six lines provide a header with the name of the model and experiment, the world dimensions, and the date and time of the run. The main table is organized such that each column is an input parameter or output variable (input comes first) and each row represents one run of your model. A full treatment of data visualization and analysis techniques is beyond the scope of this book. However, there are a few standard data analysis packages and several common plot types that you’ll likely come back to again and again. Here we will cover Microsoft Excel, R, and Python, showing how to create an x—y scatter plot, a bar plot, and a line graph.

Chapter 9: Data Analysis For a more extensive treatment of exploratory data analysis, we recommend Wickham and Grolemund (2017) and McKinney (2017). MICROSOFT EXCEL

Among quantitative social scientists, Microsoft Excel (and the derivatives such as Google Sheets or LibreOffice’s Calc) receives a lot of derision, but it remains nearly ubiquitously available to researchers and students alike and is particularly good at quickly tossing together a plot to display some data. It is unlikely to be an efficient solution once the simulation output multiplies into numerous folders full of separate data files, so most modelers move relatively quickly toward scripting languages (Davies and Romanowska 2018). Excel can usually open a CSV file correctly from the FILE menu, or sometimes just if you double-click on the file. However, if there are extra commas (e.g., inside quotes or parameter names) in any of the columns, the resulting spreadsheet will be all jumbled. If this happens, clean out the extra commas in a text editor before opening your CSV in Excel. We have varied weighted-trade-choice and metals? as the experiment’s input parameters, so we now want to plot one of those against population size to see what the effect may have been. Use your mouse to drag select just the header and data in the weighted-trade-choice column, then hold CONTROL (COMMAND on Mac) to also drag select the COUNT TURTLES column the same way. Once your columns are selected, find the INSERT SCATTER (X, Y) button (SCATTER on Mac) in the INSERT menu, CHARTS section. Pick the option with no lines and Excel should create your plot with weighted-trade-choice as the x-axis and your final population size on the y-axis (fig. 9.2). Interestingly, this plot shows that as the preference for Greek wine increases, there is a positive effect on the total population size ( count turtles includes Gauls, Etruscans, and Greeks). It is unclear why that might be, but further simulation and exploration of this effect would certainly be warranted. We have just plotted both the weighted-trade-choice scenarios together, but we might be interested in whether metal mining had an impact on population size. For this we will create a paired bar plot, which is a little more difficult in Excel. First, select the all the data columns and rows (i.e., without the six header rows), and then use the SORT button on

At the 2019 CAA (Computer Applications in Archaeology) conference, a debate broke out about whether Excel should be taught to archaeology students at all, as it encourages bad habits that go against open-science principles.

An Excel update changed how the DATA menu's FROM TEXT import feature works. This new method now formats the data columns oddly, which makes it more difficult to plot your data. R and Python are generally more concerned with maintaining backward compatibility than Excel, but make sure you can adapt to these software changes.

Recall that since each row is the result of a single run, each point represents the final state of the model for one run. If there is little stochasticity in your model, you may notice replicate runs clustering together.

327

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Figure 9.2. Scatter plot made in Excel looking at the effect of “weighted-trade-choice” on agent population size. Each run is shown as a single point. y-axis range has been adjusted to better show the data pattern.

the DATA menu to SORT BY the metals? column. Next, select just the values of count turtles that have metals? = false . In the INSERT menu, choose CLUSTERED COLUMN BAR CHART. On Mac this is CLUSTERED COLUMN in the 2D COLUMN chart category. In the CHART DESIGN menu, click SELECT DATA, and add a second data series using the ADD (+ on Mac) button. Click the icon beside SERIES VALUES (Y VALUES next to the box with SERIES on Mac), and drag to highlight the count turtles values associated with metals? = true . Click OK and you should see your bar chart. If you like, go back into SELECT DATA and edit the HORIZONTAL AXIS LABELS by selecting the weighted-trade-choice values. Your paired bar chart has one color for true and another for false, so that you can evaluate if metals? had any effect on the resulting population size (fig. 9.3). Although metals? = false seems to result in a larger final population size for the higher weighted-trade-choice runs, the effect is quite small—more runs and more interrogation of that effect would be needed before we can decide if it is significant.

328

Chapter 9: Data Analysis

Figure 9.3. Excel’s paired bar chart. Each pair of runs is shown as two bars with color indicating whether “metals?” is set to true or false. Replicate runs are each included as a separate bar. Note the adjusted y-axis range to highlight the difference in bar heights.

Last, we will take a look at the wine storage curves that were such a central subject of Crabtree (2016). Open any one of the CSV files that were exported from the wine plots. Again, there is a header section that contains the model name, settings, and the plot and pen settings. Below are the x and y values for each pen that the plot used to record data. Repeat the procedure from above to create a SCATTER (X, Y) plot of the Etruscan wine, this time as a line-style plot, and then add the Greek wine as the second series. All this has done is replicate the plot that NetLogo created during the run but in a format that is a little easier to manipulate for publication. R & PYTHON

Of this book’s authors, two use R and one uses Python for their data analysis. More and more archaeologists are adopting one of these programming languages, particularly as more workshops are held at major archaeology conferences, introductory articles are written, and the openscience movement gains steam and encourages open-source approaches (Marwick et al. 2017). The scripted approach to data analysis using R or Python allows for improved transparency and replicability of published

open science: a philosophy of research transparency in science. Advocates for open-access publishing, open-data sharing, and transparent methods. open source/open code: a pillar of the open-science movement that encourages the publication of all scientific code, including analysis scripts.

329

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

research. This is contrasted with point-and-click software like Excel or IBM’s SPSS, which may perform similar analyses or produce similar figures, but the methods are not easily replicable or transparent. It is also difficult to imagine Excel operating efficiently over multiple files generated by the simulation or creating tens or even hundreds of graphs necessary to fully assess the results. A simple rule of thumb is that if you estimate that the data analysis will take you a week of copy-pasting and figure-making in Excel, you’ll be better off spending that time learning how to conduct your data analysis in R or Python. Here we will show you a simple pipeline for the analysis of NetLogo output with R and Python commands so that you can choose your preferred language. To replicate the analysis we just performed in Excel, first we need to install R or Python. If using R, download and launch RStudio.2 If you prefer Python, or want to try, both download the Anaconda Distribution,3 launch Anaconda Navigator from your START menu, and choose either RSTUDIO for R or SPYDER for Python (you can also use JUPYTER NOTEBOOK for both). Here we will just give the code to perform our analyses, but there are numerous textbooks to help you deepen your skills, some of which we list in the Further Reading section at the end of the chapter. Make sure your data file (“AmphorABM experiment-table.csv”) is saved in the same folder as the script. For the code blocks below, first we show the R code, then the Python code for the same analysis steps.

ABMA Code Repo:

ch9_Python.ipynb ch9_R.R

Jupyter Noteboook is a simple yet powerful tool that enables you to blend code with description and figures. It takes mere minutes to get to know it.

. R CODE BLOCK 9.6

# If you do not have the packages listed, uncomment # the next line and run it once # install.packages("ggplot2","dplyr","readr") library(readr) library(ggplot2) library(dplyr) simdata TURTLE SHAPES EDITOR. U S I N G S H A P E S F O R STAT E S O R T E R R A I N

Shapes may better communicate a terrain type than patch color alone: for example, a triangle may better represent a mountain than trying to pick the “right” mountain color, as in figure A.7. Shapes may also help denote landscape states better than color alone, particularly when the landscape has events such as snow, rain, seeds germinating, or plants fruiting. See figure A.7.

Kornhauser, Wilensky, and Rand (2009) discuss visual design principles and considerations in great depth.

392

WHEN USING SHAPES, USER EXPERIENCE IS STILL KING

How many shapes are too many? Again, it depends entirely on the model. A good general approach is to modify one feature at a time, run the model, and ask yourself whether the visualization feels busy. Sometimes taking a little time off from the model before revisiting it can help you see it afresh. If you're still not sure, show it to someone for feedback.

Appendix

Figure A.7. Shapes can tell part of the story when the paired colors provide sufficient contrast. Top: Seeds, as circles, sprout into plants. Middle: Lines in the clouds represent rain, and water running down to plants are dots on the mountains. Bottom: Plants with mature ears of maize have yellow dots with high contrast.

As Accessibility Evolves, So Does Our Thinking Keep in mind that although it would be nice to “do it right the first time,” that is an unrealistic expectation for any modeler. Developing a clear, concise, and accessible model is an iterative process. Making models colorblind-friendly involves trade-offs in meaningful color-based communication, but we have found that understanding these trade-offs and working within these constraints has improved the depth of our understanding of the use of color, and our approach to modeling overall. We hope you will find the same benefits!

393

BIBLIOGRAPHY Acerbi, A., A. Mesoudi, and M. Smolla. 2020. Individual-Based Models of Cultural Evolution: A Step-by-Step Guide using R, December. doi:10.31219/osf.io/32v6a. Ackland, G. J., M. Signitzer, K. Stratford, and M. H. Cohen. 2007. “Cultural Hitchhiking on the Wave of Advance of Beneficia Technologies.” Proceedings of the National Academy of Sciences 104, no. 21 (May): 8714–8719. doi:10.1073/pnas.0702469104. Ahrweiler, P., and N. Gilbert. 2005. “Caff Nero: the Evaluation of Social Simulation.” Journal of Artificial Societies and Social Simulation 8, no. 4 (October). https://jasss.soc.surrey.ac. uk/8/4/14.html. Ammerman, A. J., and L. L. Cavalli-Sforza. 1973. “A Population Model for the Diffusio of Early Farming in Europe.” In The Explanation of Culture Change: Models in Prehistory, edited by C. Renfrew, 343–358. London, UK: Duckworth. Andel, T. H. van, and W. Davies. 2003. Neanderthals and Modern Humans in the European Landscape during the Last Glaciation: Archaeological Results of the Stage 3 Project. Cambridge, UK: McDonald Institute for Archaeological Research. Angourakis, A., M. Salpeteur, V. Martínez Ferreras, and J. M. Gurt Esparraguera. 2017. “The Nice Musical Chairs Model: Exploring the Role of Competition and Cooperation Between Farming and Herding in the Formation of Land Use Patterns in Arid Afro-Eurasia.” Journal of Archaeological Method and Theory 24, no. 4 (December): 1177–1202. doi:10 . 1007/s10816-016-9309-8. Anthony, D. W. 1990. “Migration in Archeology: The Baby and the Bathwater.” American Anthropologist 92 (4): 895–914. doi:10.1525/aa.1990.92.4.02a00030. Arifin S. M. N., and G. R. Madey. 2015. “Verification Validation, and Replication Methods for Agent-Based Modeling and Simulation: Lessons Learned the Hard Way!” In Concepts and Methodologies for Modeling and Simulation, edited by L. Yilmaz, 217–242. Simulation Foundations, Methods and Applications. Springer International Publishing. doi:10. 1007/978-3-319-15096-3_10. Axelrod, R. 1980. “More Effectiv Choice in the Prisoner’s Dilemma.” Journal of Conflict Resolution 24, no. 3 (September): 379–403. doi:10.1177/002200278002400301. Axelrod, R. M. 1997. The Complexity of Cooperation: Agent-Based Models of Competition and Collaboration. Princeton, NJ: Princeton University Press. Axtell, R. L., J. M. Epstein, J. S. Dean, G. J. Gumerman, A. C. Swedlund, J. Harburger, S. Chakravarty, R. Hammond, J. Parker, and M. Parker. 2002. “Population Growth and Collapse in a Multiagent Model of the Kayenta Anasazi in Long House Valley.” Proceedings of the National Academy of Sciences 99 (suppl 3): 7275–7279. doi:10.1073/pnas.092080799. Baker, J. 2017. NetLogo Bidding Market Model. Evanston, IL. https : / / ccl . northwestern . edu / netlogo/models/BiddingMarket.

395

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Banks, W. E., F. d’Errico, A. T. Peterson, M. Vanhaeren, M. Kageyama, P. Sepulchre, G. Ramstein, A. Jost, and D. Lunt. 2008. “Human Ecological Niches and Ranges during the LGM in Europe Derived from an Application of Eco-Cultural Niche Modeling.” Journal of Archaeological Science 35 (2): 481–491. doi:10.1016/j.jas.2007.05.011. Barabási, A. L. 2016. Network Science. Cambridge, UK: Cambridge University Press. Barceló, J. A., F. Del Castillo, R. Del Olmo, L. Mameli, F. J. M. Quesada, D. Poza, and X. Vilà. 2015. “Simulating Patagonian Territoriality in Prehistory: Space, Frontiers and Networks Among Hunter-Gatherers.” In Agent-Based Modeling and Simulation in Archaeology, edited by G. Wurzer, K. Kowarik, and H. Reschreiter, 217–256. Cham, Switzerland: Springer International Publishing. doi:10.1007/978-3-319-00008-4_10. Barton, C. M. 2013. Patch-Choice Model from Optimal Foraging Theory (Human Behavioral Ecology). https://www.comses.net/codebases/2224/releases/1.0.0/. . 2014. “Complexity, Social Complexity, and Modeling.” Journal of Archaeological Method and Theory 21, no. 2 (June): 306–324. doi:10.1007/s10816-013-9187-2. . 2015. Diet-Breadth Model from Optimal Foraging Theory (Human Behavioral Ecology). https://www.comses.net/codebases/2225/releases/1.1.0/. Barton, C. M., J. Riel-Salvatore, J. M. Anderies, and G. Popescu. 2011. “Modeling Human Ecodynamics and Biocultural Interactions in the Late Pleistocene of Western Eurasia.” Human Ecology 39, no. 6 (December): 705–725. doi:10.1007/s10745-011-9433-8. Barton, C. M., I. I. Ullah, and S. Bergin. 2010. “Land Use, Water, and Mediterranean Landscapes: Modelling Long-Term Dynamics of Complex Socio-Ecological systems.” Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences 368, no. 1931 (November): 5275–5297. doi:10.1098/rsta.2010.0193. Barton, L., and I. I. T. Ullah. 2016. “Computer Simulation and the Origins of Agriculture in East Asia.” Presented at the Seventh Worldwide Conference of the SEAA June 8–12, 2016, Cambridge/Boston, MA, USA. Boston, MA. Batty, M. 2005. Cities and Complexity: Understanding Cities with Cellular Automata, AgentBased Models, and Fractals. OCLC: ocm56387135. Cambridge, MA: MIT Press. Baum, T., M. Mainberger, T. Taylor, W. Tinner, A. Hafner, and R. Ebersbach. 2020. “How Many, How Far? Quantitative Models of Neolithic Land Use for Six Wetland Sites on the Northern Alpine Forelands between 4300 and 3700 BC.” Vegetation History and Archaeobotany 29, no. 6 (November): 621–639. doi:10.1007/s00334-019-00768-9. Becker, J. J., D. T. Sandwell, W. H. F. Smith, J. Braud, B. Binder, J. L. Depner, D. Fabre, J. Factor, S. Ingalls, and S. H. Kim. 2009. “Global Bathymetry and Elevation Data at 30 Arc Seconds Resolution: SRTM30_PLUS.” Marine Geodesy 32 (4): 355–371. doi:10.1080/0149041090329 7766. Bentley, R. A., M. W. Hahn, and S. J. Shennan. 2004. “Random Drift and Culture Change.” Proceedings of the Royal Society of London. Series B: Biological Sciences 271, no. 1547 (July): 1443–1450. doi:10.1098/rspb.2004.2746. Bergin, S. 2019. The Cardial Spread Model. CoMSES Computational Model Library. https : / / www.comses.net/codebases/5278/releases/1.1.0/.

Bibliography Bergin, S. M. 2016. “Mechanisms and Models of Agropastoral Spread During the Neolithic in the West Mediterranean: The Cardial Spread Model.” PhD, Arizona State University. https: //search.proquest.com/docview/1845308964/abstract/D9BE13322D14FB5PQ/1. Bernabeu Aubán, J., C. M. Barton, S. Pardo Gordó, and S. M. Bergin. 2015. “Modeling Initial Neolithic Dispersal. The First Agricultural Groups in West Mediterranean.” Ecological Modelling 307 (July): 22–31. doi:10.1016/j.ecolmodel.2015.03.015. Bettinger, R. L., and D. A. Young. 2004. “Hunter-Gatherer Population Expansion in North Asia and the New World.” In Entering America: Northeast Asia and Beringia Before the Last Glacial Maximum, edited by D. B. Madsen. Salt Lake City, UT: University of Utah Press, September. Beyer, R. M., M. Krapp, and A. Manica. 2020. “High-Resolution Terrestrial Climate, Bioclimate, and Vegetation for the Last 120,000 Years.” Scientific Data 7, no. 1 (July): 236. doi:10.1038/ s41597-020-0552-1. Binford, L. R. 1962. “Archaeology as Anthropology.” American Antiquity 28, no. 2 (October): 217–225. doi:10.2307/278380. . 1979. “Organization and Formation Processes: Looking at Curated Technologies.” Journal of Anthropological Research 35 (3): 255–273. doi:10.1086/jar.35.3.3629902. Binford, L. R., and J. A. Sabloff 1982. “Paradigms, Systematics, and Archaeology.” Journal of Anthropological Research 38 (2): 137–153. doi:10.1086/jar.38.2.3629594. Bird, R. B., and D. W. Bird. 2008. “Why Women Hunt: Risk and Contemporary Foraging in a Western Desert Aboriginal Community.” Current Anthropology 49 (4): 655–693. doi:10. 1086/587700. Bird, R. B., and D. Nimmo. 2018. “Restore the Lost Ecological Functions of People.” Nature Ecology & Evolution 2, no. 7 (July): 1050. doi:10.1038/s41559-018-0576-5. Bivand, R. S., E. Pebesma, and V. Gomez-Rubio. 2013. Applied Spatial Data Analysis with R. Second edition. Springer, NY. https://www.asdar-book.org/. Bocinsky, R. K. 2011. “Is a Bird in Hand Really Worth Two in the Bush?: Models of Turkey Domestication on the Colorado Plateau.” PHD Thesis, Washington State University. Bocinsky, R. K., and T. A. Kohler. 2014. “A 2,000-Year Reconstruction of the Rain-Fed Maize Agricultural Niche in the US Southwest.” Nature Communications 5, no. 1 (December): 5618. doi:10.1038/ncomms6618. Bonanno, G. 2018. Game Theory. Scotts Valley, CA: CreateSpace Independent Publishing Platform. Bonnell, T. R., R. R. Sengupta, C. A. Chapman, and T. L. Goldberg. 2010. “An Agent-Based model of Red Colobus Resources and Disease Dynamics Implicates Key Resource Sites as Hot Spots of Disease Transmission.” Ecological Modelling 221, no. 20 (October): 2491– 2500. doi:10.1016/j.ecolmodel.2010.07.020. Bookstein, A., V. A. Kulyukin, and T. Raita. 2002. “Generalized Hamming Distance.” Information Retrieval 5 (4): 353–375. doi:10.1023/A:1020499411651.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Borck, L., B. J. Mills, M. A. Peeples, and J. J. Clark. 2015. “Are Social Networks Survival Networks? An Example from the Late Pre-Hispanic US Southwest.” Journal of Archaeological Method and Theory 22 (1): 33–57. doi:10.1007/s10816-014-9236-5. Box, G. E. P. 1979. “Robustness in the Strategy of Scientifi Model Building.” In Robustness in Statistics, edited by R. L. Launer and G. N. Wilkinson, 201–236. Academic Press, January. doi:10.1016/B978-0-12-438150-6.50018-2. Braconnot, P., S. P. Harrison, M. Kageyama, P. J. Bartlein, V. Masson-Delmotte, A. Abe-Ouchi, B. Otto-Bliesner, and Y. Zhao. 2012. “Evaluation of Climate Models Using Palaeoclimatic Data.” Nature Climate Change 2, no. 6 (June): 417–424. doi:10.1038/nclimate1456. Brandes, U., G. Robins, A. McCranie, and S. Wasserman. 2013. “What is Network Science?” Network Science, no. 1 (April): 1–15. doi:10.1017/nws.2013.2. Brantingham, P. J. 2003. “A Neutral Model of Stone Raw Material Procurement.” American Antiquity 68 (3): 487–510. doi:10.2307/3557105. Briggs, D. N. 2003. “Metals, Salt, and Slaves: Economic Links between Gaul and Italy from the Eighth to the Late Sixth Centuries BC.” Oxford Journal of Archaeology 22 (3): 243–259. doi:10.1111/1468-0092.00186. Brughmans, T. 2010. “Connecting the Dots: Towards Archaeological Network Analysis.” Oxford Journal of Archaeology 29, no. 3 (July): 277–303. doi:10.1111/j.1468-0092.2010.00349.x. . 2013. “Networks of Networks: A Citation Network Analysis of the Adoption, Use, and Adaptation of Formal Network Techniques in Archaeology.” Literary and Linguistic Computing 28, no. 4 (December): 538–562. doi:10.1093/llc/fqt048. . 2015. MERCURY: An ABM of Tableware Trade in the Roman East” (Version 1.1.0). https://www.comses.net/codebases/4347/releases/1.1.0/. . 2016. Network Science with Netlogo Tutorial. https : / / archaeologicalnetworks . files . wordpress.com/2013/11/netlogo_networks_tutorial_07-2017.pdf. Brughmans, T., A. Collar, and F. Coward. 2016. The Connected Past: Challenges to Network Studies in Archaeology and History. Oxford, UK: Oxford University Press. Brughmans, T., and M. Peeples. 2017. “Trends in Archaeological Network Research.” Journal of Historical Network Research 1 (1): 1–24. https://jhnr.uni.lu/index.php/jhnr/article/view/10. Brughmans, T., and J. Poblome. 2016. “Roman Bazaar or Market Economy? Explaining Tableware Distributions in the Roman East through Computational Modelling.” Antiquity 90 (350): 393–408. doi:10.15184/aqy.2016.35. Bullock, S. 2014. “Levins and the Lure of Artificia Worlds.” The Monist 97 (3): 301–320. doi:10. 5840/monist201497320. Campolongo, F., J. Cariboni, and A. Saltelli. 2007. “An Effectiv Screening Design for Sensitivity Analysis of Large Models.” Environmental Modelling & Software, Modelling, computer-assisted simulations, and mapping of dangerous phenomena for hazard assessment, 22, no. 10 (October): 1509–1518. doi:10.1016/j.envsoft.2006.10.004. Carlson, D. L. 2017. Quantitative Methods in Archaeology Using R. Cambridge, UK: Cambridge University Press. doi:10.1017/9781139628730.

Bibliography Carrignon, S., T. Brughmans, and I. Romanowska. 2020. “Tableware Trade in the Roman East: Exploring Cultural and Economic Transmission with Agent-Based Modelling and Approximate Bayesian Computation.” PLOS ONE 15, no. 11 (November): e0240414. doi:10. 1371/journal.pone.0240414. Cegielski, W. H., and J. D. Rogers. 2016. “Rethinking the Role of Agent-Based Modeling in Archaeology.” Journal of Anthropological Archaeology 41 (March): 283–298. doi:10.1016/j. jaa.2016.01.009. Charnov, E. L. 1976. “Optimal Foraging, the Marginal Value Theorem.” Theoretical Population Biology 9, no. 2 (April): 129–136. doi:10.1016/0040-5809(76)90040-X. Chattoe-Brown, E. 2013. “Why Sociology Should Use Agent-Based Modelling.” Sociological Research Online 18 (3): 3. doi:10.5153/sro.3055. Chliaoutakis, A., and G. Chalkiadakis. 2020. “An Agent-Based Model for Simulating InterSettlement Trade in Past Societies.” Journal of Artificial Societies and Social Simulation 23 (3): 10. doi:10.18564/jasss.4341. Clark, J. K., and S. A. Crabtree. 2015. “Examining Social Adaptations in a Volatile Landscape in Northern Mongolia via the Agent-Based Model Ger Grouper.” Land 4, no. 1 (March): 157–181. doi:10.3390/land4010157. Cockburn, D., S. A. Crabtree, Z. Kobti, T. A. Kohler, and R. K. Bocinsky. 2013. “Simulating Social and Economic Specialization in Small-Scale Agricultural Societies.” Journal of Artificial Societies and Social Simulation 16 (4): 4. doi:10.18564/jasss.2308. Codling, E. A., M. J. Plank, and S. Benhamou. 2008. “Random Walk Models in Biology.” Journal of The Royal Society Interface 5, no. 25 (August): 813–834. doi:10.1098/rsif.2008.0014. Conolly, J., and M. W. Lake. 2006. Geographical Information Systems in Archaeology. Cambridge, UK: Cambridge University Press. doi:10.1017/CBO9780511807459. Costopoulos, A. 2001. “Evaluating the Impact of Increasing Memory on Agent Behaviour: Adaptive Patterns in an Agent-Based Simulation of Subsistence.” Journal of Artificial Societies and Social Simulation 4, no. 4 (October). https://jasss.soc.surrey.ac.uk/4/4/7.html. . 2018. Thoughts on Archaeology and Complexity, March. https://archeothoughts.wordp ress.com/2018/03/20/thoughts-on-archaeology-and-complexity/. Crabtree, S. A. 2015. “Inferring Ancestral Pueblo Social Networks from Simulation in the Central Mesa Verde.” Journal of Archaeological Method and Theory 22, no. 1 (March): 144–181. doi:10.1007/s10816-014-9233-8. . 2016. “Simulating Littoral Trade: Modeling the Trade of Wine in the Bronze to Iron Age Transition in Southern France.” Land 5, no. 1 (February): 5. doi:10.3390/land5010005. Crabtree, S. A., D. W. Bird, and R. B. Bird. 2019. “Subsistence Transitions and the Simplificatio of Ecological Networks in the Western Desert of Australia.” Human Ecology (February). doi:10.1007/s10745-019-0053-z. Crabtree, S. A., R. K. Bocinsky, P. L. Hooper, S. C. Ryan, and T. A. Kohler. 2017. “How to Make a Polity (in the Central Mesa Verde Region).” American Antiquity 82, no. 1 (January): 71–95. doi:10.1017/aaq.2016.18.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Crabtree, S. A., K. Harris, B. Davies, and I. Romanowska. 2019. “Outreach in Archaeology with Agent-Based Modeling: Part 3 of 3.” Advances in Archaeological Practice 7, no. 2 (May): 194–202. doi:10.1017/aap.2019.4. Crabtree, S. A., L. J. S. Vaughn, and N. T. Crabtree. 2017. “Reconstructing Ancestral Pueblo food webs in the southwestern United States.” Journal of Archaeological Science 81 (May): 116– 127. doi:10.1016/j.jas.2017.03.005. Crawford, K. A. 2019a. “Rethinking Approaches for the Study of Urban Movement at Ostia.” In Finding the Limits of the Limes: Modelling Demography, Economy and Transport on the Edge of the Roman Empire, edited by P. Verhagen, J. Joyce, and M. R. Groenhuijzen, 313–327. Cham, Switzerland: Springer International Publishing. doi:10.1007/978-3-03004576-0_15. . 2019b. “Visualising Ostia’s Processional Landscape Through a Multi-Layered Computational Approach: Case Study of the Cult of the Magna Mater.” Open Archaeology 5, no. 1 (December): 444–467. doi:10.1515/opar-2019-0028. Crema, E. R. 2013. “Cycles of Change in Jomon Settlement: A Case Study from Eastern Tokyo Bay.” Antiquity 87, no. 338 (December): 1169–1181. doi:10.1017/S0003598X00049930. . 2014. “A Simulation Model of Fission-Fusion Dynamics and Long-Term Settlement Change.” Journal of Archaeological Method and Theory 21 (2): 385–404. doi:10 . 1007 / s 10816-013-9185-4. Crema, E. R., A. Kandler, and S. Shennan. 2016. “Revealing Patterns of cultural transmission from frequency data: equilibrium and non-equilibrium assumptions.” Scientific Reports 6, no. 1 (December): 39122. doi:10.1038/srep39122. Crema, E. R., and M. W. Lake. 2015. “Cultural Incubators and Spread of Innovation.” Human Biology 87:151–168. doi:10.13110/humanbiology.87.3.0151. Crooks, A. T., N. Malleson, Ed Manley, and A. J. Heppenstall. 2019. Agent-Based Modelling and Geographical Information Systems. London, UK: Sage Publishing. https://www.abmgis. org. Crooks, A., A. Croitoru, X. Lu, S. Wise, J. M. Irvine, and A. Stefanidis. 2015. “Walk This Way: Improving Pedestrian Agent-Based Models through Scene Activity Analysis.” ISPRS International Journal of Geo-Information 4, no. 3 (September): 1627–1656. doi:10.3390/ijgi 4031627. Crooks, A., A. Heppenstall, and N. Malleson. 2018. “Agent-Based Modeling.” In Comprehensive Geographic Information Systems, edited by T. J. Cova and M.-H. Tsou, 218–243. Amsterdam, Netherlands: Elsevier. doi:10.1016/B978-0-12-409548-9.09704-9. David, B., and J. Thomas. 2016. Handbook of Landscape Archaeology. Abingdon, UK: Routledge, June. Davies, B., S. J. Holdaway, and P. C. Fanning. 2018. “Modeling Relationships between Space, Movement, and Lithic Geometric Attributes.” American Antiquity 83, no. 3 (July): 444– 461. doi:10.1017/aaq.2018.23.

Bibliography Davies, B., and I. Romanowska. 2018. “An Emergent Community?: Agent-Based Modellers in Archaeology.” SAA Archaeological Record 18 (2): 27–32. https://onlinedigeditions.com/ publication/?i=486133&article_id=3048153&view=articleBrowser&ver=html5. Davies, B., I. Romanowska, K. Harris, and S. A. Crabtree. 2019. “Combining Geographic Information Systems and Agent-Based Models in Archaeology: Part 2 of 3.” Advances in Archaeological Practice 7, no. 2 (May): 185–193. doi:10.1017/aap.2019.5. Dean, J. S., G. J. Gumerman, J. M. Epstein, R. L. Axtell, A. C. Swedlund, M. T. Parker, and S. McCarroll. 2000. “Understanding Anasazi Culture Change through Agent-Based Modeling.” In Dynamics in Human and Primate Societies: Agent-Based Modeling of Social and Spatial Processes, edited by T. A. Kohler and G. J. Gumerman, 179–205. Oxford, UK: Oxford University Press, July. Doran, J. 1970. “Systems Theory, Computer Simulations, and Archaeology.” World Archaeology 1 (3): 289–298. Downey, A. 2016. Think Python. 2nd edition, updated for Python 3. Sebastopol, CA: O’Reilly Media. . 2018. Think Complexity: Complexity Science and Computational Modeling. Second edition. Beijing, China: O’Reilly. Dunnell, R. C. 1982. “The Harvey Lecture Series. Science, Social Science, and Common Sense: The Agonizing Dilemma of Modern Archaeology.” Journal of Anthropological Research 38, no. 1 (April): 1–25. doi:10.1086/jar.38.1.3629946. Edmonds, B., and D. Hales. 2003. “Replication, Replication, and Replication: Some Hard Lessons from Model Alignment.” Journal of Artifical Societies and Social Simulation 6, no. 4 (October). https://jasss.soc.surrey.ac.uk/6/4/11.html. Eerkens, J. W., and C. P. Lipo. 2007. “Cultural Transmission Theory and the Archaeological Record: Providing Context to Understanding Variation and Temporal Changes in Material Culture.” Journal of Archaeological Research 15 (3): 239–274. doi:10.1007/s10814-0079013-z. Eglen, S. J., B. Marwick, Y. O. Halchenko, M. Hanke, S. Sufi P. Gleeson, R. A. Silver, et al. 2017. “Toward Standard Practices for Sharing Computer Code and Programs in Neuroscience.” Nature Neuroscience 20, no. 6 (June): 770–773. doi:10.1038/nn.4550. Epstein, J. M. 2009. “Modelling to Contain Pandemics.” Nature 460 (August): 687. doi:10.1038/ 460687a. Epstein, J. M., and R. Axtell. 1996. Growing Artificial Societies: Social Science from the Bottom Up. Complex Adaptive Systems. Washington, DC: Brookings Institution Press. Epstein, J. M., J. Parker, D. Cummings, and R. A. Hammond. 2008. “Coupled Contagion Dynamics of Fear and Disease: Mathematical and Computational Explorations.” PLOS ONE 3, no. 12 (December): e3955. doi:10.1371/journal.pone.0003955. Epstein, Joshua M. 1999. “Agent-Based Computational Models And Generative Social Science.” Complexity 4 (5): 41–60. https://doi.org/10.1002/(SICI)1099-0526(199905/06)4:5%3C41:: AID-CPLX9%3E3.0.CO;2-F.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Erdős, P, and A Rényi. 1960. “On the Evolution of Random Graphs.” Publication of the Institute of Mathematics, Hungarian Academy of Sciences 5:17–61. Evans, T. 2016. “Which Network Model Should I Use? Towards a Quantitative Comparison of Spatial Network Models in Archaeology.” In The Connected Past: Challenges to Network Studies in Archaeology and History, edited by T. Brughmans, A. Collar, and F. Coward, 149–173. Oxford, UK: Oxford University Press. Fábrega-Álvarez, P. 2006. “Moving without Destination: A Theoretical, GIS-Based Determination of Routes (Optimal Accumulation Model of Movement from a Given Origin).” Archaeological Computing Newsletter 64:7–11. https://digital.csic.es/bitstream/10261/15993/ 1/2006_Archaeological%5C%20Computing_Pastor_Gis.PDF. Farmer, J. D., and D. Foley. 2009. “The Economy Needs Agent-Based Modelling.” Nature 460 (Aug): 685–686. doi:10.1038/460685a. Fort, J. 2015. “Demic and Cultural Diffusio Propagated the Neolithic Transition across Differ ent Regions of Europe.” Journal of The Royal Society Interface 12, no. 106 (May): 20150166. doi:10.1098/rsif.2015.0166. . 2018. “The Neolithic Transition: Diffusio of People or Diffusio of Culture?” In Diffusive Spreading in Nature, Technology and Society, 313–331. Cham, Switzerland: Springer. doi:10.1007/978-3-319-67798-9_16. Fort, J., N. Isern, A. Jerardino, and B. Rondelli. 2016. “Population Spread and Cultural Transmission in Neolithic Transitions.” In Simulating Prehistoric and Ancient Worlds, edited by J. A. Barceló and F. D. Castillo, 189–197. Computational Social Sciences. Cham, Switzerland: Springer International Publishing. doi:10.1007/978-3-319-31481-5_5. Fort, J., T. Pujol, and M. V. Linden. 2012. “Modelling the Neolithic Transition in the Near East and Europe.” American Antiquity 77 (2): 203–219. doi:10.7183/0002-7316.77.2.203. Froese, T., C. Gershenson, and L. R. Manzanilla. 2014. “Can Government Be Self-Organized? A Mathematical Model of the Collective Social Organization of Ancient Teotihuacan, Central Mexico.” PLOS ONE 9 (1): e109966–e109966. doi:10.1371/journal.pone.0109966. Gamble, C. 2013. Settling the Earth: The Archaeology of Deep Human History. Cambridge, UK: Cambridge University Press. Gauthier, N. 2019a. Multilevel Simulation of Demography and Food Production in Ancient Agrarian Societies: A Case Study from Roman North Africa. Preprint. SocArXiv, August. doi:10. 31235/osf.io/5be6a. . 2019b. Trade, Migration, and the Dynamics of Spatial Interaction. Preprint. SocArXiv, September. doi:10.31235/osf.io/trbf8. Geertz, C. 1978. “The Bazaar Economy: Information and Search in Peasant Marketing.” The American Economic Review 68 (2): 28–32. https://www.jstor.org/stable/1816656. Gilbert, N. G., and K. G. Troitzsch. 2005. Simulation for the Social Scientist. Maidenhead, UK: Open University Press. Gillings, M., P. Hacigüzeller, and G. R. Lock, eds. 2020. Archaeological Spatial Analysis: A Methodological Guide. New York, NY: Routledge.

Bibliography Gould, S. J. 1990. Wonderful Life: The Burgess Shale and the Nature of History. New York, NY: W. W. Norton & Company, September. Graham, S. 2005. “Agent-Based Modelling, Archaeology, and Social Organisation: The Robustness of Rome.” The Archaeological Computing Newsletter 63:1–6. . 2006. “Networks, Agent-Based Models and the Antonine Itineraries: Implications for Roman Archaeology.” Journal of Mediterranean Archaeology 19 (1): 45. doi:10.1558/jmea. 2006.19.1.45. . 2009. “Behaviour Space: Simulating Roman Social Life and Civil Violence.” Digital Studies/Le champ numérique 1, no. 2 (June). doi:10.16995/dscn.109. . 2018. O-Date/Abm3: August2018-For-Zenodo, August. doi:10.5281/ZENODO.1405081. . 2019. Failing Gloriously and Other Essays. The Digital Press at the University of North Dakota. Graham, S., and S. Weingart. 2015. “The Equifinalit of Archaeological Networks: An AgentBased Exploratory Lab Approach.” Journal of Archaeological Method and Theory 22, no. 1 (December): 248–274. doi:10.1007/s10816-014-9230-y. GRASS Development Team. 2018. Geographic Resources Analysis Support System (GRASS GIS) Software. USA: Open Source Geospatial Foundation. https://grass.osgeo.org. Gravel-Miguel, C., J. K. Murray, B. J. Schoville, C. D. Wren, and C. W. Marean. 2021. “Exploring Variability in Lithic Armature Discard in the Archaeological Record.” Journal of Human Evolution 155 (June): 102981. doi:10.1016/j.jhevol.2021.102981. Gravel-Miguel, C., and C. D. Wren. 2018. “Agent-Based Least-Cost Path Analysis and the Diffusion of Cantabrian Lower Magdalenian Engraved Scapulae.” Journal of Archaeological Science 99 (November): 1–9. doi:10.1016/j.jas.2018.08.014. Grimm, V. 1999. “Ten Years of Individual-Based Modelling in Ecology: What Have We Learned and What Could We Learn in the Future?” Ecological Modelling 115, nos. 2-3 (February): 129–148. doi:10.1016/S0304-3800(98)00188-4. Grimm, V., U. Berger, D. L. DeAngelis, J. G. Polhill, J. Giske, and S. F. Railsback. 2010. “The ODD Protocol: A Review and First Update.” Ecological Modelling 221, no. 23 (November): 2760–2768. doi:10.1016/j.ecolmodel.2010.08.019. Grimm, V., S. F. Railsback, C. E. Vincenot, U. Berger, C. Gallagher, D. L. DeAngelis, B. Edmonds, et al. 2020. “The ODD Protocol for Describing Agent-Based and Other Simulation Models: A Second Update to Improve Clarity, Replication, and Structural Realism.” Journal of Artificial Societies and Social Simulation 23 (2): 7. doi:10.18564/jasss.4259. Gurven, M., and H. Kaplan. 2007. “Longevity Among Hunter- Gatherers: A Cross-Cultural Examination.” Population and Development Review 33, no. 2 (June): 321–365. doi:10.1111/j. 1728-4457.2007.00171.x. Gutierrez, D., B. Frischer, E. Cerezo, A. Gomez, and F. Seron. 2007. “AI and Virtual Crowds: Populating the Colosseum.” Journal of Cultural Heritage 8, no. 2 (April): 176–185. doi:10. 1016/j.culher.2007.01.007.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Hamill, L., and N. Gilbert. 2016. Agent-Based Modelling in Economics. Chichester, UK: Wiley. doi:10.1002/9781118945520. Hammond, R. A. 2009. “Complex Systems Modeling for Obesity Research.” Preventing Chronic Disease 6, no. 3 (June). https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2722404/. . 2010. “A Complex Systems Approach to Understanding and Combating the Obesity Epidemic.” In Obesity Prevention: The Role of Brain and Society on Individual Behavior, 767–777. London, UK: Academic Press. doi:10.1016/B978-0-12-374387-9.00061-1. Hammond, R. A., and J. T. Ornstein. 2014. “A Model of Social Influenc on Body Mass Index.” Annals of the New York Academy of Sciences 1331 (1): 34. doi:10.1111/nyas.12344. Hammond, R. A., J. T. Ornstein, R. Purcell, M. D. Haslam, and M. Kasman. 2021. “Modeling Robustness of COVID-19 Containment Policies.” OSFPreprints (May). doi:10.31219/osf.io/ h5ua7. Hammond, R. A., N. Osgood, and M. Wolfson. 2017. “Using Complex Systems Simulation Modeling to Understand Health Inequality.” In Growing Inequality: Bridging Complex Systems, Population Health, and Health Disparities, edited by G.A. Kaplan and S. Galea. Washington, DC: Westphalia Press. Hardin, G. 1968. “The Tragedy of the Commons.” Science 162, no. 3859 (December): 1243–1248. doi:10.1126/science.162.3859.1243. Harrison, S. P., P. J. Bartlein, and I. C. Prentice. 2016. “What Have We Learnt from Palaeoclimate Simulations?” Journal of Quaternary Science 31 (4): 363–385. doi:10.1002/jqs.2842. Hartley, L. P. 1953. The Go-Between. Harmondsworth, UK: Penguin Random House. Hauke, J., I. Lorscheid, and M. Meyer. 2017. “Recent Development of Social Simulation as Reflecte in JASSS Between 2008 and 2014: A Citation and Co-Citation Analysis.” Journal of Artificial Societies and Social Simulation 20 (1): 5. doi:10.18564/jasss.3238. Hawkes, K., J. O’Connell, and N. B. Jones. 2018. “Hunter-Gatherer Studies and Human Evolution: A Very Selective Review.” American Journal of Physical Anthropology 165, no. 4 (April): 777–800. doi:10.1002/ajpa.23403. Haywood, A. M., P. J. Valdes, T. Aze, N. Barlow, A. Burke, A. M. Dolan, A. S. von der Heydt, et al. 2019. “What can Palaeoclimate Modelling Do for You?” Earth Systems and Environment 3, no. 1 (April): 1–18. doi:10.1007/s41748-019-00093-1. Hegmon, M. 1989. “Risk Reduction and Variation in Agricultural Economies: A Computer Simulation of Hopi Agriculture.” Research in Economic Anthropology 11:89–121. Helbing, D., J. Keltsch, and P. Molnar. 1997. “Modelling the Evolution of Human Trail Systems.” Nature 388 (6637): 47–50. doi:10.1038/40353. Henrich, J. 2001. “Cultural Transmission and the Diffusio of Innovations: Adoption Dynamics Indicate That Biased Cultural Transmission Is the Predominate Force in Behavioral Change.” American Anthropologist 103 (4): 992–1013. doi:10.1525/aa.2001.103.4.992. Heppenstall, A. J., A. T. Crooks, L. M. See, and M. Batty, eds. 2012. Agent-Based Models of Geographical Systems. Dordrecht, Netherlands: Springer.

Bibliography Hesse, M. 1978. “Theory and Value in the Social Sciences.” In Action and Interpretation: Studies in the Philosophy of the Social Sciences, edited by C. Hookway and P. Pettit, 1–16. Cambridge, UK: Cambridge University Press. Hijmans, Robert J. 2019. raster: Geographic Data Analysis and Modeling. https://CRAN.Rproject.org/package=raster. Hjorth, A., B. Head, C. Brady, and U. Wilensky. 2020. “LevelSpace: A NetLogo Extension for Multi-Level Agent-Based Modeling.” Journal of Artificial Societies and Social Simulation 23 (1): 4. doi:10.18564/jasss.4130. Hjorth, A., B. Head, and U. Wilensky. 2015. LevelSpace NetLogo extension. Technical report. Evanston, IL: Center for Connected Learning and Computer Based Modeling, Northwestern University. https://ccl.northwestern.edu/rp/levelspace/index.shtml. Holcombe, M., S. Coakley, M. Kiran, University of Sheffiel S. Chin, C. Greenough, D. Worth, et al. 2013. “Large-Scale Modeling of Economic Systems.” Complex Systems 22, no. 2 (June): 175–192. doi:10.25088/ComplexSystems.22.2.175. Holmes, K. M. 2007. “Using Pliocene Palaeoclimatic Data to Postulate Dispersal Pathways of Early Hominins.” Palaeogeography, Palaeoclimatology, Palaeoecology 248, nos. 1-2 (May): 96–108. doi:10.1016/j.palaeo.2006.11.012. Huang, B. 2017. “Agent-Based Modeling.” In Comprehensive Geographic Information Systems, edited by T. J. Cova, M.-H. Tsou, G. Bareth, C. Song, Y. Song, K. Cao, and E. A. Silva. Amsterdam, Netherlands: Elsevier. Hughes, J. K., A. Haywood, S. J. Mithen, B. W. Sellwood, and P. J. Valdes. 2007. “Investigating Early Hominin Dispersal Patterns: Developing a Framework for Climate Data Integration.” Journal of Human Evolution 53 (5): 465–474. doi:10.1016/j.jhevol.2006.12.011. Jackson, M. O. 2008. Social and Economic Networks. Princeton, NJ: Princeton University Press. Janssen, M. A. 2009. “Understanding Artificia Anasazi.” Journal of Artificial Societies and Social Simulation 12 (4): 13. https://jasss.soc.surrey.ac.uk/12/4/13.html. Janssen, M. A., and K. Hill. 2014. “Benefit of Grouping and Cooperative Hunting Among Ache Hunter–Gatherers: Insights from an Agent-Based Foraging Model.” Human Ecology 42, no. 6 (August): 823–835. doi:10.1007/s10745-014-9693-1. . 2016. “An Agent-Based Model of Resource Distribution on Hunter-Gatherer Foraging Strategies: Clumped Habitats Favor Lower Mobility, but Result in Higher Foraging Returns.” In Simulating Prehistoric and Ancient Worlds, edited by J. A. Barceló and F. D. Castillo, 159–174. Computational Social Sciences. Cham, Switzerland: Springer International Publishing. doi:10.1007/978-3-319-31481-5_3. Kandler, A., and K. N. Laland. 2009. “An Investigation of the Relationship between Innovation and Cultural Diversity.” Theoretical Population Biology 76, no. 1 (August): 59–67. doi:10. 1016/j.tpb.2009.04.004. Kanters, H., T. Brughmans, and I. Romanowska. 2021. “Sensitivity Analysis in Archaeological Simulation: An Application to the MERCURY Model.” Journal of Archaeological Science: Reports 38:102974. doi:10.1016/j.jasrep.2021.102974.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Karsdorp, F., M. Kestemont, and A. Riddell. 2021. Humanities Data Analysis: Case Studies with Python. Princeton, NJ: Princeton University Press. Kelly, R. L. 2013. The Lifeways of Hunter-Gatherers: The Foraging Spectrum. 2nd. Cambridge, UK: Cambridge University Press. Kintigh, K. W., and S. E. Ingram. 2018. “Was the Drought Really Responsible? Assessing Statistical Relationships between Climate Extremes and Cultural Transitions.” Journal of Archaeological Science 89 (January): 25–31. doi:10.1016/j.jas.2017.09.006. Knappett, C., T. Evans, and R. Rivers. 2011. “The Theran Eruption and Minoan Palatial Collapse: New Interpretations Gained from Modeling the Maritime Network.” Antiquity 85 (329): 1008–1023. doi:10.1017/S0003598X00068459. Knuth, D. E. 1974. “Computer Programming as an Art.” Communications of the ACM (New York, NY) 17, no. 12 (December): 667–673. doi:10.1145/361604.361612. Kobti, Z. 2012. “Simulating Household Exchange with Cultural Algorithms.” In Emergence and Collapse of Early Villages, edited by T. A. Kohler and M. D. Varien. Berkeley, CA: University of California Press. Kohler, T. A., R. K. Bocinsky, D. Cockburn, S. A. Crabtree, M. D. Varien, K. E. Kolm, S. Smith, S. G. Ortman, and Z. Kobti. 2012. “Modelling Prehispanic Pueblo Societies in their Ecosystems.” Ecological Modelling 241 (August): 30–41. doi:10.1016/j.ecolmodel.2012.01.002. Kohler, T. A., D. Cockburn, P. L. Hooper, R. K. Bocinsky, and Z. Kobti. 2012. “The Coevolution of Group Size and Leadership: An Agent-Based Public Goods Model for Prehispanic Pueblo Societies.” Advances in Complex Systems 15 (1-2). doi:10.1142/S0219525911003256. Kohler, T. A., S. Cole, and S. Ciupe. 2009. “Population and Warfare: A Test of the Turchin Model in Puebloan Societies.” Pattern and Process in Cultural Evolution: 297–295. Kohler, T. A., S. G. Ortman, K. E. Grundtisch, C. M. Fitzpatrick, and S. M. Cole. 2014. “The Better Angels of their Nature: Declining Violence through Time among Prehispanic Farmers of the Pueblo Southwest.” American Antiquity 79 (3): 444–464. Kohler, T. A., and M. D. Varien. 2012. Emergence and Collapse of Early Villages: Models of Central Mesa Verde Archaeology. Vol. 6. Berkeley, CA: University of California Press. Kovacevic, M., S. Shennan, M. Vanhaeren, F. d’Errico, and M. G. Thomas. 2015. “Simulating Geographical Variation in Material Culture: Were Early Modern Humans in Europe Ethnically Structured?” In Learning Strategies and Cultural Evolution during the Palaeolithic, edited by A. Mesoudi and K. Aoki, 103–120. Tokyo, Japan: Springer Japan. doi:10.1007/9784-431-55363-2_8. Kuckelman, K. A. 2010. “The Depopulation of Sand Canyon Pueblo, a Large Ancestral Pueblo Village in Southwestern Colorado.” American Antiquity 75 (3): 497–525. doi:10.7183/00027316.75.3.497. Lake, M. W. 2000. “MAGICAL Computer Simulation of Mesolithic Foraging.” In Dynamics in Human and Primate Societies: Agent-Based Modeling of Social and Spatial Processes, edited by T. A. Kohler and G. J. Gumerman, 107–143. Oxford, UK: Oxford University Press.

Bibliography . 2001. “The Use of Pedestrian Modelling in Archaeology, with an Example from the Study of Cultural Learning.” Environment and Planning B 28 (3): 385–404. https://www. environmentandplanning.com/epb/fulltext/b28/b2726.pdf. . 2010. “The Uncertain Future of Simulating the Past.” In Simulating Change: Archaeology Into the Twenty-first Century, edited by A. Costopoulos and M. W. Lake. Salt Lake City, UT: University of Utah Press. . 2014. “Trends in Archaeological Simulation.” Journal of Archaeological Method and Theory 21, no. 2 (June): 258–287. doi:10.1007/s10816-013-9188-1. Lemmen, C., D. Gronenborn, and K. W. Wirtz. 2011. “A Simulation of the Neolithic Transition in Western Eurasia.” Journal of Archaeological Science 38, no. 12 (December): 3459–3470. doi:10.1016/j.jas.2011.08.008. Lewin, R. 1999. Complexity: Life at the Edge of Chaos. 2nd edition. Chicago, IL: University of Chicago Press. Ligmann-Zielinska, A., P.-O. Siebers, N. Magliocca, D. C. Parker, V. Grimm, J. Du, M. Cenek, et al. 2020. “‘One Size Does Not Fit All’: A Roadmap of Purpose-Driven Mixed-Method Pathways for Sensitivity Analysis of Agent-Based Models.” Journal of Artificial Societies and Social Simulation 23 (1): 6. doi:10.18564/jasss.4201. Llobera, M., P. Fábrega-Álvarez, and C. Parcero-Oubiña. 2011. “Order in Movement: A GIS Approach to Accessibility.” Journal of Archaeological Science 38, no. 4 (April): 843–851. doi:10.1016/j.jas.2010.11.006. Lorig, F., E. Johansson, and P. Davidsson. 2021. “Agent-Based Social Simulation of the COVID19 Pandemic: A Systematic Review.” Journal of Artificial Societies and Social Simulation 24 (3): 5. doi:10.18564/jasss.4601. Lorscheid, I., B.-O. Heine, and M. Meyer. 2012. “Opening the ‘Black Box’ of Simulations: Increased Transparency and Effectiv Communication through the Systematic Design of Experiments.” Computational and Mathematical Organization Theory 18, no. 1 (March): 22–62. doi:10.1007/s10588-011-9097-3. Macal, C. M. 2009. “Agent-Based Modeling and Artificia Life BT - Encyclopedia of Complexity and Systems Science,” edited by R. A Meyers, 112–131. New York, NY: Springer. doi:10.1007/ 978-0-387-30440-3_7. Marin, J.-M., and C. Robert. 2014. Bayesian Essentials with R. 2nd ed. Springer Texts in Statistics. New York, NY: Springer-Verlag. https://www.springer.com/us/book/9781461486862. Marwick, B. 2017. “Computational Reproducibility in Archaeological Research: Basic Principles and a Case Study of Their Implementation.” Journal of Archaeological Method and Theory 24:424–450. doi:10.1007/s10816-015-9272-9. Marwick, B., J. d’A. Guedes, C. M. Barton, L. A. Bates, M. Baxter, A. Bevan, E. A. Bollwerk, et al. 2017. “Open Science in Archaeology.” SAA Archaeological Record 17 (4): 10–14. https: //osf.io/3d6xx/. McAllister, P. A. 2006. Beer-Drinking Rituals: Power, Practice and Performance in the South African Rural Periphery. Durham, NC: Carolina Academic Press.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

McKinney, W. 2017. Python for Data Analysis. 2nd edition. Sebastapol, CA: O’Reilly Media, Inc. https://proquest.safaribooksonline.com/9781491957653. Mesoudi, A. 2011. Cultural Evolution: How Darwinian Theory Can Explain Human Culture and Synthesize the Social Sciences. Chicago, IL: University of Chicago Press. Miller, J. H., and S. E. Page. 2009. Complex Adaptive Systems: An Introduction to Computational Models of Social Life. Princeton, NJ: Princeton University Press. Mithen, S. J. 1987. “Simulation as a Methodological Tool: Inferring Hunting Goals from Faunal Assemblages.” In CAA87. Computer and Quantitative Methods in Archaeology 1987 (BAR International Series 393), edited by C.L.N Ruggles and S.P.Q. Rahtz, 119–137. Oxford, UK: B.A.R. . 1990. Thoughtful Foragers: A Study of Prehistoric Decision Making. Cambridge, UK: Cambridge University Press. doi:10.1017/CBO9780511752964. Mithen, S. J., and M. Reed. 2002. “Stepping Out: A Computer Simulation of Hominid Dispersal from Africa.” Journal of Human Evolution 43 (4): 433–462. doi:10.1006/jhev.2002.0584. Mokom, F., and Z. Kobti. 2015. “Exploiting Objects as Artifacts in Multi-Agent Based Social Simulations.” Proceedings of the 14th International Conference on Autonomous Agents and Multiagent Systems (AAMAS 2015): 1869–1870. doi:10.5555/2772879.2773478. Morgan-Wall, T. 2019. rayshader: Create and Visualize Hillshaded Maps from Elevation Matrices. https://CRAN.R-project.org/package=rayshader. Moritz, M., R. Behnke, C. M. Beitl, R. B. Bird, R. M. Chiaravalloti, J. K. Clark, S. A. Crabtree, et al. 2018. “Emergent Sustainability in Open Property Regimes.” Proceedings of the National Academy of Sciences (November): 201812028. doi:10.1073/pnas.1812028115. Müller, B., F. Bohn, G. Dreßler, J. Groeneveld, C. Klassert, R. Martin, M. Schlüter, J. Schulze, H. Weise, and N. Schwarz. 2013. “Describing Human Decisions in Agent-Based Models – ODD + D, an extension of the ODD protocol.” Environmental Modelling & Software 48 (October): 37–48. doi:10.1016/j.envsoft.2013.06.003. Neiman, F. D. 1995. “Stylistic Variation in Evolutionary Perspective: Inferences from Decorative Diversity and Interassemblage Distance in Illinois Woodland Ceramic Assemblages.” American Antiquity 60, no. 01 (January): 7–36. doi:10.2307/282074. Newman, M. E. J. 2010. Networks: An Introduction. Oxford, UK: Oxford University Press. O’Dwyer, J. P., and A. Kandler. 2017. “Inferring Processes of Cultural Transmission: The Critical Role of Rare Variants in Distinguishing Neutrality from Novelty Biases.” Philosophical Transactions of the Royal Society B: Biological Sciences 372, no. 1735 (December): 20160426. doi:10.1098/rstb.2016.0426. O’Sullivan, D., and G. L. W. Perry. 2013. Spatial Simulation: Exploring Pattern and Process. Chichester, UK: John Wiley & Sons, September. https://patternandprocess.org/. Page, S. E. 2018. The Model Thinker: What You Need to Know to Make Data Work for You. First edition. New York, NY: Basic Books.

Bibliography Pardo-Gordó, S., S. M. Bergin, J. B. Aubán, and C. M. Barton. 2017. “Alternative Stories of Agricultural Origins: The Neolithic Spread in the Iberian Peninsula.” In Times of Neolithic Transition along the Western Mediterranean, edited by O. García-Puchol and D. C. SalazarGarcía, 101–131. Fundamental Issues in Archaeology. Cham, Switzerland: Springer International Publishing. doi:10.1007/978-3-319-52939-4_5. Patlak, C. S. 1953. “Random Walk with Persistence and External Bias.” The Bulletin of Mathematical Biophysics 15, no. 3 (September): 311–338. doi:10.1007/BF02476407. Payette, N. 2013. NetLogo Rnd-Extension. https://github.com/NetLogo/Rnd-Extension. Pearson, K. 1905. “The Problem of the Random Walk.” Nature 72, no. 1867 (August): 342–342. doi:10.1038/072342a0. Peeples, M. A. 2011. R Script for Calculating the Brainerd–Robinson Coefficient of Similarity and Assessing Sampling Error. Electronic document, https://www.mattpeeples.net/BR.html. Peeples, M. A., and W. R. Haas. 2013. “Brokerage and Social Capital in the Prehispanic US Southwest.” American Anthropologist 115 (2): 232–247. doi:10.1111/aman.12006. Pennington, R. 2001. Hunter-Gatherer Demography. Cambridge, UK: Cambridge University Press. Poledna, S., M. G. Miess, and C. H. Hommes. 2019. Economic Forecasting with an Agent-Based Model. SSRN Scholarly Paper. Rochester, NY: Social Science Research Network, November. https://papers.ssrn.com/abstract=3484768. Poundstone, W. 1993. Prisoner’s Dilemma: John Von Neumann, Game Theory and the Puzzle of the Bomb. New York, NY: Anchor Books. Powell, A., S. Shennan, and M. G. Thomas. 2009. “Late Pleistocene Demography and the Appearance of Modern Human Behavior.” Science 324 (5932): 1298–1301. doi:10.1126/science. 1170165. Premo, L. S. 2005. “Patchiness and Prosociality: An Agent-Based Model of Plio/Pleistocene Hominid Food Sharing.” In Multi-Agent and Multi-Agent-Based Simulation, edited by D. Hutchison, T. Kanade, J. Kittler, J. M. Kleinberg, F. Mattern, J. C. Mitchell, M. Naor, et al., 3415:210–224. Berlin, Germany: Springer. doi:10.1007/978-3-540-32243-6_17. . 2010. “Equifinalit and Explanation: The Role of Agent-Based Modeling in Post-Positivist Archaeology.” In Simulating Change: Archaeology into the Twenty-First Century, edited by A. Costopoulos and M. W. Lake, 28–37. Salt Lake City, UT: University of Utah Press. . 2014. “Cultural Transmission and Diversity in Time-Averaged Assemblages.” Current Anthropology 55, no. 1 (February): 105–114. doi:10.1086/674873. R Core Team. 2019. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/. Raichlen, D. A., B. M. Wood, A. D. Gordon, A. Z. P. Mabulla, F. W. Marlowe, and H. Pontzer. 2014. “Evidence of Lévy Walk Foraging Patterns in Human Hunter–Gatherers.” Proceedings of the National Academy of Sciences 111, no. 2 (January): 728–733. doi:10. 1073 / pnas. 1318616111.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Ramachandran, S., O. Deshpande, C. C. Roseman, N. A. Rosenberg, M. W. Feldman, and L. L. Cavalli-Sforza. 2005. “Support from the Relationship of Genetic and Geographic Distance in Human Populations for a Serial Founder Effec Originating in Africa.” Proceedings of the National Academy of Sciences 102, no. 44 (November): 15942–15947. doi:10 . 1073/pnas.0507611102. Raney, B., N. Cetin, A. Völlmy, M. Vrtic, K. Axhausen, and K. Nagel. 2003. “An Agent-Based Microsimulation Model of Swiss Travel: First Results.” Networks and Spatial Economics 3, no. 1 (January): 23–41. doi:10.1023/A:1022096916806. Renfrew, C., and P. G. Bahn. 2017. Archaeology: Theories, Methods and Practice. London, UK: Thames & Hudson. Reynolds, C. W. 1987. “Flocks, Herds, and Schools: A Distributed Behavioral Model.” In SIGGRAPH ’87 Conference Proceedings, 21:25–34. 4. Anaheim, CA: Computer Graphics. doi:1 0.1145/37402.37406. Riris, P. 2018. “Assessing the Impact and Legacy of Swidden Farming in Neotropical Interfluvia Environments through Exploratory Modelling of Post-Contact Piaroa Land Use (Upper Orinoco, Venezuela).” The Holocene 28, no. 6 (June): 945–954. doi:10.1177/09596836177528 57. Robinson, D. T., A. Di Vittorio, P. Alexander, A. Arneth, C. M. Barton, D. G. Brown, A. Kettner, et al. 2018. “Modelling Feedbacks between Human and Natural Processes in the Land System.” Earth System Dynamics 9, no. 2 (June): 895–914. doi:10.5194/esd-9-895-2018. Romanowska, I. 2015a. “Agent-Based Modelling and Archaeological Hypothesis Testing: The Case Study of the European Lower Palaeolithic.” In Across Space and Time. Papers from the 41st Conference on Computer Applications and Quantitative Methods in Archaeology, Perth, 25–28 March 2013, 203–214. Amsterdam, Netherlands: Amsterdam University Press. . 2015b. “So You Think You Can Model? A Guide to Building and Evaluating Archaeological Simulation Models of Dispersals.” Human Biology 87 (3): 169–192. doi:10 . 13110 / humanbiology.87.3.0169. . 2018. “Using Agent-Based Modelling to Infer Economic Processes in the Past.” In Quantifying Ancient Economies. Problems and Methodologies, edited by J. R. Rodriguez, V. R. Calvo, and J. M. Bermudez Lorenzo, 107–118. Instrumenta 60. Barcelona, Spain: University of Barcelona. Romanowska, I., T. Brughmans, P. Bes, S. Carrignon, L. Egelund, A. Lichtenberger, and R. Raja. 2021. “A Study of the Centuries-Long Reliance on Local Ceramics in Jerash Through Full Quantificatio and Simulation.” Journal of Archaeological Method and Theory (February). doi:10.1007/s10816-021-09510-0. Romanowska, I., S. A. Crabtree, K. Harris, and B. Davies. 2019. “Agent-Based Modeling for Archaeologists: Part 1 of 3.” Advances in Archaeological Practice 7 (2): 178–184. doi:10.1017/ aap.2019.6. Romanowska, I., C. Gamble, S. Bullock, and F. Sturt. 2017. “Dispersal and the Movius Line: Testing the Effec of Dispersal on Population Density through Simulation.” Quaternary International 431 (Part B): 53–63. doi:10.1016/j.quaint.2016.01.016.

Bibliography Rossignol, J., and L. Wandsnider. 1992. Space, Time, and Archaeological Landscapes. New York, NY: Plenum Press. Rubio-Campillo, X., F. X. H. Cardona, and M. Yubero-Gómez. 2015. “The Spatiotemporal Model of an 18th-Century City Siege.” Social Science Computer Review 33 (6): 749–765. doi:doi. org/10.1177/0894439314558559. Rubio-Campillo, X., P. V. Matías, and E. Ble. 2015. “Centurions in the Roman Legion: Computer Simulation and Complex Systems.” Journal of Interdisciplinary History 46 (2): 245–263. doi:doi.org/10.1162/JINH_a_00833. Sahlins, M. 1972. Stone Age Economics. Chicago, IL: Aldine Atherton. Sakoda, J. M. 1971. “The Checkerboard Model of Social Interaction.” The Journal of Mathematical Sociology 1, no. 1 (January): 119–132. doi:10.1080/0022250X.1971.9989791. Salecker, J., M. Sciaini, K. M. Meyer, and K. Wiegand. 2019. “The NLRX R Package: A Next‐Generation Framework for Reproducible NetLogo Model Analyses.” Edited by L. Graham. Methods in Ecology and Evolution 10, no. 11 (November): 1854–1863. doi:10.1111/2041-210X.13286. Sarjoughian, H. S., and B. R. Zeigler. 1998. “DEVSJAVA: Basis for a DEVS-Based Collaborative M&S Environment.” In SCS Western Multi-Conference, 30:29–36. San Diego. Schelling, T. C. 1969. “Models of Segregation.” The American Economic Review 59 (2): 488–493. https://www.jstor.org/stable/1823701. . 1971. “Dynamic Models of Segregation.” Journal of Mathematical Sociology 1 (2): 143– 186. doi:10.1080/0022250X.1971.9989794. Scherjon, F. 2013. “SteppingIn—Modern Humans Moving into Europe—Implementation.” In Proceedings of the 40th Conference on Computer Applications and Quantitative Methods in Archaeology Southampton, 26–30 March 2012, 105–117. Amsterdam, Netherlands: Amsterdam University Press. . 2019. “Virtual Neanderthals: A Study in Agent-Based Modelling Late Pleistocene Hominins in Western Europe.” PhD diss. https://openaccess.leidenuniv.nl/handle/1887/73639. Schindler, J. 2012. “A Simple Agent-Based Model of the Tragedy of the Commons.” In ECMS 2012 Proceedings, edited by K. G. Troitzsch, M. Moehring, and U. Lotzmann, 44–50. ECMS, May. doi:10.7148/2012-0044-0050. Semenchenko, A., G. Oliveira, and A.P.F. Atman. 2016. “Hybrid Agent-Based Model for Quantitative in-Silico Cell-Free Protein Synthesis.” Biosystems 150 (December): 22–34. doi:10. 1016/j.biosystems.2016.07.008. Sessions, R. 1950. “How a “Difficul Composer Gets that Way; Harpsichordist.” The New York Times. https://www.nytimes.com/1950/01/08/archives/how-a-difficult-composer-getsthat-way-harpsichordist.html. Simon, H. A. 1956. “Rational Choice and the Structure of the Environment.” Psychological Review 63 (2): 129–138. doi:10.1037/h0042769. Smith, W. H. F., and D. T. Sandwell. 1997. “Global Sea Floor Topography from Satellite Altimetry and Ship Depth Soundings.” Science 277, no. 5334 (September): 1956–1962. doi:10.1126/ science.277.5334.1956.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Smolla, M., S. Alem, L. Chittka, and S. Shultz. 2016. “Copy-When-Uncertain: Bumblebees Rely on Social Information when Rewards are Highly Variable.” Biology Letters 12, no. 6 (June): 20160188. doi:10.1098/rsbl.2016.0188. Squazzoni, F., J. G. Polhill, B. Edmonds, P. Ahrweiler, P. Antosz, G. Scholz, É. Chappin, et al. 2020. “Computational Models That Matter During a Global Pandemic Outbreak: A Call to Action.” Journal of Artificial Societies and Social Simulation 23 (2): 10. doi:10.18564/ jasss.4298. Stanford, K. 2017. “Underdetermination of Scientifi Theory.” In The Stanford Encyclopedia of Philosophy, Winter 2017, edited by E. N. Zalta. Stanford, CA: Metaphysics Research Lab, Stanford University. https : / / plato . stanford . edu / archives / win2017 / entries / scientific underdetermination/. Steele, J. 2009. “Human Dispersals: Mathematical Models and the Archaeological Record.” Human Biology 81 (2-3): 121–140. doi:10.3378/027.081.0302. Stephens, D. W., and J. R. Krebs. 1986. Foraging Theory. Princeton, NJ: Princeton University Press. Stephens, D. W., J. F. Lynch, A. E. Sorensen, and C. Gordon. 1986. “Preference and Profitability Theory and Experiment.” The American Naturalist 127, no. 4 (April): 533–553. doi:10.1086/ 284501. Stevens, M., J. Harrington, and F. Schiel. 2019. “Associating the Origin and Spread of Sound Change Using Agent-Based Modelling Applied to /s/-Retraction in English.” Glossa: A Journal of General Linguistics 4 (1): 8. doi:10.5334/gjgl.620. Stodden, V., and S. Miguez. 2014. “Best Practices for Computational Science: Software Infrastructure and Environments for Reproducible and Extensible Research.” Journal of Open Research Software 2, no. 1 (July): e21. doi:10.5334/jors.ay. Stonedahl, F., and U. Wilensky. 2010. “Evolutionary Robustness Checking in the Artificia Anasazi Model.” In Complex Adaptive Systems—Resilience, Robustness, and Evolvability: Papers from the AAAI Fall Symposium, 120–129. Association for the Advancement of Artificia Intelligence. https://www.aaai.org/ocs/index.php/FSS/FSS10/paper/view/2181. Taghikhah, F., T. Filatova, and A. Voinov. 2021. “Where Does Theory Have It Right? A Comparison of Theory-Driven and Empirical Agent Based Models.” Journal of Artificial Societies and Social Simulation 24 (2): 4. doi:10.18564/jasss.4573. ten Broeke, G., G. van Voorn, and A. Ligtenberg. 2016. “Which Sensitivity Analysis Method Should I Use for My Agent-Based Model?” Journal of Artificial Societies and Social Simulation 19 (1): 5. doi:10.18564/jasss.2857. Testart, A., R. G. Forbis, B. Hayden, T. Ingold, S. M. Perlman, D. L. Pokotylo, P. Rowley-Conwy, and D. E. Stuart. 1982. “The Significanc of Food Storage among Hunter-Gatherers: Residence Patterns, Population Densities, and Social Inequalities [and comments and reply].” Current Anthropology 23 (5): 523–537. Thiele, J. C., W. Kurth, and V. Grimm. 2014. “Facilitating Parameter Estimation and Sensitivity Analysis of Agent-Based Models: A Cookbook Using NetLogo and R.” Journal of Artificial Societies and Social Simulation 17 (3): 11. doi:10.18564/jasss.2503.

Bibliography Thomas, D. H. 1973. “An Empirical Test for Steward’s Model of Great Basin Settlement Patterns.” American Antiquity 38 (2): 155–176. doi:10.2307/279362. Tobler, W. R. 1970. “A Computer Movie Simulating Urban Growth in the Detroit Region.” Economic Geography 46:234–240. doi:10.2307/143141. Troitzsch, K. G. 2004. “Validating Simulation Models.” In 18th European Simulation Multiconference. Networked Simulations and Simulation Networks, edited by G. Horton, 117–128. San Diego: Erlagen. Ullah, I. I. T. 2015. Agmodel: Version 0.3. doi:10.5281/ZENODO.17551. Varien, M. D., and B. J. Mills. 1997. “Accumulations Research: Problems and Prospects for Estimating Site Occupation Span.” Journal of Archaeological Method and Theory 4 (2): 141– 191. doi:10.1007/BF02428057. Verhagen, P. 2012. “Biting off More than We Can Chew? The Current and Future Role of Digital Techniques in Landscape Archaeology.” In Landscape Archaeology between Art and Science, edited by S. J. Kluiving and E. Guttmann-Bond, 309–320. Amsterdam, Netherlands: Amsterdam University Press, December. doi:10.1515/9789048516070-023. Viswanathan, G. M., V. Afanasyev, S. V. Buldyrev, E. J. Murphy, P. A. Prince, and H. E. Stanley. 1996. “Lévy Flight Search Patterns of Wandering Albatrosses.” Nature 381, no. 6581 (May): 413–415. doi:10.1038/381413a0. Viswanathan, G. M., M. G. E. da Luz, E. P. Raposo, and H. E. Stanley. 2011. The Physics of Foraging: An Introduction to Random Searches and Biological Encounters. Cambridge, UK: Cambridge University Press, June. Waddington, K. D., and L. R. Holden. 1979. “Optimal Foraging: On Flower Selection by Bees.” The American Naturalist 114 (2): 179–196. doi:10.1086/283467. Weiss, H. 2013. “The SIR Model and the Foundations of Public Health.” MATerials MATemàtics 3 (17): 1–17. White, A. A. 2013. “An Abstract Model Showing that the Spatial Structure of Social Networks Affect the Outcomes of Cultural Transmission Processes.” Journal of Artificial Societies and Social Simulation 16 (3): 1–24. doi:10.18564/jasss.2219. Wickham, H., and G. Grolemund. 2017. R for Data Science: Import, Tidy, Transform, Visualize, and Model Data. 1st. Sebastapol, CA: O’Reilly Media, Inc. Wilensky, U. 1997. NetLogo Wolf-Sheep Predation Model. Evanston, IL. . 1999. NetLogo. Evanston, IL: Center for Connected Learning / Computer-Based Modeling, Northwestern University. https://ccl.northwestern.edu/netlogo. . 2002. NetLogo PD Basic Evolutionary Model. Technical report. Evanston, IL: Center for Connected Learning and Computer-Based Modeling, Northwestern University. https: //ccl.northwestern.edu/netlogo/models/PDBasicEvolutionary. Wilensky, U., and W. Rand. 2015. An Introduction to Agent-Based Modeling: Modeling Natural, Social, and Engineered Complex Systems with NetLogo. Cambridge, MA: MIT Press, April.

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O LO GY

Wilkinson, T. J., M. Gibson, J. Christiansen, M. Widell, D. Schloen, N. Kouchoukos, C. Woods, et al. 2007. “Modeling Settlement Systems in a Dynamic Environment: Case Studies from Mesopotamia.” The Model-Based Archaeology of Socionatural Systems. https://discovery. ucl.ac.uk/1329440/. Willem, L., F. Verelst, J. Bilcke, N. Hens, and P. Beutels. 2017. “Lessons from a Decade of IndividualBased models for Infectious Disease Transmission: A Systematic Review (2006–2015).” BMC Infectious Diseases 17, no. 1 (September): 612. doi:10.1186/s12879-017-2699-8. Winterhalder, B., and E. A. Smith. 1981. Hunter-Gatherer Foraging Strategies: Ethnographic and Archeological Analyses. Chicago, IL: University of Chicago Press. Wobst, H. M. 1974. “Boundary Conditions for Paleolithic Social Systems: A Simulation Approach.” American Antiquity 39 (2): 147–178. doi:10.2307/279579. Wolfram, S. 2002. A New Kind of Science. Champaign, IL: Wolfram Media. Wren, C. D., C. Atwater, K. Hill, M. A. Janssen, J. C. De Vynck, and C. W. Marean. 2018. “An Agent-Based Approach to Weighted Decision Making in the Spatially and Temporally Variable South African Palaeoscape.” In Proceedings of the 44th Computer Applications and Quantitative Methods in Archaeology Conference (CAA 2016), 507–522. Oslo, Norway: Archeopress. Wren, C. D., S. Botha, J. C. De Vynck, M. A. Janssen, K. Hill, E. Shook, J. Harris, et al. 2020. “The Foraging Potential of the Holocene Cape South Coast of South Africa without the Palaeo-Agulhas Plain.” Quaternary Science Reviews. doi:10.1016/j.quascirev.2019.06.012. Wren, C. D., and A. Burke. 2019. “Habitat Suitability and the Genetic Structure of Human Populations during the Last Glacial Maximum (LGM) in Western Europe.” PLOS ONE 14, no. 6 (June): e0217996. doi:10.1371/journal.pone.0217996. Wren, C. D., J. Z. Xue, A. Costopoulos, and A. Burke. 2014. “The Role of Spatial Foresight in Models of Hominin Dispersal.” Journal of Human Evolution 69:70–78. doi:10.1016/j.jhevol. 2014.02.004. Xue, J. Z. 2013. “A Theory of Supply-Driven Evolution for Cultural Evolution.” Israel Journal of Ecology and Evolution 59, no. 2 (May): 92–98. doi:10.1080/15659801.2013.853436. Yang, C., and U. Wilensky. 2011. NetLogo EpiDEM Basic Model. Evanston, IL. Young, D. A., and R. L. Bettinger. 1992. “The Numic Spread: A Computer Simulation.” American Antiquity 57 (1): 85–99. doi:10.2307/2694836. . 1995. “Simulating the Global Human Expansion in the Late Pleistocene.” Journal of Archaeological Science 22 (1): 89–92. doi:10.1016/S0305-4403(95)80165-0. Zubrow, E. B. W. 1971. “Carrying Capacity and Dynamic Equilibrium in the Prehistoric Southwest.” American Antiquity 36 (2): 127–138. doi:10.2307/278666.

I INDEX

A abstraction, 235, 236, 350 Ackland, G. J., 226 adaptation, 179, 180, 247 agent definition of, 7 agent-based modeling, 6, 10, see also agent, see also model in archaeology, 3, 4, 11, 12, 20, 107, 108, 110, 187, 208, 212, 238, 302, 339 software, 12 agentset, 31, 49–51, 83, 92, 278, 302 Akaike Information Criterion, 146 algorithm, see diffusion definition of, 21 genetic, 144, 336, 337 movement, 14, 128, 148, 227, 279 algorithmic zoo, 155 analysis, 189, 269, 277, 284, 297, 318, 324–326, 329, 330, 334, 335, 339, 342, 352 sensitivity, 89, 138, 313, 314, 334–336, 351 uncertainty, 335 anonymous procedures, 95, 97 Anthony, D.W., 134 Approximate Bayesian Computation, 337 approximation, 31, 34, 48, 114 arbitrary values, 89, 90 Artificial Anasazi, see model average degree, 295–297, 309 average shortest path length, 297 Axtell, R.L., 76, 77, 98

B Baker, J., 168 balanced reciprocal exchange networks (BRN), 285–288, 298–302, 304–306, 309

Barceló, J. A., 180 barter, 155–157, 169 Barton, C.M., 202, 206–208, 212, 222, 340 Bayesian approaches, 146, 337 Bayesian Information Criterion, 146 BehaviorSpace, 270, 313, 321–325 benchmarking, 277 Bergin, S., 141, 206, 227 Bernabeu Aubán, J., 141, 227 Bettinger, R.L., 20, 30, 34, 35, 40 betweenness centrality, 297, 298 Beyer, R.M., 268 Boolean definition of, 92, 178, 183 409 bottom-up models, 6, 222 bounded rationality, 170 Box, G.E.P., 40 Braconnot, P., 267 Brantingham, P.J., 112, 249 breed, 45, 46, 50, 51, 56, 70, 78, 160, 173, 212, 229, 256, 257, 276, 287, 291, 297 Brughmans, T., 166, 181, 188, 284, 295, 302 bug, 65, 66, 70, 85, 93, 248, 276, 303, 305–307, 352, see also testing Bullock, S., 281 Burke, A., 221, 222, 340 burn-in period, 321

C calibration, 3, 89, 108, 313, 314, 325, 326, 356 Carrignon, S., 180, 181 causation, 34, 89 Cegielski, W.H., 302 cellular automata (CA) definition of, 135

difference from ABM, 135 ceramics, 46–48, 90, 144, 159, 163–165, 173, 180, 188, 277, 289 chaos, 5 chemistry, 110, 134 Clark, J.K., 128, 130 climate change, 22 cluster, 293 code block, 28 coefficient of variation, 318 color, see Appendix command, 24, 25, 28–30, 36, 38 complexity, 6, 11, 22, 23, 51, 66, 76, 77, 176, 189, 194, 231, 238, 269, 283, 308, 325, 341, 347, see science theory of, 5 condition, 28 Conolly, J., 250 continuous space, 186 Costopoulos, A., 125, 337 Crabtree, S.A., 10, 128, 130, 203, 215, 284, 286, 287, 302, 329, 336, 341, 342 Crawford, K. A., 127 Crema, E.R., 180, 194, 216, 217, 221, 222 Crooks, A.T., 126, 248 cultural trait, 171–179, 181, 183, 226, 339 cultural transmission, 13, 110, 155, 156, 171, 172, 177, 178, 180, 181, 183, 186, 188, 190, 237, 302, see also transmission bias, 155, 173–177, 181, 182, 339 culture, 76, 171, 180, 338

D data analysis, 13, 34, 144, 278, 315, 326, 329, 330, 341, 342, 352 artificial, 13, 21, 63, 75, 89, 146, 313, 314, 316, 318 417

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O L O G Y

distribution, 145 structures, 92, 164, 250 Davies, B., 249, 259, 277 Dean, J.S., 77, 340 debug, 25, 45, 65–67, 75, 88, 93, 95, 96, 187, 276, 288, 303, 307, 348, 354, see also testing diffusion, 20, 110, 134, 172, 226, 266 cultural, 110 demic, 110 digital object identifier (DOI), 341 dimension, 7, 8, 11 dispersal, 20, 21, 32, 33, 35, 36, 38–41, 89, 90, 109, 110, 114, 134, 135, 139, 141, 143, 145, 148, 227, 248, 342 distance Edit, 179 Hamming, 179, 180 Jaccard, 179 distribution Cauchy, 116 normal (Gaussian), 115, 200 uniform, 141 drift, see random drift dynamics evolutionary, 193, 194, 223, 226 population, 41, 78, 98, 128, 134, 193, 194, 214, 216, 219, 221, 223, 226, 228, 236, 316, 318

E ecology, 10–12, 110, 181, 195, 208, 267, 353 economy, 189 edge definition of, 291 directed, 290, 293 undirected, 290, 293 Eerkens, J.W., 180 Eglen, S.J., 341 emergence, 7, 135, 174, 178, 313, 334, 337, 338 entity, 5, 28, 45, 48, 195 Epstein, J.M., 338 equation-based model, see model equifinality, 34, 75, 89, 107, 142, 199 equilibrium Nash, 170 evaluation, 133, 334, 356 418

evolution, 4, 11, 12, 33, 88, 99, 133, 134, 171, 178, 180, 185, 194 202, 204, 223, 226, 232, 233, 239, 336, 340 cultural, 155, 156, 171, 179–181, 189, 224, 226 exchange, 13, 14, 45, 48, 60, 75, 80, 107, 155–157, 165, 166, 169–171, 180, 188–190, 193, 238, 284–287, 289, 291, 295, 299–302, 306, 309 experiment design, 249, 276, 313, 314, 336, 342, 351 explanatory model, see model extension GIS, 36, 250–253, 255–257, 260, 262, 269, 287, 340 411 LevelSpace, 133, 134 Network, 281, 284, 286, 287, 295, 296 Profiler, 247, 271–273, 275, 276, 309, 319 R, 277 RnD, 119–121, 174, 217, 219, 223, 224, 250

F fitness, 56, 109, 179, 193, 194, 216, 217, 223–226, 235, 336, 337 float, 92 flocking, 5, 10, 126, 127, 414 formalism, 236 Fort, J., 134, 135 fractal, 269, 270 frequency, 45–48, 61, 64, 90–92, 132, 165, 173, 176, 177, 181, 225, 239, 298, 303, 320, 334 Fábrega-Álvarez, P., 269

G Game of Life, 135 game theory, 193, 194, 229, 233, 235 Gauthier, N., 228 Geertz, C., 190 generality, 48, 269, 281–283, 350 generalized reciprocal exchange network (GRN), 285, 286, 288, 292–295, 298, 300, 302, 309 genetics, 178, 203, 226

geographic information science (GIS), 9, 12, 13, 31, 36, 92, 118, 143, 200, 247–250, 252, 254, 258, 259, 262, 266–270, 277, 278, 282, 313 geometry, 331, 332 Gilbert, N., 156, 159, 165, 169, 170 Gillings, M., 250 Graham, S., 180, 187, 302, 354 graph, 64, 204, 290, 291, 297, 308, 326, 330, 331 Gravel-Miguel, C., 325 grid, 10, 23, 26, 36, 37, 90, 211, 253, 254, 333 Grolemund, G., 327 growth, 20–22, 28, 32, 40, 90, 128, 134, 135, 188, 193, 201, 215, 221–223, 235, 236, 285, 286, 336, 356

H Hacigüzeller, P., 250 Hamill, L., 156, 159, 165, 169, 170 Hammond, R.A., 8 hard-coding, 308, 322, 324 Harrison, S.P., 267 Haywood, A.M., 267 Helbing, D., 126 Henrich, J., 180 heterogeneity, 8, 134, 170, 198, 235, 248, 269, 289 Hill, K., 127, 130, 133, 214, 269 histogram, 100, 157, 158, 225, 298, 299 homogeneity, 182 Hughes, J.K., 135, 136

I ID, 56, 132, 261, 262

information, see also transmission initialization, 21, 272, 321 input, 28, 56, 59, 65, 87, 94, 193, 287, 297, 313, 316, 322, 324, 326, 327, 333–336, 342, 352 integer, 92, 93 interaction agent–agent, 193, 259, 264, 265, 337 agent–patch, 193, 199, 259, 260, 265 nonlinear, 5 patch-patch, 203, 259, 264 Internet Archaeology, 341

Index

J Janssen, M.A., 77, 98, 99, 101, 127, 130, 133, 214, 269, 336 Jupyter Notebook, 278, 330

K Kandler, A., 180 Keltsch, J., 126 Knuth, D.E., 277 Kohler, T.A., 76, 77, 201 Krapp, M., 268

L label, 52, 55, 60, 61, 215, 216, 288, 333, 338 Lake, M.W., 12, 122, 125, 250, 269, 271, 339 Laland, K.N., 180 Ligtenberg, A., 318, 337 Linden, M.V., 135 line plot, 100, 225, 320, 334 Lipo, C. P., 180 list, 25, 29, 45, 46, 51, 54, 56, 61–64, 70, 71, 75, 90, 92–99, 101, 122, 125, 155, 159–164, 174, 175, 179, 180, 195, 198, 200, 209, 210, 212–214, 219, 250, 256, 257, 261, 262, 278, 287, 292, 300, 301, 304, 305, 318, 321, 339 nested, 255 lithics, 260 Llobera, M., 269 Lock, G.R., 250 loop for, 46 if, 46, 60, 81, 95, 96, 117, 128, 130, 174, 201 nested, 174 while, 46, 60, 63, 64, 131–133, 227, 230 Lévy flight, 115, 116, 128, 141, 149, 210

M machine learning, 146 Manica, A., 268 McKinney, W., 327 Mesoudi, A., 156, 171, 173 methodology, 13, 111, 118, 339 Microsoft Excel, 313, 326–332

Miguez, S., 341 Mithen, S. J., 12, 135 model demographic cultural evolution, 175 abstract, 20, 45, 69, 98, 100, 208, 236 Ache hunting, 130, 214, 269 agent-based, 6–11, 20, 75, 88, 118, 135, 168, 170, 194, 199–201, 206, 208, 237, 250, 260, 269, 277, 282, 302, 308, 315, 317, 337–339, 347, 351, 352, 354 AgModel, 202, 203 AmphorABM, 194, 203–205, 248, 316, 317, 320–324, 326, 335, 336, 338 Artificial Anasazi, 11, 75–77, 90, 98–101, 145, 197, 336, 340, 355 bidding market, 168 Boids (flocking), 5, 8, 88, 126, 127, 148 Cardial Neolithic, 194 Cardial Spread, 141, 227 complex, 45, 155, 162, 179, 194, 336 correlated random walk, 114 Cultural Hitchhiking, 226 Cultural Trade, 180 definition of, 32 diet-breadth, 212–214 diffusion, 20 digital elevation (DEM), 267, 277 Edgeworth Box game, 168, 169 equation-based, 20, 138 explanatory, 283 Fisher–Skellam–KPP, 20, 134, 138, 141, 216 fission–fusion, 216, 218 foraging memory capacity, 125 Ger Grouper, 128, 194, 201, 215, 216 HomininSpace, 144 hunter-gatherer, 180 individual-based, 10 LGM ecodynamics, 221, 223 Lotka–Volterra, 195, 196 MAGICAL, 122, 269 Market, 159–161 MASTOC, 229 MedLanD, 141, 146, 194, 206, 208, 211, 277 Mercury, 166, 167 multilevel population dynamics, 228

Neolithic spread, 135 nested, 228 Neutral Procurement, 249 neutral procurement, 112, 249, 277 null, 159 out-of-Africa dispersal, 135 PaleoscapeABM, 118, 211 Patagonian hunter-gatherers, 180 patch-choice, 208, 209, 211, 239 physical, 13 Piaroa Swidden Farming, 208 Prestige Trade, 180 prey-choice, 208, 212, 214 Prisoner’s Dilemma, 233 procession movement, 127 Random Seed Example, 324 random walk, 111, 112 realistic, 7, 69, 166, 201, 238, 259, 281, 282 restricted walk, 121 roulette reproduction, 224 Schelling–Sakoda segregation, 10, 88 selection, 89, 143, 144, 146 SHEEP, 145 Shops, 170 simple economy, 156, 158 spatial foresight, 139, 140 Stepping Out, 135, 137 SteppingIn, 138 SugarScape, 75–77, 88, 90, 98, 100, 101, 148, 222, 248, 279, 340 Susceptible–Infectious–Recovered (SIR), 184 Swidden Farming, 207 theory-building, 283 time-averaging, 181 top-down, 222 trade distance, 50 trail evolution, 126 Village Ecodynamics, 77, 201, 238, 302 Walk This Way, 126 weighted random walk, 119 Wolf–Sheep Predation, 194– 196, 199, 215, 236, 318 Young & Bettinger (Y&B) dispersal, 20, 30, 34, 35, 40 Molnár, P., 126 419

A G E N T- B A S E D M O D E L I N G F O R A R C H A E O L O G Y

movement, 13, 14, 28–30, 33, 40, 75, 101, 107–111, 113, 116, 120–122, 126–128, 131, 134, 146, 147, 155, 171, 189, 199, 201, 210, 215, 239, 247, 259, 260, 263, 269, 329, 340 mutation, 174, 178, 179, 182, 226, 336 Müller, B., 340

N negative reciprocity, 285, 286 neighbor, 31, 52, 59, 76, 126, 127, 135, 141, 177, 233, 234, 253, 266, 290, 295 neighborhood Moore, 31, 32, 128 Von Neumann, 31, 32 NetLogo, 3, 10, 12, 13, 19, 20, 23–26, 28–31, 35, 36, 38, 41, 45, 46, 49–52, 54, 56–62, 64, 65, 70 agentset, 31, 49–51, 83, 92, 278, 302 breed, 45, 46, 50, 51, 56, 70, 78, 160, 173, 212, 229, 256, 257, 276, 287, 291, 297 command center, 56, 62, 67, 272, 276, 303, 304 interface, 23 procedure, 24, 28 network, 290 components, 290 Erdős-Rényi, 291 small-world, 297 network science, 45, 156, 281, 284, 290, 291, 295, 296, 302, 308, 309 node, 290, 291, 294–298, 308 noise, 139, 145, 188

O ODD protocol, 340 one factor at a time (OFAT), 336 ontology definition of, 68, 155, 173, 187 OpenMOLE, 342 optimization, 247, 249, 277, 351 order rank (sharing strategy), 28, 38, 49, 59, 90, 94, 110, 111, 164, 294 Ornstein, J. T., 8 overfitting, 337

420

O’Dwyer, J.P., 180 O’Sullivan, D., 269

P parameter, 235 definition of, 90 space, 144, 188, 325, 335–337 sweep, 146, 306, 313, 314, 321, 325, 326, 333, 334, 336, 338, 342 parameterization, 40, 75, 80, 90, 100, 189, 193, 194, 221, 235, 237, 316, 321, 351 Parcero-Oubiña, C., 269 parsimony, 147, 155, 156, 187, 189, 238, 248, 283, 342, 351 patch definition of, 78 path, 112, 114, 118, 211 shortest, 297, 309 Pearson, K., 112 peer review, 315 Pennington, R., 221 Perry, G. L. W., 115, 269 phase initialization, 21 run, 22 phase space, 314, 322 Poblome, J., 188, 302 point of equilibrium, 317 population interactions, 134 size, 90, 100, 196, 214, 225, 227, 238, 318, 327, 328, 332, 335, 336 pottery, see ceramics Powell, A., 175 precision, 9, 90, 236, 281–283, 350 prediction, 33, 89, 143, 282, 283 preferential attachment, 291 Premo, L.S., 181, 182, 236, 282 price setting, 155, 156 primitive, 25, 26, 30, 31, 36, 38, 46, 50–52, 54, 57, 59, 64, 67, 70, 71, 75, 78, 82, 83, 87, 91, 93–97, 99, 107, 112, 115, 117, 119, 122, 128, 134, 164, 172, 255–257, 264, 290, 293, 296, 302, 306, 308, 319, 320, 324, 353 procedure go, 24, 28, 30, 38

move, 83 setup, 24–26, 36, 38 pseudocode definition of, 21 Pujol, T., 135 Python, 12, 70, 95, 277, 295, 306, 313, 314, 326, 329–334, 342

R R, 136, 277, 295, 314, 329–333, 341 Rand, W., 194 random drift, 173 random seed, 314, 315, 324 randomness, 119, 120, 188, 315, 327, see also model rank, 207, 212, 213 raster, 36, 248, 250–252, 266, 269, 277, 278 realism, 90, 188, 235, 236, 270, 281–283, 350 Reed, M., 135 replication, 99–101, 140, 197, 221, 249, 270, 307, 336 reporter, 25, 45, 49, 62, 90, 96–98, 157, 172, 295–297, 324, 326 repository, 35, 155, 220, 239, 268, 339, 340 resilience, 193, 199, 200, 203, 239, 286 resource pooling, 285–289, 298, 302, 309 Reynolds, C., 5, 10, 127 Riris, P., 208, 266, 340 Robinson, D. T., 206 robustness, 194, 305, 335, 347 Rogers, J.D., 302 Romanowska, I., 48, 135, 145, 172, 181 roulette wheel algorithm, 219, 223 run, 314

S Sahlins, M.D., 285–287, 293, 299, 300, 302 Sakoda, J.M., 88 scale, 45, 49, 107, 109 scenario, 4, 10, 34, 61, 89, 90, 139, 144, 146, 174, 188, 215, 216, 237, 265, 284, 305, 314–316, 319, 321, 322, 324–327, 332 Schelling, T. C., 88

Index Scherjon, F., 138, 144 Schindler, J., 229 science complexity, 3, 5, 6, 10, 14, 19, 98, 349 season, 110, 128, 130, 134 self-organized criticality, 337 sensing, 109, 116, 117, 127 Shennan, S., 175, 180 similarity measures, 179, 180 Simon, H.A., 170 simulation, 3–9, 11, 12, 19–21, 23–26, 28, 32–34, 38–40, 45, 46, 49, 50, 56, 57, 59–61, 65, 66, 69, 75, 77, 80, 82, 88–92, 107–109, 112, 121, 124, 134, 135, 144, 145, 157, 161, 162, 170, 180, 184, 187, 188, 194, 206, 226, 235, 248, 262, 267–269, 277, 281–283, 302, 303, 305, 307, 313–315, 317, 319–322, 326, 327, 330, 335, 347–349, 352, 355, see also model spatial autocorrelation, 247 spatial variability, 8, 200, 202, 237 spherical cow, 283 Steele, J., 134 stochasticity, see randomness Stodden, V., 341 Stonedahl, F., 336, 337 string, 92, 179, 306, 319 stylized fact, 143, 145, 147 subsistence, 13, 14, 75, 78, 99, 107, 108, 148, 172, 173, 188, 189, 193–195, 199–201, 203, 208, 214, 227, 228, 235–239, 260, 267, 286 summary statistics, 298 supply and demand, see model sweep, 314 syntax, 21, 25, 46, 52, 70, 75, 82, 97, 107, 302, 348 system complex, 5, 8, 77, 249, 308, 347–349, 355 coordinate (geography), 250, 251

T

testing, 4, 33–35, 66, 205, 262, 270,275, 281, 283, 285, 302, 303, 305–307, 321, 335, 337, 340, 349–351, 356 scenario, 146, 305 Thomas, M.G., 175 threshold, 58, 61, 68, 203, 206, 209, 214, 216, 227, 228, 259, 264, 336 tick, see time step, time step, 21, 22, 24–28, 32, 38, 40, 51, 52, 56, 57, 61, 62, 71, 78–83, 86, 90, 94, 109–111, 123, 130, 131, 134, 137, 140, 161–164, 166, 182, 184, 197, 199–201, 205, 209, 211, 217, 221, 222, 224–226, 230, 231, 234, 272–275, 277, 287, 288, 290, 298, 307, 313, 317, 318, 320, 321, 324 Tobler, W.R., 247 topology, 9, 264, 290 torus, 36, 264 toy landscape, 86, 139, 316 tractability, 90, 281–283, 350 trade, see exchange trade-off, 48, 90, 203, 281, 282, 350 tragedy of the commons, 193, 194, 228–230, 233, 238 transition, 202, 316 transmission, 155, 171–175, 183–186, 189, 226, see also cultural transmission horizontal, 171, 172, 181, 189 oblique, 172, 175 social, 171 vertical, 171, 172, 174, 175, 189 turtle, see agent

V

U

X

Ulam, S., 10 Ullah, I.I.T., 202, 206 uncertainty, 144, 147, 170, 236, 334,335 underdetermination of scientific theory, 89, 143 universality, 98 utility, 121, 159, 165, 168, 170, 171, 173, 176, 177, 186, 238

validation, 75, 76, 88, 89, 98, 107–109, 142–147, 268, 316, 348, 352 types of, 143 van Voorn, G., 318, 337 variable, 56, 321 definition of, 45, 49, 56 global, 30, 46, 56, 57, 61, 70, 87, 88, 138, 207, 250, 318 local, 46, 54, 57, 59, 63, 80, 82, 83, 117 state, 30 vector, 36, 250, 254, 255, 257, 258, 261, 278 verification, 65, 75, 109 Village Ecodynamics Project, 76, 77, 201, 202, 237, 302 visualization, 289, 293, 303, 315, 326, 333, 342 von Neumann, J., 10

W walk correlated random, 114, 115, 339 random, 111–114, 117, 118, 128, 138, 211, 260, 338, 340 targeted, 116, 119, 128, 138, 141, 219 weighted, 119, 120 warm-up phase, see burn-in period White, A.A., 302 Wickham, H., 327 Wilensky, U., 156, 194, 195, 233, 336, 337 Wren, C. D., 118, 119, 139, 140, 202, 211, 221, 222, 224, 340

Xue, J.Z., 179

Y Young, D. A., 20, 30, 34, 35, 40

temporal variability, 200, 202, 237 ten Broeke, G., 318, 337 421

Contents

Introduction

Chapter 1

Chapter 2

New Imam River Castle/ Hanekiyye Town

Güzelcedere Bridge/ Güzelcedere

Ucan/Abbas Khan Türkmen Town

Sadabad

Chapter 3

Chapter 4

Chapter 5

Chapter 6

Bassiz Kümbet

Bitlis

Galata/Istanbul

Karanicay/Miyane

Chapter 7

Chapter 8

Chapter 9

Conclusion

Hamadan

Gardens of Dergezin

Mouth of Karadere/ Seymen Plain/Khoy

Tabriz

I THE IMAGES IN THIS VOLUME The images in this volume are from Beyan-ı Menazil-i Sefer-i Irakeyn-i Sultan Süleyman Han (Chronicle of Stages of Campaign of Iraq and Persia of Sultan Suleiman Khan), also known as The Menazilname. The Menazilname is among the most prominent works of Matrakçı Nasuh (1480– c. 1564), a Bosnian polymath who was a historian, mathematician, artist, calligrapher, and swordsman. An excellent example of Ottoman art from the period of Kanunî Sultan Süleyman’s reign (1520-1566), The Menazilname features a historical narrative and 107 elaborate miniature paintings combining to describe the route taken by the Ottoman army during the Sultan’s Iraqi campaign of 1534.

Glossary

Model Zoo

Dergezin Town

Karanicay

ABMs for the Colorblind New Imam River

Bibliography

Index

Erzincan

Baghdad

V AUTHORS IZA ROMANOWSKA (@Iza_Romanowska) is a complexity

scientist working on the interface between social sciences and computer science, having originally trained and worked as a prehistoric archaeologist before switching to computerbased research. She specializes in agent-based modeling, a simulation technique she uses for various research questions, from mobility in prehistoric cities and the first out-of-Africa human dispersal to large-scale economic interactions across the Roman Mediterranean and real-time pedestrian flows in modern sports venues. As an Aarhus Institute of Advanced Studies–COFUND fellow (2020–2023), she will be working on the project “Reconstructing Ancient Demographics through Archaeological–Historical Data Integration and Computer Simulation: The Cases of the Dutch Roman Limes and Roman Palmyra.” COLIN D. WREN (@CDWren) is a Palaeolithic archaeologist

specializing in computational approaches including agentbased modeling, geographic information science, and data visualization (Ph.D. McGill University). He is an Associate Professor of Anthropology at University of Colorado— Colorado Springs, and a research associate with the African Center for Coastal Palaeoscience at Nelson Mandela University. He has published various case studies examining the interactions between human society and the environment on both local and continental scales. Dr. Wren is interested in reconstructing the evolution of past mobility and foraging behavior, complex cognition, and human– environment dynamics. His ongoing projects include models of South African foraging behavior during periods relevant to the evolution of Homo sapiens and the impacts of climatic variability on inter-regional mobility and social interaction during the Last Glacial Maximum (ca. 20,000 years ago) in Western Europe.

STEFANI A. CRABTREE (@StefaniCrabtree) is Assistant

Professor in Socio-Environmental Modeling in the Department of Environment and Society of the Quinney College of Natural Resources at Utah State University and the ASU-SFI Center for Biosocial Complex Systems Fellow at The Santa Fe Institute. She additionally holds external affiliation at three institutions: Research Associate at Crow Canyon Archaeological Center, Fellow at the Centre de Recherches Interdisciplinaires Paris, and Research Associate at the Australian Research Council Centre of Excellence for Australian Biodiversity and Heritage. Her research applies complex systems science modeling methodologies (such as agent-based modeling and network science) to problems in social science and ecology. Current research topics include the human place in ecosystems worldwide, the ability to use the archaeological past to calibrate our understanding of human resilience, and the feedbacks between ecosystem health and human health. Dr. Crabtree holds two PhDs, one from Washington State University (Anthropology, 2016) and one from the Université de Franche-Comté (Maison des Sciences de l’Homme et l’Environnement, 2017).

SFI PRESS BOARD OF ADVISORS Nihat Ay

John Miller

Professor, Max Planck Institute for Mathematics in the Sciences; SFI Resident Faculty

Professor, Carnegie Mellon University; SFI Science Steering Committee Chair

Sam Bowles

Chairman & CEO, Miller Value Partners; SFI Trustee & Chairman Emeritus

William H. Miller

Professor, University of Siena; SFI Resident Faculty

Jennifer Dunne

Melanie Mitchell

SFI Resident Faculty;

SFI Vice President for Science

SFI Davis Professor of Complexity, Science Board co-chair; SFI External Faculty

Jessica Flack

Cristopher Moore

SFI Resident Faculty

SFI Resident Faculty

Mirta Galesic

Sidney Redner

SFI Resident Faculty

SFI Resident Faculty

Chris Kempes

Dan Rockmore

SFI Resident Faculty

Professor, Dartmouth College; SFI External Faculty

Manfred Laublicher

President’s Professor, Arizona State University; SFI External Faculty

Jim Rutt JPR Ventures; SFI Trustee

Michael Mauboussin

Daniel Schrag

Managing Director, Global Financial Strategies; SFI Trustee & Chairman of the Board

Professor, Harvard University; SFI External Faculty

Geoffrey West

Cormac McCarthy

SFI Resident Faculty;

Author; SFI Trustee

SFI Toby Shannan Professor of Complex Systems & Past President

Ian McKinnon

Founding Partner, Sandia Holdings LLC; SFI Trustee

David Wolpert

SFI Resident Faculty

EDITORIAL David C. Krakauer

Publisher/Editor-in-Chief

Tim Taylor

Aide-de-Camp

Katherine Mast

SFI Press Associate

Laura Egley Taylor Manager, SFI Press

Sienna Latham Managing Editor

Bronwynn Woodsworth SFI Press Assistant

SFI

PRESS

T H E S A N TA F E I N S T I T U T E P R E S S

The SFI Press endeavors to communicate the best of complexity science and to capture a sense of the diversity, range, breadth, excitement, and ambition of research at the Santa Fe Institute. To provide a distillation of discussions, debates, and meetings across a range of influential and nascent topics. To change the way we think. SEMINAR SERIES

New findings emerging from the Institute’s ongoing working groups and research projects, for an audience of interdisciplinary scholars and practitioners. ARCHIVE SERIES

Fresh editions of classic texts from the complexity canon, spanning the Institute’s thirty years advancing the field. COMPA SS SERIES

Provoking, exploratory volumes aiming to build complexity literacy in the humanities, industry, and the curious public. SCHOL ARS SERIES

Affordable and accessible textbooks disseminating the latest findings in the complex systems science world.

Also from SFI Press The Emergence of Premodern States: New Perspectives on the Development of Complex Societies Jeremy A. Sabloff & Paula L. W. Sabloff, eds. Worlds Hidden in Plain Sight: The Evolving Idea of Complexity at the Santa Fe Institute, 1984- 2019 David C. Krakauer, ed.

For additional titles, inquiries, or news about the Press, visit us at www.sfipress.org.

ABOUT THE SANTA FE INSTITUTE The Santa Fe Institute is the world headquarters for complexity science, operated as an independent, nonprofit research and education center located in Santa Fe, New Mexico. Our researchers endeavor to understand and unify the underlying, shared patterns in complex physical, biological, social, cultural, technological, and even possible astrobiological worlds. Our global research network of scholars spans borders, departments, and disciplines, bringing together curious minds steeped in rigorous logical, mathematical, and computational reasoning. As we reveal the unseen mechanisms and processes that shape these evolving worlds, we seek to use this understanding to promote the well-being of humankind and of life on Earth.

COLOPHON The body copy for this book was set in EB Garamond, a typeface designed by Georg Duffner after the Ebenolff-Berner type specimen of 1592. Headings are in Kurier, created by Janusz M. Nowacki, based on typefaces by the Polish typographer Małgorzata Budyta. For footnotes and captions, we have used CMU Bright, a sans serif variant of Computer Modern, created by Donald Knuth for use in TeX, the typesetting program he developed in 1978. The SFI Press complexity glyphs used throughout this book were designed by Brian Crandall Williams.

–A–

S AN TA F E I N ST I T UT E

COMPLEXITY GLYPHS

–B–

–C–

–D–

–E–

–F–

–G–

–H–

–I–

–J–

–K–

–L–

–M–

–N–

–O–

–P–

–Q–

–R–

–S–

–T–

–U–

–V–

–W–

–X–

–Y–

zero

one

two

three

four

five

six

seven

eight

nine

–Z–

SFI

PRESS

SCHOLARS SERIES

In the course of an excavation, when something comes up out of the ground, everything is cleared away very carefully all around it. You take away the loose earth, and you scrape here and there with a knife until finally your object is there, all alone, ready to be drawn and photographed with no extraneous matter confusing it. This is what I have been seeking to do—clear away the extraneous matter so that we can see the truth. — A G AT H A C H R I ST I E, D E AT H O N T H E N I L E (1937)

but also the trajectories, of human societies, we need a more dynamic view of human social systems. Agentbased modeling (ABM), which can create fine-scale models of behavior over time and space, may reveal important, general patterns of human activity. Agent-Based Modeling for Archaeology is the first ABM textbook designed for researchers studying the human past. Appropriate for scholars from archaeology, the digital humanities, and other social sciences, this book offers novices and more experienced ABM researchers a modular approach to learning ABM and using it effectively. T O F U L LY U N D E R S TA N D N O T O N LY T H E PA S T,

Readers will find the necessary background, discussion of modeling techniques and traps, references, and algorithms to use ABM in their own work. They will also find engaging examples of how other scholars have applied ABM, ranging from the study of the intercontinental migration pathways of early hominins, to the weather–crop–population cycles of the American Southwest, to the trade networks of Ancient Rome. This textbook provides the foundations needed to simulate the complexity of past human societies, offering researchers a richer understanding of the past—and likely future—of our species.

I Z A ROM A N OWS K A COLI N D. W R EN

SFI

S T E FA N I A . C R A B T R E E

PRESS

T H E S A N TA F E I N S T I T U T E P R E S S SCHOLARS SERIES