[AGENT-BASED MODELING FOR ARCHAEOLOGY] Simulating the Complexity of Societies
IZA ROMANOWSKA COLIN D. WREN STEFANI A. CRABTREE
PLEASE NOTE:
The contents of this open-access PDF are excerpted
Copyright By PowCoder代写 加微信 powcoder
from the following textbook, which is licensed under
a Creative Commons Attribution-ShareAlike 4.0 —AGATHA CHRISTIE, DEATH ON THE NILE (1937)
International License: Romanowska, I., C. D. -Based Modeling for Archaeology: Simulating the
and traps, references, and algorithms to use ABM in their own work. They will Complexity of Societies. Santalso find engaging examples of how other scholars have applied ABM, ranging from the study of the intercontinental migration pathways of early hominins, to the
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.
TO FULLY UNDERSTAND NOT ONLY THE PAST, but also the trajectories, of human societies, we need a more dynamic view of human social systems. Agent- based 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
humanities, and other social sciences, this book offers novices and more experienced ABM researchers a modular approach to learning ABM and using it effectively.
Readers will find the necessary background, discussion of modeling techniques
a Fe, NM: SFI Press.
This and other components, as well as a complete electronic copy of the book, can be freely downloaded at ARCHAEOLOGY
https://santafeinstitute.github.io/ABMA
REGARDING COLOR:
The color figures in this open-access version of Agent-Based Modeling for Archaeology have been adapted to improve the accessibility of the book for readers with different types of color- blindness. This often results in more complex color-related aspects of the code than are out-
PRESS THE SANTA FE INSTITUTE PRESS
AGENT-BASED MODELING FOR
Romanowska
lined within the code blocks of the chapters. As such, the colors that appear on your screen will differ from those of our included figures. See the “Making Colorblind-Friendly ABMs” section of the Appendix to learn more about improving model accessibility.
SCHOLARS SERIES
cles of the
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.
THE SANTA FE INSTITUTE PRESS 1399 Road, Santa Fe, 87501 |
THE FOUNDATIONAL STEPS OF BUILDING AN AGENT-BASED MODEL
1.0 Introduction
In this and the subsequent two chapters, we will use examples of simula- tions 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
• explaintheepistemologicalpositionofABMinscientificpracticeand
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 archaeo- logical inquiry. You will also be able to build a basic simulation and un- derstand 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 the- oretical explanation. In our experience, our students gain a much better understanding of the concepts related to simulation and complexity sci- ence 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 as- pect 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
▷ 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
PART I: LEARNING TO WALK
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 dis- persal. 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 com- parison with other modeling techniques. To illustrate the process of devel- oping 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 de- fine 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
In their 1995 paper, Young and Bettinger (Y &B henceforth) used a simple diffusion model to investigate the out-of-Africa dispersal of modern hu- mans (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 direc- tions from the point of origin (East Africa) following a gradient, from more densely inhabited areas to those that are less populous. In a mechanism sim- ilar 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 inhab- ited earlier than those farther away from it. However, the archaeological
You can find a detailed description of the Fisher-Skellam-KPP model in chapter 4.
data indicate that humans arrived in some areas (e.g., Europe) later than in others (e.g., Southeast Asia) irrespective of their geographical proxim- ity. 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 semitrop- ical 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 initializa- tion phase, where you define the world and its inhabitants, effectively set- ting up the state of the world at time step zero. Let’s write out our model’s setup in pseudocode:
algorithm: a sequence of instructions given to a computer.
pseudocode: a simplified notation of the structure of the code.
PSEUDOCODE BLOCK 1.0
Chapter 1: Building an Agent-Based Model
Set parameters [ population-growth = popG
initial-pop-size = n
initial-location = (x,y) ]
PART I: LEARNING TO WALK
PSEUDOCODE BLOCK 1.0 (cont.)
PSEUDOCODE BLOCK 1.1
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:
Create n agents
For each agent, A,
Place A in (x, y)
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 proba- bilistically. 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 ran- dom 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 neigh- borhood that can be colonized. Read carefully through the pseudocode, en- suring that you understand all abbreviations and can point out where they are defined. You have probably noticed that the pseudocode above is a sim- plified 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).
Figure 1.0. Main elements of NetLogo’s graphical user INTERFACE tab.
NETLOGO INTERFACE
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 preva- lent among social and life scientists (Hauke, Lorscheid, and Meyer 2017) and is by far the most popular agent-based modeling framework among ar- chaeologists (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 particu- larly 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:
• The VIEW panel for watching the simulation;
This heritage is why NetLogo refers to agents as turtles and to grid cells as patches.
Chapter 1: Building an Agent-Based Model
PART I: LEARNING TO WALK
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.
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
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 proce- dure, we will create the starting population of agents and build their envi- ronment. 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 any- where 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
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 re- porters. Commands define the actions of an agent, while reporters calcu- late 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 user- defined procedures and built-in ones called primitives. The NetLogo Dic- tionary 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:
A procedure consists of all code enclosed between
to and end .
primitive: built-in procedure or variable name.
To check a primitive’s documentation, move your cursor so that it is within the word and press F1.
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.
Chapter 1: Building an Agent-Based Model
to setup end
to go tick
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 proce- dure. This procedure usually starts with the clear-all primitive, which
4 https://ccl.northwestern.edu/netlogo/docs/dictionary.html
PART I: LEARNING TO WALK
You can play with the setup in the ch1_patches model in the ABMA Code
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.
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 re- ferred 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 program- ming 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
Repo. 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:
create-turtles 20 [
setxy random 5 random 5
reset-ticks
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 customize them, as in this example:
CODE BLOCK 1.3
random 5 chooses one value at random among 0, 1, 2, 3, and 4.
You can check the documentation of
create-turtles in the NetLogo Dictionary.
CODE BLOCK 1.4 TEST
Brackets are square [...] , parentheses are round (...) , and curly
brackets are . . . curly {...} .
Chapter 1: Building an Agent-Based Model
create-turtles 20 [
set color random 140
set size 2
set shape "turtle"
setxy random 5 random 5
reset-ticks
When you’re done, hit the CHECK button to make sure there are no er- rors 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 SET- TINGS 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.
can be moved to any one of t
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com