Week 6: Agent Based Modeling

Agent Based Modeling

You’ve now had a chance to explore some archaeological and historical networks. Network analysis is fantastic and there’s amazing research being done - you should check out The Connected Pasthttps://connectedpast.net/) for more. When I was doing my PhD, I managed to spin out an entire thesis by stitching together a series of network ‘snapshots’ by time period from a collection of stamped Roman bricks (the stamps are makers’ marks). Each brick contained information about different levels of economic complexity - warehouse, brick yard, brick maker, land owner, date - and my thesis told the evolving story of that region by figuring out the story between the moments captured by the networks.

Do you see the problem? Network analysis does not have much to say to explain how one network shape or another might evolve or emerge in the gaps, how snapshot_at_time_1 becomes what we see in snapshot_at_time_2.

These were the base strata of social relationships in the Tiber Valley around the power to control land. What I wanted was a way to reanimate those networks. What kind of society had these kinds of relationships? I would examine how they evolved, from different starting positions. What I wanted was a simulation.

What is a model?

“Essentially, all models are wrong, but some are useful” - George Box.

We build models when we are trying to understand something complex by focussing on the essential elements. A model is always a necessary generalization or simplification of the thing we are trying to study. Let’s say we’re interested in how birds flock together, how they all seem to ‘know’ where to go. In fact, when you zoom out a bit, it almost looks like the flock is a creature on its own, right? We might expect that flocking behaviour involves a lot of very complex decisions made by individual birds. And when we think about how we might represent this in a computer, it starts getting really complicated. Each bird, reacting to the other birds, making decisions, going this way rather than that… we might be tempted to say that some bird has to be the leader, right?

It turns out, you can specify three simple rules that when implemented by all the birds will give rise to the complexity of a murmuration:

  1. don’t get too close to another bird
  2. don’t stray away too far from another bird
  3. go along with wherever everyone else is going.

Three simple rules, implemented by a population of birds where every bird is different and has a different sense of what counts as ’too close’ and ’too far’ and ‘go more or less this way’, and voilà, a complex emergent phenomenon.

Agent based modeling therefore is a way of building a simulation that focusses on specifying individual rules of behaviour for heterogenous collections of agents (birds, humans, whatever). Each agent is represented in software as its own independent object that implements its rules depending on its local neighborhood - most agent models have an explicitly spatial arrangement (many archaeological ABM will run on top of the data from archaeological GIS, for example).

The Task

If I am interested in the impact of plague in an ancient society, I write a model that specifies how people interact, and how they individually react to plague - my rules can be informed directly from archaeological or historical evidence. I can design an environment for them to exist in that mimics something crucial about the past, like regional connectivity of cities. Or the daily rhythm of a marketplace. I then set up an experiment where I run the model, the simulation over and over again to account for probability, and I run it multiple times under various conditions. Perhaps I start with a world where individuals are too afraid to travel if they get sick, and I run the simulation. Then I turn the ‘fear’ dial down by one, and re-run. Eventually I finish where people simply don’t care about being sick. What I end up with is a visualization of the entire ’landscape’ of behaviours in this model. Then the task is to use what we’ve learned to refocus our attention on the actual historical evidence that we have. Where that evidence matches up with particular circumstances in the model we have learned something new!

I’m not trying to turn you in to an agent based modeller. Rather, I’m trying to equip you with enough literacy that you can engage with someone else’s published model and know if they’re pulling the wool over your eyes or not.

In our workbench this week, I walk you through some examples building progressively more complex models:

  • virus on a network (virus-on-a-network.ipynb)
  • a foraging society (abm-foraging.ipynb)
  • information diffusion on the Roman communications network (abm-on-roman-network.ipynb)

These three models illustrate powerful ways that our earlier focus on networks can be reanimated with real artificial intelligence. Swarm intelligence. Agents make decisions based on their interpretation of the rules in a given situation. What we as archaeologists examine afterwards are the emergent phenomena that result.

Explore those models. Read the code carefully to try to understand what is going on. It can be extremely helpful to diagram out how the code works:

look_for_neighbouring_birds
            if I_see_a_bird > my_neighbour_tolerance
                        adjust_heading 90_degrees
            if I_see_a_bird < my_lonely_factor
                        adjust_heading...
 

Document your exploration and your observations exploring my models in a note file in your workbench. Feel free to try to tweak the models to see how they behave, how they change, and what that might imply.

Then, think of an archaeological situation that we’ve encountered already in this class and sketch out using the kind of pseudo-code I used in the example above some rules that might model the phenomenon you’re interested in. Many archaeologists begin building models this way - sketching out linguistically what a model might do, what the agents might do and their characteristics, and the environment. Wikilink liberally to my examples as necessary.

{% admonition} Many archaeologists use the Netlogo language to design and run their models and experiments. The Netlogo platform and language depends on Java. Rather than give you another thing to download and install, my examples are written in a ‘port’ of the Netlogo language meant to work with the R programming language, since that is part of our workbench environment already. Another option that people use is the mesa package for Python. Neltogo is definitely the most accessible approach, since it is closest in syntax and logic to English. {%}

Go Further

I love agent modeling. If you wish to go further, I would strongly recommend that you download netlogo for yourself and explore its suite of example models. It’s a dedicated program and language for building agent models and there is a wonderful step-by-step book by Romanowska, Wren, and Crabtree available for free that will enable you to develop your own models from scratch. Alternatively, if you look at the example models, you can often find an existing model that could become the foundation for something archaeological easily enough. That’s how I developed some of my published work.

Prev