Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
14e9505
Initial commit
rlskoeser Apr 20, 2023
26e3eb2
Add basic setup instructions and configure pre-commit hooks
rlskoeser May 25, 2023
f52f186
Merge pull request #1 from Princeton-CDH/setup
rlskoeser May 25, 2023
6ec4b4e
Preliminary Mesa code for stag hunt game
rlskoeser May 25, 2023
15608bb
Preliminary model for risky food simulation #3
rlskoeser Jun 1, 2023
33cd8e7
Add python requirements
rlskoeser Jun 1, 2023
2c27806
Use ruff instead of isort
rlskoeser Jun 6, 2023
168afb7
Add readme to document the risky food simulation
rlskoeser Jun 6, 2023
714b74c
Improve formatting for game description
rlskoeser Jun 6, 2023
3ce223a
Document the risky food simulation
rlskoeser Jun 6, 2023
5058661
Add more data collection parameters
rlskoeser Jun 6, 2023
ffe21c1
Make simrisk code pip installable
rlskoeser Jun 6, 2023
95c762d
Initial unit testing structure
rlskoeser Jun 6, 2023
9f3374b
Preliminary github actions unit test workflow
rlskoeser Jun 6, 2023
c07b522
Update deprecated action versions
rlskoeser Jun 6, 2023
e112e4e
Clean up debug output and unused code
rlskoeser Jun 6, 2023
97f9278
Adjust propagation logic for next round
rlskoeser Jun 14, 2023
2609fb9
Merge pull request #4 from Princeton-CDH/risky-food
rlskoeser Jun 14, 2023
751fd55
Move stag hunt prototype into simulatingrisk project dir
rlskoeser Jun 14, 2023
a856b37
Merge branch 'main' into prototype-stag-hunt
rlskoeser Jun 14, 2023
9a130cb
Add a minimal readme for stag hunt sim, documenting incomplete status
rlskoeser Jun 14, 2023
1bdbb5f
Merge pull request #2 from Princeton-CDH/prototype-stag-hunt
rlskoeser Jun 14, 2023
1342ef5
Preliminary implementation of risky bet game #6
rlskoeser Jun 14, 2023
25a841b
Remove unused line of code
rlskoeser Jun 20, 2023
49e5dda
Add data collection and chart for risk level quartiles
rlskoeser Jun 21, 2023
2c55c68
Set size portrayal based on current wealth within wealth distribution
rlskoeser Jun 21, 2023
1ea349e
Make risk adjustment strategy configurable
rlskoeser Jun 21, 2023
bb63922
Add data collection & chart to track the risk and payoff
rlskoeser Jun 21, 2023
3640b77
Make agent count more efficient
rlskoeser Jun 21, 2023
6a5a594
Correct colors and risk taking logic based on meeting review
rlskoeser Jun 21, 2023
99738de
Refactor weighted choice into a resuable weighted coin flip method
rlskoeser Jul 18, 2023
edf3287
Start adding unit tests for risky bed model
rlskoeser Jul 18, 2023
99237d1
Add more unit tests for risky bet model and agent
rlskoeser Jul 18, 2023
d292fe3
Use more efficient random method for weighted coin flip
rlskoeser Jul 18, 2023
4c1dc0e
Rename agent to simplify and reduce redundancy
rlskoeser Jul 18, 2023
b0f9fda
Adjust risk indexing to use 11 bins, including 0-0.5 and 0.95-1
rlskoeser Jul 18, 2023
396cd13
Add a readme to document the risky bet simulation
rlskoeser Jul 18, 2023
d85cb42
Fix typo
rlskoeser Jul 18, 2023
8a64ab4
Merge pull request #9 from Princeton-CDH/risky-bet
rlskoeser Jul 20, 2023
7245b34
Preliminary batch run script #7
rlskoeser Jul 18, 2023
c65e638
Notebook with preliminary analysis of risky bet batch run output
rlskoeser Jul 18, 2023
ef7ae22
Configure source directory; exclude notebooks dir when installing
rlskoeser Jul 18, 2023
fef2164
Set version and readme dynamically in pyproject
rlskoeser Jul 18, 2023
8cdea17
Add risky food simulation to batch run script
rlskoeser Jul 19, 2023
746cd69
Document how to run simulations (interactive & batch) in project readme
rlskoeser Jul 19, 2023
e8a0d4d
Add preliminary analysis of risky food batch run
rlskoeser Jul 19, 2023
1c9b44d
Add unit tests for batch run script
rlskoeser Jul 19, 2023
45aa0c1
Merge pull request #11 from Princeton-CDH/batch-run
rlskoeser Jul 20, 2023
b7b4fcc
Implement risky food types variant #5
rlskoeser Jul 25, 2023
dffb447
Split out server setup from server running code; add histogram #10
rlskoeser Jul 25, 2023
9622760
Avoid unit tests error calculating median on empty list
rlskoeser Jul 25, 2023
b4d3e23
Adapt risk histogram for risky bet server
rlskoeser Jul 25, 2023
1957a4b
Move risk histogram code into common location for reuse
rlskoeser Jul 25, 2023
def4129
Update batch run script for revised version of risky food sim
rlskoeser Jul 25, 2023
e50f395
Run analysis against batch run of new risky food sim
rlskoeser Jul 25, 2023
3df943b
Update batch run test to match change in batch run params
rlskoeser Jul 25, 2023
b47ba17
Update for Mesa 2.1
rlskoeser Jul 25, 2023
58040e0
Add tests for risky food model
rlskoeser Jul 25, 2023
c065646
Confirmed change in p > r comparison with @LaraBuchak
rlskoeser Jul 27, 2023
c75dda6
Add notes to the readme about the project and how we define risk level
rlskoeser Jul 27, 2023
e018ef0
Tweak batch run parameters to check for convergence in current sims
rlskoeser Aug 3, 2023
304388d
Update analysis notebook to run against latest batch run data
rlskoeser Aug 3, 2023
dd5cf36
Update tests to match changes to batch run options
rlskoeser Aug 3, 2023
8e3f0ce
Merge pull request #12 from Princeton-CDH/risky-food-types
rlskoeser Aug 3, 2023
6479205
Tweak risky bet model for running with solara / jupyterviz
rlskoeser Aug 8, 2023
fecdcbe
Set risky bet to run in jupyter or mesa runserver; document in readme
rlskoeser Aug 22, 2023
f6508ac
Add matplotlib to dependencies
rlskoeser Aug 22, 2023
f6a28a3
Setup risky food to run with jupyterviz; generalize risk histogram plot
rlskoeser Aug 22, 2023
7c258ec
Generalize runserver histogram module; handle missing chart labels
rlskoeser Aug 22, 2023
b586d32
Preliminary implemntation of hawk/dove game
rlskoeser Aug 22, 2023
f4deea4
Preliminary solara / jupyterviz app for hawkdove sim
rlskoeser Aug 22, 2023
de8bc99
Merge pull request #17 from Princeton-CDH/sims-in-colab
rlskoeser Sep 1, 2023
2adfcba
Created using Colaboratory
rlskoeser Sep 1, 2023
8235302
Created using Colaboratory
rlskoeser Sep 5, 2023
414adc7
Add readme for notebooks folder
rlskoeser Sep 5, 2023
4f73540
Implement custom agent space drawer with altair for hawk/dove game
rlskoeser Sep 6, 2023
4d7966b
Implement option to initialize all hawk/dove with the same risk level
rlskoeser Sep 6, 2023
f273739
Add a 0-1 risk level diagram to readme
rlskoeser Sep 12, 2023
6f550e9
Update hawk/dove rules to document revised logic for choosing play
rlskoeser Sep 12, 2023
275b4c7
Update hawk/dove choice logic to calculate based on number of doves
rlskoeser Sep 12, 2023
0b2bba8
Add risk/wealth plot to hawkdove simulation server
rlskoeser Sep 12, 2023
6800f19
Implement option for initial hawk odds #22
rlskoeser Sep 12, 2023
176a2f9
Revise label for 0.5/risk neutral in diagram
rlskoeser Sep 13, 2023
b74bb00
Update README.md
LaraBuchak Sep 13, 2023
c064517
Revise dove payoff to 2.1 to make EU maximizer clearer
rlskoeser Sep 13, 2023
6e1c6de
Plot % hawks when displaying hawk/dove game
rlskoeser Sep 13, 2023
c61a742
Depend on bleeding edge mesa for latest jupyterviz code
rlskoeser Sep 13, 2023
b5730db
Update EU maximizer to 0.5⁻
rlskoeser Sep 13, 2023
4bf4097
Merge pull request #23 from Princeton-CDH/readme-risklevel-diagram
rlskoeser Sep 14, 2023
139f238
Merge pull request #16 from Princeton-CDH/feature/hawk-dove
rlskoeser Sep 14, 2023
feceb82
Update all apps and charts to work with current mesa / jupyterviz
rlskoeser Sep 20, 2023
3d77cc7
Update README.md
LaraBuchak Sep 26, 2023
bb5dceb
Update README.md
LaraBuchak Sep 26, 2023
92a7f42
Update README.md
LaraBuchak Sep 26, 2023
566844f
Update README.md
LaraBuchak Sep 26, 2023
4dcf443
Update README.md
LaraBuchak Sep 26, 2023
e7a6d97
Update README.md
LaraBuchak Sep 26, 2023
c4b72ef
Preliminary batch run for hawk/dove with single risk attitude
rlskoeser Sep 26, 2023
43136a4
Run models as subcommands; add single/variable risk option to hawk/dove
rlskoeser Sep 26, 2023
1c95b67
Include rolling average to % hawk chart for hawk/dove app
rlskoeser Sep 28, 2023
5a89324
Handle risk level zero properly; include points in data collection
rlskoeser Sep 28, 2023
5762569
Update batch run tests
rlskoeser Sep 28, 2023
3965ff4
Notebooks for analyzing batch runs of single/variable risk hawk/dove
rlskoeser Oct 6, 2023
5ad18e0
Don't try to calculate q1 when there are no risk levels
rlskoeser Oct 6, 2023
6d27d3b
Merge pull request #28 from Princeton-CDH/feature/hawkdove-analysis
rlskoeser Oct 6, 2023
152bcbd
Add diagrams to explain hawk/dove risk attitudes (#29)
rlskoeser Oct 10, 2023
7a7fe5b
Calculate & collect rolling percent hawk; detect convergence & stop #…
rlskoeser Oct 10, 2023
b3d36ae
minimal solara app with access to all three current mesa models (#32)
rlskoeser Oct 13, 2023
095554b
Split hawk/dove simulation into two variants for single and variable …
rlskoeser Oct 19, 2023
105752c
Hawk/dove updating risk attitudes (#36)
rlskoeser Oct 25, 2023
0ec6760
Add more charts to hawk/dove variable risk simulation (#37)
rlskoeser Oct 26, 2023
9869fa2
address hawk/dove last choice sync error (#41)
rlskoeser Nov 7, 2023
dba6df3
implement logic for population risk states (#39)
rlskoeser Nov 7, 2023
c014969
Updated population risk state notebook using new enum & label method
rlskoeser Nov 7, 2023
370977a
More options for hawk/dove neighborhoods (#46)
rlskoeser Nov 28, 2023
492f786
Update to mesa v2.1.5
rlskoeser Dec 14, 2023
c0f86e4
Option to adjust risk attitude based on recent or total payoff
rlskoeser Dec 14, 2023
fd478e7
Add hawk/dove multi tests to version control; test adjust payoff
rlskoeser Dec 14, 2023
dc3179f
Ensure agents compare correct points for model config
rlskoeser Dec 14, 2023
03bacc3
Simplify recent points init; test total/recent points tracking
rlskoeser Dec 14, 2023
f4b3459
Add option to initialize risk attitudes from different distributions
rlskoeser Dec 15, 2023
862a95a
Update hawk/dove %hawk by risk level chart to use same color scheme
rlskoeser Dec 15, 2023
b036419
Merge pull request #54 from Princeton-CDH/hawkdove-adjust-recent-payoff
rlskoeser Dec 15, 2023
add9a14
Merge pull request #55 from Princeton-CDH/risk-distribution
rlskoeser Dec 15, 2023
6293e82
Update hawk/dove game risk attitudes to include both endpoints
rlskoeser Dec 19, 2023
2e5282c
Update chart showing hawk/dove choice by risk attitude
rlskoeser Dec 19, 2023
7ccdd97
Update population risk categories for change to risk bounds 0-9
rlskoeser Dec 19, 2023
528738d
Merge pull request #57 from Princeton-CDH/hawkdove-risk-endpoints
rlskoeser Dec 19, 2023
f0a1574
Fix hawk/dove multi color scheme for change to risk levels 0-9
rlskoeser Dec 19, 2023
bac1a48
Add parameter for chance of random hawk/dove play #45
rlskoeser Dec 19, 2023
40d5883
Merge pull request #58 from Princeton-CDH/hawkdove-random-play
rlskoeser Dec 20, 2023
c9fe2b7
fine-tune variant distributions per feedback from @LaraBuchak
rlskoeser Jan 4, 2024
d61da2e
Merge pull request #59 from Princeton-CDH/revise-hawkdove-distributions
rlskoeser Jan 16, 2024
a65a856
Hawk/dove batch run code for data analysis (#60)
rlskoeser Jan 23, 2024
7063027
Add a max runs option to batch run script for development
rlskoeser Jan 25, 2024
1a5dd62
Add a readable status (running/converged) and include in data collection
rlskoeser Jan 25, 2024
1c43deb
Document convergence logic
rlskoeser Jan 25, 2024
8293f02
Correct mistake in play chart: r=0 always plays hawk
rlskoeser Jan 26, 2024
6e130c7
Make collecting agent data optional (off by default)
rlskoeser Jan 30, 2024
693da8d
Explicitly track total agents in model data collection
rlskoeser Feb 6, 2024
818e0a9
Update data collection to include totals of agents per risk level
rlskoeser Feb 6, 2024
3e24e0b
Merge pull request #65 from Princeton-CDH/doc-convergence
rlskoeser Feb 21, 2024
5a6c84c
Merge pull request #66 from Princeton-CDH/collect-agent-totals
rlskoeser Feb 21, 2024
c23402a
Update agents to track whether risk attitude was updated or not
rlskoeser Feb 22, 2024
dd9f7e5
Implement new convergence logic; include agent change in data collection
rlskoeser Feb 23, 2024
84b26ec
Add a line chart of # of agents who updated risk level
rlskoeser Feb 23, 2024
09715eb
Update hawk/dove space to indicate agents who changed risk level
rlskoeser Feb 23, 2024
9ac26d4
Document new convergence logic
rlskoeser Feb 23, 2024
b200b04
Turn adjustment on by default; add fallback convergence logic
rlskoeser Feb 23, 2024
e2cffdd
Preliminary code for batch running subsets for paired parameter testing
rlskoeser Feb 23, 2024
2702706
Add reusable analysis methods for common analysis steps
rlskoeser Feb 23, 2024
b573d37
Add a command-line option to select parameter set
rlskoeser Feb 26, 2024
40ae006
Add minimal sigint handling to batch run processing
rlskoeser Feb 26, 2024
774a78d
Set default initial risk distribution to uniform instead of normal
rlskoeser Feb 26, 2024
613ed15
Update tests to match revised default options
rlskoeser Feb 26, 2024
2b5b955
Fix group and count logic so it counts the right thing
rlskoeser Feb 26, 2024
cd1c756
Add plot to show box plot of wealth by risk level; add titles to plots
rlskoeser Feb 26, 2024
87211c4
Adjust batch run parameter sets
rlskoeser Feb 26, 2024
b7e70ac
Jupyter notebook analyzing population & risk distribution (new converge)
rlskoeser Feb 27, 2024
2f66e01
Merge pull request #69 from Princeton-CDH/convergence-no-riskadjust
rlskoeser Mar 21, 2024
76e2122
Merge branch 'main' into dh-code-review
rlskoeser May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions simulatingrisk/hawkdove/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Hawk-Dove with risk attitudes

Hawk/Dove game with risk attitudes

## Game description

This is a variant of the Hawk/Dove Game: https://en.wikipedia.org/wiki/Chicken_(game)

| | H | D|
|-|-|-|
| H | 0, 0 | 3, 1|
| D |1, 3| 2, 2|

BACKGROUND: An unpublished paper by Simon Blessenohl shows that the equilibrium in this game is different for EU maximizers than for REU maximizers (all with the same risk-attitude), and that REU maximizers do better as a population (basically, play DOVE more often)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extend EU and REU, I do not understand the differences. A bit more background information to this distinction would be helpful.


We want to know: what happens when different people have _different_ risk-attitudes.
(See also variant simulation [Hawk/Dove game with multiple risk attitudes](../hawkdovemulti/). )

GAME: Hawk-Dove with risk-attitudes

Players arranged on a lattice [options for both 4 neighbors (AYBD) and 8 neighbors (XYZABCDE)]

| | | |
|-|-|-|
| X | Y |Z |
|A | **I** | B |
| C | D | E |

- Payoffs are determined as follows:
- Look at what each neighbor did, then:
- If I play HAWK and neighbor plays DOVE: 3
- If I play DOVE and neighbor plays DOVE: 2
- If I play DOVE and neighbor plays HAWK: 1
- If I play HAWK and neighbor plays HAWK: 0

Each player on a lattice (grid in Mesa):
- Has parameter $r$ [from 0 to 9]
- Let `d` be the number of neighbors who played DOVE during the previous round. If $d >= r$, then play HAWK. Otherwise play DOVE. (Agents who are risk-avoidant only play HAWK if there are a lot of doves around them. More risk-avoidance requires a higher number of doves to get an agent to play HAWK.)
- The proportion of neighbors who play DOVE corresponds to your probability of encountering a DOVE when playing a randomly-selected neighbor. The intended interpretation is that you maximize REU for this probability of your opponent playing DOVE. Thus, $r$ corresponds to the probability above which playing HAWK maximizes REU.
- Choice of play for the first round:
- Who is a HAWK and who is a DOVE is randomly determined; proportion set at the beginning of each simulation. E.g. 30% are HAWKS; if we have 100 players, then each player has a 30% chance of being HAWK;
- This initial parameter is called HAWK-ODDS; default is 50/50


## Payoffs and risk attitudes

This game has a discrete set of options instead of probability, so instead of defining `r` as a value between 0.0 and 1.0, we use discrete values based on the choices. For the game that includes diagonal neighbors when agents play all neighbors:

<table>
<tr><th>r</th></th><th>0</th><th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>
<tr>
<th>Plays H when:</th>
<td>always</td>
<td>$\geq1$ D</td>
<td>$\geq2$ D</td>
<td>$\geq3$ D</td>
<td>$\geq4$ D</td>
<td>$\geq5$ D</td>
<td>$\geq6$ D</td>
<td>$\geq7$ D</td>
<td>$\geq8$ D</td>
<td>never</td>
</tr>
<tr><td></td>
<td colspan="4">risk seeking</td>
<td>EU maximizer<br>(risk neutral)</td>
<td>EU maximizer<br>(risk neutral)</td>
<td colspan="4">risk avoidant</td>
</tr>
</table>


An REU maximizer will play HAWK when
```math
r(p) > \frac{(D,H)-(H,H)}{(H,D)-(D,D)}
```
In other words, when $r(p) > 0.52$. An EU maximizer, with $r(p) = p$, will play HAWK when $p > 0.52$, e.g., when more than 4 out of 8 neighbors play DOVE. Thus, $r = 4$ corresponds to risk-neutrality (EU maximization), $r < 4$ corresponds to risk-inclination, and $r > 4$ corresponds to risk-avoidance.

Payoffs were chosen to avoid the case in which two choices had equal expected utility for some number of neighbors. For example, if the payoff of $(D,D)$ was $(2,2)$, then at $p = 0.5$ (4 of 8 neighbors), then EU maximizers would be indifferent between HAWK and DOVE; in this case, no r-value would correspond to EU maximization, since $r = 4$ strictly prefers DOVE and $r = 3$ strictly prefers HAWK.

Another way to visualize the risk attitudes and choices in this game is this table, which shows when agents will play Hawk or Dove based on their risk attitudes (going down on the left side) and the number of neighbors playing Dove (across the top).

<table>
<tr><td colspan="2"></td><th colspan="9"># of neighors playing DOVE</thr></tr>
<tr><td><th>r</th><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td></tr>
<tr><td rowspan="4">risk seeking</td><th>0</th><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><th>1</th><td>D</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><th>2</th><td>D</td><td>D</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><th>3</th><td>D</td><td>D</td><td>D</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><td rowspan="2">neutral</td></td><th>4</th><td>D</td><td>D</td><td>D</td><td>D</td><td>H</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><th>5</th><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>H</td><td>H</td><td>H</td><td>H</td></tr>
<tr><td rowspan="4">risk avoidant</td><th>6</th><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>H</td><td>H</td><td>H</td></tr>
<tr><th>7</th><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>H</td><td>H</td></tr>
<tr><th>8</th><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>H</td></tr>
<tr><th>9</th><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td><td>D</td></tr>
</table>

## Convergence

The model is configured to stop automatically when it has stabilized. Convergence is based on a stable rolling average of the percent of agents in the simulation playing hawk.

A rolling average of the percent of agents playing hawk is calculated every round based on the percent for the last **30** rounds. The rolling average is not calculated until after at least **15** rounds.

When we have collected the rolling average for at least **15** rounds and the last **30** rolling averages are the same when rounded to 2 percentage points, we consider the simulation converged.


Loading