Implementing and Testing an Agent-Based Model

M. Drew LaMar
March 13, 2019

Class announcements

  • Raft Debate tomorrow!
    • March 14, Chesapeake ABC, 6:30 pm
    • We'll be going over after lab as a group if you are interested
    • Extra Credit for attending! One point on an exam.

The ODD Protocol - Learning Objectives

  • Be able to name the benefits of using a “Materials and Methods” protocol (e.g. ODD) for reporting and organizing the steps of agent-based model design and analysis.
    • Describing
    • Understanding
    • Replicating
    • Formulating

The ODD Protocol - Learning Objectives

  • Develop a firm understanding of the “Overview” and “Details” elements of ODD.

The ODD Protocol - Learning Objectives

  • Develop an introductory understanding of the “Design concepts” element of ODD.

The ODD Protocol - Learning Objectives

  • Understand, from its ODD description, the model we will program and use in chapters 4 and 5.

Butterfly Model ODD - Purpose

The model was designed to explore questions about virtual corridors. Under what conditions do the interactions of butterfly hilltopping behavior and landscape topography lead to the emergence of virtual corridors, that is, relatively narrow paths along which many butterflies move? How does variability in the butterflies’ tendency to move uphill affect the emergence of virtual corridors?

Question: What are the explanatory variables and processes and what is the system output we are interested in?

The ODD Protocol

ODD: Overview -> Process Overview and Scheduling
  • Observer measures: Quantify and record measure of system state.
    • Display system state in graphs.
    • Measure system state with statistical summaries.
  • Model interpretation and learning intimately tied to how you observe system!!!
  • Observer measures are to models as data are to experiments.

The ODD Protocol

Process Overview and Scheduling There is only one process in the model: movement of the butterflies. On each time step, each butterfly moves once. The order in which the butterflies execute this action is unimportant because there are no interactions among the butterflies.

The ODD Protocol

ODD: Design concepts
  • These are important aspects that must be addressed when creating agent-based models.
  • These concepts are specific to agent-based models. Other types of models would have different design concepts.
  • (Take a look at Chapter 3)

The ODD Protocol

ODD: Details
  • Initialization: Specify initial conditions for all state variables of all entities.
  • Input data: Time-dependent external forces that effect the system (e.g. weather).
  • Submodels: Details of submodels specified in the process overview. Will include equations, logical rules, and algorithms.

Chapter 4: Implementing an ABM - Learning Objectives

  • Be able to translate a model from its written description in ODD format into NetLogo code.
  • Be able to define global, turtle, and patch variables.
  • Become familiar with NetLogo's most important primitives, such as ask, set, let, create-turtles, ifelse, and one-of.
  • Start learning good programming practices, such as making very small changes and constantly checking them, and writing comments in your code.
  • Produce your own software for the Butterfly model described in chapter 3.

Implementing an ABM - Tips & Tricks

  • Program the overall structure of a model first, before starting any of the details.
  • Before adding each new element, conduct some basic tests of the existing code and save the file.
  • For the love of all things made of chocolate, indentation and organization is your friend!

NetLogo Brainteaser

Discuss: When you click the new setup button, why does NetLogo seem to color the patches in spots all over the View, instead of simply starting at the top and working down?

Answer: NetLogo always, by default, goes through turtles and patches in random order. This is an attempt to remove a possible confounding process - agent ordering. This is an example of asynchronous updating.

Code Commenting

This is the programmers “Do as I say and not as I do!” Think of commenting as taking notes in your learning.

“Comments are needed to make code easier for others to understand, but they are also very useful to ourselves: after a few days or weeks go by, you might not remember why you wrote some part of your program as you did instead of in some other way.”

Code Commenting - What do I comment?

  • Briefly describe each procedure (section) or nontrivial piece of code (paragraphs).
  • Explain meaning of variables (Pull from ODD if possible)
  • Document context of each procedure (specific to ABMs - turtle, patch?)
  • Label ending of procedures and sometimes if or ifelse statements (i.e. after closing using ] character)
  • Use ;----------- to separate procedures in long programs.
  • Comment pieces of code that are used for unit testing or temporary output.
    show (word elev1 " " elev2 " " elevation)

Code Commenting - Caveats

The point is to make your code readable and understandable, so some caveats:

  • There is such a thing as too much commenting - try and make your code unobfuscated (e.g. if there are multiple ways to accomplish something, choose the readable over the elegant and short)
  • Use tabs and blank lines to show code organization.