W0: What are Models?

CS300b – Agent Modeling

Eric Araújo

Boids Model

Boids Model

  • Created by Craig Reynolds, a computer scientist working on motion picture graphics in the mid-1980s
  • He tried to code the path of each individual bird, which showed impossible to be done
  • The amount of thinking from the birds is independent to the number of birds in the flock
  • Each bird has a simple heuristics in order to stay together with the other birds nearby

Boids Model

Reynolds came up with the three rules that describe the decision-making mechanism of each bird (or boid) within the flock:

  • Separation: If there are other boids immediately in front of you, turn away from them to avoid collisions and crowding.
  • Alignment: Turn to align with the average heading of nearby boids.
  • Cohesion: Attempt to stay close to nearby flockmates by steering toward the average position of neaby boids.

Boids Model

Boids is an example of an Agent-based Model.

  • Individuals are represented as computational entities (agents)
  • Agents behave and interact locally

What is a Model?

  • A simplified representation of a real-world phenomenon.
  • Scientific models help us understand, explain, and predict.
  • Not just about fashion! 😉

What is a model?

[…] a model is an abstract or physical structure that can potentially represent a real-world phenomenon.

Why model?

Formal models offer advantages over verbal descriptions:

  • Precise communication: Reduce ambiguity inherent in language.
  • Hypothesis generation: Reveal unexpected consequences of assumptions.
  • Counterfactual exploration: Simulate “what if” scenarios.

Why model?

“All models are wrong, but some are useful.”

Box, George E. P.; Norman R. Draper (1987). Empirical Model-Building and Response Surfaces, p. 424, Wiley. ISBN 0471810339.

Why model?

“[…] the apparent stupidity of a model can be a strength. By focusing only on some key aspects of a real-world system (i.e.,those aspects instantiated in the model), we can investigate how such a system would work if, in principle, we really could ignore everything we are ignoring.”

Paul Smaldino (page 8)

Decomposition

  • What are the parts of the system we are interested in?
  • What are their properties?
  • What are the relationships between the parts and their properties?
  • How do those properties and relationships change?

Decomposition

  • Breaking down a system into essential parts, properties, and relationships.
  • Driven by the research question: What do we want to understand?
  • Different decompositions yield different models.
  • No one “right” way: Choose the level of detail that suits your needs.

Types of Models

Equation-Based Models

  • Describe system dynamics using mathematical equations.
  • Often used for systems with well-defined relationships.

Agent-Based Models (ABMs):

  • Simulate individual entities (“agents”) and their interactions.
  • Capture emergent patterns from complex behaviors.

Fine-Grained vs. Coarse-Grained Models

Fine-grained models:

  • High level of detail, aiming for accurate predictions.
  • Can be complex and computationally demanding.

Coarse-grained models:

  • Simplified representations, focusing on key mechanisms.
  • Prioritize understanding over precise prediction.

Fine-Grained vs. Coarse-Grained Models

Choose the level of detail appropriate for your research question.

  • Fine-grained means that there are data in the world that can be used to precisely parameterize and test the models.
  • Coarse-grained models focus on broad, qualitative patterns in the data, not on reproducing exact measurements.

The Modeling Journey

  • Models are tools for thinking: They help us refine our ideas, test our assumptions, and explore possibilities.
  • “Doing violence to reality” allows for insight: Simplification can reveal essential mechanisms.

SIR Model

Equation-based Models

Advantages

  • Precision
  • Elegance

Disadvantages

  • Ability to handle heterogeneity
  • Explainability

SIR - Equation-based

\[ \frac{dS}{dt} = -\beta SI\] \[ \frac{dI}{dt} = \beta SI - \gamma I\] \[ \frac{dR}{dt} = \gamma I\]

SIR - Equation-based

\[ S(t+1) = S(t) - \beta S(t)I(t)\] \[ I(t+1) = I(t) + \beta S(t)I(t) - \gamma I(t)\] \[ R(t+1) = R(t) + \gamma I(t)\]

SIR

Preview

SIR - Agent-based Model

  • agents are situated on a two-dimensional surface and move around using a random walk
  • reduction of social contact flattens the curve

Netlogo Basics

Netlogo basics

Extracted from the book Modeling Social Behavior, by Paul E. Smaldino

Patches

  • spatial organization
  • discrete square cells laid out in two-dimensional retangular grid
  • can be used as agents themselves
  • used to represent properties of the agent’s environment

Turtles

  • spatially embodied
  • have a position in continuous space and a directional heading

Turtles history

  • Neuroscientist and roboticis W. Grey Walker created a simple, programmable, mobile robot in the 1950s called tortoise
  • Inspired the creators of Logo, developed in the 1960s. Logo permits to issue commands to move and draw with a small triangular figure on a computer monitor

Turtles history

Extracted from the book Modeling Social Behavior, by Paul E. Smaldino

Netlogo Tabs

  • Interface
    • Create, delete and manipulate controllers
    • Inspect the model’s output and parameter manipulation
    • Settings of the patch grid

Netlogo Tabs

  • Info
    • Description of the model
    • Documentation

Netlogo Tabs

  • Code
    • Instructions for the model’s operation
    • The code for Netlogo is everything, not just the Code tab

Programming basics - variables

  • no requirement for specifying the type of object to be represented by your variables
  • we want our variables name to be both succint and easily identifiable
  • Netlogo uses equal sign (=) only for logical test. Use set for changing the value of a variable
set value-win (0.1 * money-invested) - 1

Programming basics - variables

  • models paramenters
    • global variables
    • agents variables
  • local variables

Programming basics - functions/procedures

  • a label for a set of commands that are run together whenever the function is called
  • may take arguments
  • may need return values (reporters)
  • Netlogo has build-in functions called primitives, which helps programmers a lot!

Programming basics - loops

  • the ability to perform the same computation over and over and over at great speed.
  • for-loops and while-loops are the most common types.
while [any? other turtles-here]
    [forward 1]

Programming basics - loops

  • Netlogo is very polite
ask agents [
    right 45
    forward 1
]

Programming basics - conditional statements

  • allow for code to be executed only if specific conditions are met.
  • Nelogo provides if and ifelse commands for that.
ask agents [
    ifelse energy > 1
    [
        right 45
        forward 1
    ]
    [
        forage
    ]
]

Programming basics - object-oriented programming (OOP)

  • different types of variables for the program to work with.
  • each class stores its own variables and procedures.
  • all instantiations (objects) of this class will posses these variables and procedures.
  • Netlogo is a special typo of OOP called agent-oriented programming
    • commands can be written as direct instructions to the agent