-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintro-abm.qmd
More file actions
236 lines (142 loc) · 25.4 KB
/
Copy pathintro-abm.qmd
File metadata and controls
236 lines (142 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Introduction to ABM {#intro-abm}
Agent-based modelling (ABM) is a powerful tool for studying complexity by creating dynamic simulations using formal definitions, rules, and populations, resulting in the study of emergent properties in social and ecological systems. By adopting a bottom-up perspective, it allows for a deeper understanding of the processes that shape real-world phenomena.
To better contextualise ABM, we start by positioning this modelling approach in relation to other modelling approaches. We then describe ABM's central concepts, including what makes it often more intuitive and adequate for representing certain types of phenomena, particularly social interactions, yet paradoxically being more complex and unpredictable than other simulation models.
## A teaser: Schelling's segregation model
<a href="https://ncase.me/polygons" target="_blank">
<img src="assets/images/ncase-shelling.PNG" alt="ncase-shelling" style="width: 450px; border: none; box-shadow: none; vertical-align:super">
</a>
<a href="http://ccl.northwestern.edu/netlogo/models/Segregation" target="_blank">
<img src="assets/images/Segregation Simple interface.png" alt="shelling-netlogo" style="width: 350px; border: none; box-shadow: none">
</a>
## ABM as a tool for complexity
Agent-based modelling (ABM) is a tool that can be used to explore phenomena through the lens of complexity science, that is as manifestations of complex systems. [Complex systems](https://en.wikipedia.org/wiki/Complex_system) are characterized by a high number and diversity of causal relationships, non-linearity (feedback loops), self-organization, self-similarity, and path dependence. [Complex adaptive systems](https://en.wikipedia.org/wiki/Complex_adaptive_system) are a special case of complex systems, one that is considered able to adapt to (and learn from) its environment. Such systems are better understood through its smaller parts and their interaction.
<a title="Acadac, Public domain, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Complex-adaptive-system.jpg"><img width="512" alt="Complex-adaptive-system" src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Complex-adaptive-system.jpg/512px-Complex-adaptive-system.jpg?20050529073219"></a>
ABM is a methodological framework that allows researchers to simulate the dynamics of complex systems. The approach involves:
* **Formalizing definitions** of elements within the system.
* Defining **rules as algorithms** to govern interactions between elements.
* Simulating a **population as distributed processes**.
* Creating a **bottom-up approach to modelling** to study emergent properties.
* Incorporating **stochasticity** to generate probabilistic results.
<a title="derivative work: George (talk)
Conways_game_of_life_breeder.png: Hyperdeath, CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Conways_game_of_life_breeder_animation.gif">Game of Life - breeder<br><img alt="Conways game of life breeder animation" src="https://upload.wikimedia.org/wikipedia/commons/e/e6/Conways_game_of_life_breeder_animation.gif?20140304220345"></a>
<a href="https://link.medium.com/1uqbZW0M2T" target="_blank"><img src="https://cdn-images-1.medium.com/max/1600/1*yrVzKSeqaA1O3G3HF-AHlw.gif" width="512px">
<br>Flocking behaviour in 'Behavioral systems' by Danil Nagy in 'Generative Design', medium.com</a>
ABM is a type of simulation that is particularly useful for modelling social systems because it allows for the representation of human agency and interaction. In ABM, a phenomenon is modelled through populations of autonomous agents and their interactions. This approach contrasts with other modelling techniques that represent causal components as aggregated variables and parameters. The use of distributed computation allows for the generation of complex dynamics that are not reducible to analytical solutions. ABM is also useful for exploring the emergence of social patterns and structures from the bottom up.
ABM is a modular approach that can integrate parts from other modelling approaches, allowing for a more comprehensive representation of complex systems. For example, ABM can integrate environmental and spatial aspects, the agency of individuals and institutions, group formation, cooperation and competition, cognitive processes, and communication. In archaeology and other disciplines such as geography and environmental sciences, this multi-paradigm approach has been favoured. The approach aligns well with the study of socio-ecological systems (SES) which acknowledges the interrelationships between natural and artificial worlds.
## ABM as mathematical models
Agent-based models, like all simulation models, are a type of mathematical model. As the term is used in science, we can define models as **representations** of a system or a phenomenon through its essential characteristics, often involving elements, relationships, and underlying assumptions. Mathematical models are simply more advanced in their logical definition through the process of **formalisation**. The *informal* or *less formal* models are those that are defined only through natural language speech (*e.g.*, in a live discussion), text (*e.g.*, in an article or book), or through certain graphical pieces (*e.g.*, infographics, diagrams).
Despite this distinction, there is no genuine opposition between models with different levels of formalisation. Mathematical formalisation is mainly used to implement and test the logic models stated less formally. Among the advantages of mathematical formalisation, the most important are **univocity** (i.e., things have a single definition) and **commensurability** (i.e. things can be measured or counted). These properties set formal models apart from models formulated purely with natural languages, among other things, allowing for a significant improvement in the robustness of our reasoning. Keep in mind, though: formalisation can also harm the intelligibility of our models, *because* they move away from natural languages.
Within the large family of mathematical models, ABM models lie typically within a category that can be characterised as *explicative* or *mechanistic*. Explicative models are focused on an explanation, expressing processes through realistic causal relationships between variables, often including assumptions. Non-explicative or *descriptive* mathematical models are used more strictly to describe, reproduce or extrapolate the relationship between variables (i.e., most statistical models). The latter models are about *patterns* or *trends* in data, while the former are about the *mechanisms* underlying data, at least as we can define them based on our current understanding of the phenomena's domain. Unlike descriptive models, explanatory models seek to explain *why* a phenomenon occurs by formalizing mechanisms through causal relationships.
<img src="https://github.com/Andros-Spica/modelling-simulation-graphs/blob/main/from-model-to-simulation-models/from-model-to-simulation-models_p1.png?raw=true" alt="models to math models"
style="width: 550px; border: none; box-shadow: none; margin-bottom: 0%; background-color: azure;"/>
The line between these categories is blurred and confounded by many models and model users. Notice, for example, that the very term "explanation" is widely used in non-mechanistic ways (*e.g.*, when it is said that the educational level of a person *explains* that person's income). However, the bulk of models on each side is considerable, and ABM models, in particular, have traits that are undeniably linked to the formulation of *mechanisms*.
To help understand this distinction, we can think about one of the most simple and popular descriptive models used today: the linear regression model.
<a title="Krishnavedala, CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Linear_least_squares_example2.svg"><img width="256" alt="Linear least squares example2" src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Linear_least_squares_example2.svg/256px-Linear_least_squares_example2.svg.png?20110610033522"></a>
We use this regression models to summarise the relationship between two variables in a dataset by finding a line that best fit the point distribution. In the case of the simple linear regression, we define a parametric equation that corresponds to a straight line in an Cartesian two-dimensional space:
>y = a + b·x

*Geometric representation of a linear regression model*
A linear regression model has two variables, x and y, which define two orthogonal dimensions, and two parameters, a and b, which determine the value of y when x = 0 and the tangent of the angle formed by the line with the x dimension. These are "meaningless" (semantically empty) in the model design, even if we deliberately choose x as the "independent" variable, despite how they are interpreted at a higher level of analysis.
The semantic emptiness of descriptive models might seem irrelevant at first. A linear regression does help us to understand data and can make effective predictions. However, the meaning of these understandings and predictions comes from our explanatory models, which are only loosely connected to the equation we use. Assuming descriptive model and interpretation are directly connected can lead to misrepresenting data, or, worse, lead to faulty reasoning about the underlying phenomenon.
<a title="Anscombe.svg: Schutz
(label using subscripts): Avenue, CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Anscombe%27s_quartet_3.svg"><img width="512" alt="Anscombe's quartet 3" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Anscombe%27s_quartet_3.svg/512px-Anscombe%27s_quartet_3.svg.png?20100326171813"></a>
To put an archaeological example, imagine we have two variables measured in a collection of sites, the estimated maximum area and the count of potsherds on the surface. Imagine that we can define a regression model that states a positive correlation exists between them. Assuming our dataset is large enough and not radically biased, we could probably interpret that built area *influences* (i.e., causes, in a weak sense) the abundance of potsherds on the surface. It would not be necessarily illogical to conclude this. Yet, the relationship described in the model is ultimately a correlation (no archaeologist would think that one is directly causing the other).
::: {.callout-note}
::: {.grid}
::: {.g-col-6}
Target reality:
<a title="Santeri Viinamäki, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Green_watering_can.jpg">
<img width="256" alt="Green watering can" src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Green_watering_can.jpg/512px-Green_watering_can.jpg" style="border: none; box-shadow: none;"></a>
:::
::: {.g-col-6}
Observations:
<img width="256" alt="Picture maze solving -observations"
src="assets/images/Picture_maze_solving_observations.png"
style="border: none; box-shadow: none; margin-bottom: -2%;">
:::
::: {.g-col-6}
Descriptive model:
<img width="256" alt="Picture maze solving - descriptive model"
src="assets/images/Picture_maze_solving_descrip-model.png"
style="border: none; box-shadow: none; margin-bottom: -2%;">
A model that return the output given the input
:::
::: {.g-col-6}
Explanatory model:
<a title="Original: User:Icey, Animation: User:MichaelFrey, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Picture_maze_solving.gif">
<img width="256" alt="Picture maze solving - explanatory model"
src="https://upload.wikimedia.org/wikipedia/commons/b/b2/Picture_maze_solving.gif" style="border: none; box-shadow: none; margin-bottom: -2%;"></a>
A model that returns the output given the input **and the definition of a mechanism**
:::
:::
:::
<img src="https://github.com/Andros-Spica/modelling-simulation-graphs/blob/main/from-model-to-simulation-models/from-model-to-simulation-models_p2.png?raw=true" alt="types of math models" class="fragment" style="width: 550px; border: none; box-shadow: none; margin-bottom: 0%; background-color: azure;"/>
The trend expressed by the linear model is but a "hint" of the mechanisms that are or could be postulated to explain it. Any hypotheses about the reason behind the correlation must be formulated outside the model, before or after its creation, for instance, by combining it with a natural language model. Thus, a descriptive model is inherently incomplete as an analytic tool and remains trivial unless it is associated with an external explicative model, formal or informal.
Still, descriptive mathematical models have been proven to be very useful and are widely adopted. Consider that in the field of artificial intelligence, the success of the descriptive models encompassed by *machine learning* have pushed aside other modelling approaches that uses programmed or procedural rules, from which ABM has branched. Within the exploration of data-driven methods, some scholars have even started to question the concept of "explanation" itself, posing that it might be a well-hidden fallacy of human cognition. On the other hand, it is still debatable how much *human* understanding can come from descriptive models alone.
## ABM as simulation models
>"a situation in which a particular set of conditions is created artificially in order to study or experience something that could exist in reality." [Oxford Advanced American Dictionary](https://www.oxfordlearnersdictionaries.com/definition/american_english/simulation)
>"**a**: the imitative representation of the functioning of one system or process by means of the functioning of another a computer simulation of an industrial process
>**b**: examination of a problem often not subject to direct experimentation by means of a simulating device"
>*simulation*, [Merrian-Webster](https://www.merriam-webster.com/dictionary/simulation)
>"A simulation is an **imitative representation of a process or system** that could exist in the real world. In this broad sense, simulation can often be used interchangeably with model. Sometimes a clear distinction between the two terms is made, in which simulations require the use of models; the model represents the **key characteristics or behaviors** of the selected system or process, whereas the simulation represents the **evolution of the model over time**. Another way to distinguish between the terms is to define simulation as experimentation with the help of a model."
>*Simulation*, [Wikipedia](https://en.wikipedia.org/wiki/Simulation)
### Algorithmic process
Simulation is a numerical approach to solve mathematical models. Simulation models are mathematical models that describe a mechanism and when iterated or repeated can represent a process, i.e. change through time *caused* by the mechanism. They are particularly useful for studying complex systems with non-linear relationships and feedback loops, and can help to generate data that can be used to test the validity of the model. There is a large variety of approaches in simulation; however, they all share this fundamental intent of representation of a process.
::: {.callout-note}
::: {.grid}
::: {.g-col-6}
**Fruit-in-the-basket simulation model**
*entities*: basket, fruits, us (*basket-fillers*).
*mechanism*: a basket can contain $N$ fruits (fruit-basket relationship), we can add fruits to the basket (us-fruit and us-basket relationships).
*simulation step*: if the basket is not full, we add $X$ fruits or less to the basket.
*process or dynamics*: an empty basket will get full with $N$ fruits after $T$ steps have passed, where $T={ceiling}(N/X)$.
*explanatory* meaning: Why the basket has $N$ fruits? *Because* (a) it can only hold $N$ fruits, and (b) we have added $X$ fruits $T$ times.
:::
::: {.g-col-6}

:::
:::
:::
 ](assets/images/Gale-Shapley-algorithm.png)
### Distributed processes
Social simulation models, specifically, apply these methods to social science topics, emphasizing the role of human agency and distributed computation. Agent-based modelling (ABM) is a common technique in social simulation, representing a phenomenon through populations of autonomous agents and their interactions.
<a href="http://jasss.soc.surrey.ac.uk/12/1/1.html" target="_blank"><img src="http://jasss.soc.surrey.ac.uk/12/1/1/fig1.jpg" alt="Galan et al. 2009" style="width: 450px; border: none; box-shadow: none"><br>Galan et al. 2009</a>
<a href="https://www.gisagents.org/2016/10/agent-based-modeling-in-geographical.html" target="_blank"><img src="https://3.bp.blogspot.com/-8dBibQOLxv4/V4-Kd1QmFGI/AAAAAAAAJxU/XyvLVDVfzMEDLyRDdh1Sc3z_Nq7z2xPDQCLcB/s640/Figure1.png" alt="Heppenstall and Crooks 2016" style="width: 450px; border: none; box-shadow: none"><br>Heppenstall and Crooks 2016</a>
<a href="http://jasss.soc.surrey.ac.uk/14/3/7.html" target="_blank"><img src="http://jasss.soc.surrey.ac.uk/14/3/7/rebaudo_et_al_figure1_600px.png" alt="Rebaudo et al. 2011" style="width: 450px; border: none; box-shadow: none"><br>Rebaudo et al. 2011</a>
In contrast with other mechanistic and dynamic mathematical modelling approaches, ABM seeks to represent a phenomenon by explicitly modelling its parts. Therefore, ABM involves the expectation that the phenomenon at the macro-level *emerges* (can be deduced) from the dynamics at the micro-level. Moreover, ABM implies that the parts, the agents, constitute 'populations', *i.e.*, they share common properties and behavioural rules. The 'agency' behind the term 'agent' also implies that these parts have certain autonomy with respect to each other and the environment, which justifies simulating their behaviour at an individual level.
In practice, 'autonomy' often translates as the agents' ability to take action, move, decide, or even think and remember. Decision-making is a central aspect of agents and most agent designs can be sufficiently expressed as flowcharts. Nevertheless, agent-based models also include entities that are *technically* agents (on the terms of [multi-agent systems](https://en.wikipedia.org/wiki/Multi-agent_system)), but lack many of such abilities or are not considered real/material discrete entities. The most common case is to represent space sectors as agents fixed to unique positions in a grid to facilitate the implementation of distributed spatial processes (*e.g.*, the growth of vegetation dependent on local factors). This type of agent is more commonly named as "cellular automaton" (*cellular automata*, in plural), In NetLogo, these entities are predefined as `patches` and are extensively used in combination with mobile agents in models in ecology and geography.
### Stochasticity
An important and distinctive aspect of agent-based models is that they are unavoidably *stochastic*, i.e., at least some processes are fed by random sequences. By definition, the order in which agents of a type perform their processes should not be predefined and, overall, should not be the same followed every iteration of the model. Thus, the only unbiased way of *scheduling* processes in ABM is to randomize all distributed sequences. This is (usually) not the case in models based on differential/difference equations, where the equations calculating variables are solved following a particular fixed order.
Methodologically, introducing randomness is a way of accounting for the entire spectrum of possibilities, whenever a certain aspect of the model is undertheorised or cannot be controlled in real scenarios. More importantly, it is justified whenever the modeller believes that the intended behaviour is independent of a specific value or order.
For those with no previous experience with computer science: note that "random" for a computer is not like "rolling dices". We are getting values of a preordered sequence presumably unrelated to the process at hand. The programs creating these sequences are called [pseudorandom number generator](https://en.wikipedia.org/wiki/Pseudorandom_number_generator) or RNG, for short. Sequences will be different every time we run our program (*i.e.*, simulation), unless we preset the RNG using a specific 'seed', an integer often spanning a massive range of positive and negative numbers. Setting a particular RNG seed is, in fact, good practice, and helps enforce the reproducibility of simulation results.
This technique is also helpful in creating variation within a population of agents or between the global conditions of simulation runs. Such a thing is accomplished by drawing the values of variables from probability distributions, defined through *hyperparameters* (*e.g.*, drawing the age of individuals in a classroom from a normal distribution defined by two parameters, `age_mean` and `age_standardDeviation`). Unfortunately, a typical bad practice is not exposing such hyperparameters, having these 'hard-coded' as if their value were an intrinsic part of the model and thus the mechanisms it represents. This bad coding element, often called "magic numbers", can and should be addressed during model implementation.
### A point of comparison: Lotka-VolterraPredator-prey model
Compared to other modelling and simulation approaches, ABM is more intuitive but also more complex.
For example, the [Lotka-Volterra predator-prey model](https://en.wikipedia.org/wiki/Lotka%E2%80%93Volterra_equations) in ecology is a pair of differential equations that are relatively simple and conceptually straightforward.
$$
\frac{dx}{dt}=\alpha x-\beta xy
$$
$$
\frac{dy}{dt}=\gamma y+\delta xy
$$
where $x$ and $y$ are the population density of prey and predator, respectively. $\alpha$ and $\gamma$ are the maximum intrinsic growth rate of each population and $\beta$ and $\delta$ are the effect of the presence of predators on prey and of prey on predators. Note that the first effect is negative and the second is positive.
This simple model has became very famous for being able to express the following dynamics:
>assumption: prey population grows based on unspecified resources (*intrinsic growth rate*)
>more prey → more food for predators, so more predators will survive and reproduce
>more predators → more prey will be killed, so less prey will survive and reproduce
>less prey → less food for predators, so fewer predators will survive and reproduce
>fewer predators → less prey will be killed, so more prey will survive and reproduce
>more prey → more food ... (the cycle begins again)
<p style="text-align: center;">
<a title="AspidistraK, CC BY-SA 4.0 <https://creativecommons.org/licenses/by-sa/4.0>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Lotka_Volterra_dynamics.svg"><img width="400" style="background-color: white" alt="Lotka Volterra dynamics" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Lotka_Volterra_dynamics.svg/512px-Lotka_Volterra_dynamics.svg.png"></a>
<br>
<i style="color: grey;">Example of Lotka Volterra dynamics</i>
</p>
The same model can also be implemented with ABM (see the comparison in [NetLogo's Model Library Wolf-Sheep Predation (Docked Hybrid)](http://ccl.northwestern.edu/netlogo/models/WolfSheepPredation(DockedHybrid))). The ABM implementation requires many additional specifications on how predator and prey agents should behave individually. Even though it is not strictly necessary to represent the core mechanism, ABM variations of the Lotka-Volterra model often aim to include more complexity. In the case of the Wolf-Sheep model mentioned, there is an explicit account of the base resource (*i.e.*, the prey of the prey), named `grass`, which is implemented as a property of spatial units. These additional specifications normally help the model be more intuitive and realistic but also significantly complicate the model design and implementation, even though generating similar aggregate dynamics as the equation-based version (*i.e.*, oscillation harmony between prey and predator populations).
<p style="text-align: center;">
<a title="SethTisue, GPL <http://www.gnu.org/licenses/gpl.html>, via Wikimedia Commons" href="https://commons.wikimedia.org/wiki/File:Netlogo-ui.png"><img width="512" alt="Netlogo-ui" style="width: 450px; height: 350px; object-fit: cover; object-position: 0% 0%;" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Netlogo-ui.png/512px-Netlogo-ui.png"></a>
<br>
<i style="color: grey;">NetLogo user interface running the Wolf-Sheep Predation model</i>
</p>
## ABM? It's probably multiparadigm modelling
Last, another significant advantage of ABM is that it can include parts (algorithms, submodels) that belong to other modelling approaches. For example, we can quickly devise a model where a population of agents runs in parallel with a full-fledged Dynamic Systems model through a set of difference equations. Commonly, ABM models are ensembles created with parts that technically are not ABM. This is why some ABM modellers and modelling platforms use terms like "multiparadigm modelling" or "hybrid modelling", which is more precise for many cases. Unfortunately, these were not adopted more widely and "agent-based modelling" continues to be the most common term, particularly in archaeology.