Simulating risk attitudes and rationality using agent-based modeling
Creators: name: Koeser, Rebecca Sutton
Publisher: name: Zenodo
Year: 2024
Subjects: subject: agent-based modeling
subject: risk attitudes
subject: Digital humanities
subject: research software
subject: Computer Simulation
subject: simulations

description: This talk shares technical details from a collaboration with philosopher Lara Buchak on a project based on Buchak’s theory of risk-weighted rational decision in the context of game theory. We designed and implemented simulations to explore risk attitudes in the context of group populations and interactions.  I will share an overview of the development process used for the project, and then focus on three software engineering challenges: managing code for three similar simulations; testing methods with probabilistic outcomes; and problems of scale for batch running simulations across a large number of parameter combinations.

The simulations for this project are implemented in Python with the Mesa framework (Kazil et al.; Mesa), and the code is made available under an open source license (Koeser 2023). The development process for implementing and refining the simulations included unit testing, code review, and interactive review and discussion of draft simulations to ensure the logic and the code were implemented and working correctly. Although not a programmer, Buchak defined and documented the initial game setup for each of the simulations, and her review of the code and interface helped to identify and resolve errors in preliminary versions of the simulations.

We implemented three variants of a hawk/dove game. In this game cooperation, or playing dove, is better for the population, but acting aggressively, or playing hawk, is better for an individual if they are in a neighborhood of doves. To set up the game, we place agents on a grid and have them play against each of their neighbors, and accumulate payoffs based on the success of their plays. We define risk attitudes 0 through 8, where that number corresponds to the minimum number of neighbors playing dove for an agent to play hawk. An agent with risk attitude 0 is most risk seeking, and will always play hawk as long as at least one neighbor plays dove; an agent with risk attitude 8 always takes the safe choice and plays dove; an agent with risk attitude 4 is risk neutral, which corresponds to expected utility.  We implemented three different variants of this game: 1) all agents have the same risk attitude; 2) agents have different risk attitudes, initialized randomly; 3) agents have different risk attitudes and periodically compare with their neighbors and adopt the most successful risk attitude in their neighborhood. The presentation includes code snippets to demonstrate how I used class-based inheritance to simplify the shared logic and more clearly separate the distinct options. 

The simulations are set up with parameters to vary grid size, how often agents update their risk attitudes, neighborhood sizes for different actions, odds for initial choice, and initial distributions of risk attitudes. We also implemented convergence logic for simulation 3 to automatically stop the simulation when the population stabilizes. The philosophical argument depends on the distribution of risk attitudes and payoffs that result from different starting conditions, and claiming robust results requires running the simulations hundreds of times across different parameter combinations. Due to the high number of combinations of parameters for our simulations, I implemented a custom batch-runner that could be run in a High Performance Computing environment so I could more easily generate and analyze results across runs to determine which parameters were correlated with which results in the simulated populations.

This work has been presented as a lightning talk at Computational Humanities Research 2023 and has been accepted as poster presentation for Digital Humanities 2024. The implementation details are a footnote in my DH2024 proposal, and I welcome the challenge and opportunity to present in more depth on the software engineering aspects of the research.

* * * 

This presentation was accepted and presented at "DH Inside Out", a mini-conference sponsored by DH Tech as a pre-conference workshop at the DH2024 conference in Washington, D.C.