# Preface

# 1. What is this book about?

The objective of this book is to help you learn to *implement* and *analyze* evolutionary models of social interactions in finite populations. The following paragraphs explain why these two skills –i.e. model implementation and analysis– are key for scientific modeling.

## Model implementation

To use a scientific model rigorously, it is important to be fully aware of all the assumptions embedded in it, and also of the various alternative assumptions that could have been chosen. If we don’t understand all the details of a model, we run the risk of over-extrapolating its scope and of drawing unsound conclusions. A great way to understand a model in depth is to *implement* it in computer code following an agent-based approach. We believe this is true regardless of whether the model is currently expressed in natural language (and may even exist only in your mind) or, alternatively, it is written down in mathematical language (e.g. using equations).

Coding a model expressed in natural language is very useful because it ensures that the model is both consistent and completely specified. A computer implementation of a model is necessarily *consistent* because the language used to code it (i.e. the programming language) is formal, so it does not allow ambiguities to infiltrate; symbols and instructions used in programming languages have always the same meaning regardless of context. A computer implementation of a model must also be *completely specified* before it can be run, since computers do not make assumptions by themselves. Thus, to execute a model in a computer, there cannot be any loose ends in the description of the model. This contrasts with models expressed in natural language, where it is easy to leave aspects of the model partially unspecified –often unintentionally–, since our brains are particularly good at using context to unconsciously fill the details. This implies that the audience may be understanding something slightly different from what is meant to be communicated, and results may be driven by assumptions that are not made explicitly. By contrast, computers need all assumptions to be spelt out, and this requirement makes the process of scientific modelling more sound and rigorous.

If a model is written in the language of mathematics, the problems outlined in the paragraph above are no longer an issue. Thus, is it really worth implementing a mathematical model in computer code following an agent-based approach? We believe that, in many cases, it certainly is. The reason is that many mathematical models contain assumptions that are desirable for analytical tractability, but which also weaken the link between the model and the real world. These assumptions made for analytical convenience tend to elevate the mathematical model to a higher level of abstraction and aggregation. By contrast, the agent-based approach has the advantage of forcing the programmer to implement the microfoundations of a model explicitly, considering each individual agent as a separate entity. This requirement helps the modeler be aware of all the assumptions that are made in the mathematical model, and it also allows for an assessment of their significance.

## Model analysis

Once the model is implemented, the way to fully understand it is to *analyze* it. In this book, we will see several techniques that are useful to analyze finite-population evolutionary models, including Markov chain analyses, Monte Carlo simulations, mean dynamics, stochastic stability analyses and diffusion approximations. For each of these techniques, we give a brief introduction, illustrate its usefulness with concrete examples, and provide references for the interested reader to learn more about it.

# 2. How to use this book

This book has been written and formatted following a hands-on approach. To make the most of it, we encourage you to have NetLogo open, and to code the models as you read the book. We are hopeful and confident that if you go through the whole text, implement the proposed models, and try to do some of the exercises included at the end of most sections, you will master the art of implementing and analyzing agent-based evolutionary dynamics.

Nonetheless, we also have in mind two other types of less committed readers:

- If you are interested in learning to analyze finite-population evolutionary models, and in their relation with other models in Evolutionary Game Theory, but
**you do not wish to program**, then you should skip all the sections preceded by the label^{ CODE }. - If you want to become proficient in coding agent-based models, but
**you are not interested in learning how to analyze these models**, please do reconsider your preference. If your preference persists after careful reflection, you may want to skip the section titled “Analysis of these models”, which you will find at the end of most chapters.

Our hope is that, regardless of the discipline you are coming from, your background and your preferences, this book will help you learn new and exciting ways of understanding evolutionary systems.