Dark theme

Data variables


During the course's practicals we are going to build up a simple agent-based model (ABM). The model will demonstrate the key themes you are likely to come across is building such a model, but will also provide more general code for dealing with spatial, and other, data. ABMs are probably the most popular modelling techniques in the social and ecological sciences.

What is an Agent-Based Model?

For over 3000 years, we've had to aggregate individual things in order to understand their mass behaviour. Mathematics, and more specifically statistics, developed because we're unable to cope with hundreds of objects or people as individuals in our heads. However, the rise of high-powered computers and large disk space means we can now start to build models that don't aggregate, but that keep individuals as individuals: so called "individual level models".

This has several advantages, for example, we can keep track of individual entities' history for the purposes of analysis or adapting how they act. One significant advantage is we can give individual objects "agency" -- we can give them individual behaviour and the ability to interact with each other and their environment. This allows us to build an Agent-Based Model (ABM), i.e. one in which our individuals have agency.

The rise of Object-Orientated Programming, where code can be segregated into specific 'objects' to do jobs, has simultaneously created a platform for ABMs, with types of individual being represented types (classes) of object, and individuals being built as objects.

ABMs are generally iterative models. They run by allowing the agents to do their thing for a time step repeatedly (for example, representing someone doing a day's activities) until some number of time steps (iterations) have run, or some stopping condition has been reached. System-level patterns emerge from the complex interactions of the multiple, relatively simple, behaviours of the agents in the model.

The key code elements of a basic ABM are:

Model code, which deals with interacting with the user and sets up the model, including running the model iterations and checking the stopping conditions.

Agent code, which is used to build agents that can include the agent's behaviour and any records of their state. The behaviours can be rule based, mathematical, or statistical. Agents will often have behaviours based around what is happening in a limited neighbourhood around them. Each agent will often contain an list of all the other agents so agents can communicate with each other.

Environment code which represents the "world" that agents may interact with. This may contain data as well as constraint the space and topology the agents can exist within. It could be anything from a network to an abstract information-brokering system, but often in social and environmental science it contains a 'raster' grid of data.

In building an ABM, then, we cover broader coding concepts of use across science, including:

  • structuring code;
  • utilising rules and maths;
  • getting code to interact with other code;
  • interacting with users;
  • reading and writing data.

So, let's move on to look at what we're going to build.


  1. This page
  2. Components of a model <-- next
  3. Capturing a position in space
  4. Moving y and x
  5. Distance between two points
  6. Final ideas