forked from Princeton-CDH/simulating-risk
-
Notifications
You must be signed in to change notification settings - Fork 0
DH Code Review #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rlskoeser
wants to merge
161
commits into
empty
Choose a base branch
from
dh-code-review
base: empty
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
161 commits
Select commit
Hold shift + click to select a range
14e9505
Initial commit
rlskoeser 26e3eb2
Add basic setup instructions and configure pre-commit hooks
rlskoeser f52f186
Merge pull request #1 from Princeton-CDH/setup
rlskoeser 6ec4b4e
Preliminary Mesa code for stag hunt game
rlskoeser 15608bb
Preliminary model for risky food simulation #3
rlskoeser 33cd8e7
Add python requirements
rlskoeser 2c27806
Use ruff instead of isort
rlskoeser 168afb7
Add readme to document the risky food simulation
rlskoeser 714b74c
Improve formatting for game description
rlskoeser 3ce223a
Document the risky food simulation
rlskoeser 5058661
Add more data collection parameters
rlskoeser ffe21c1
Make simrisk code pip installable
rlskoeser 95c762d
Initial unit testing structure
rlskoeser 9f3374b
Preliminary github actions unit test workflow
rlskoeser c07b522
Update deprecated action versions
rlskoeser e112e4e
Clean up debug output and unused code
rlskoeser 97f9278
Adjust propagation logic for next round
rlskoeser 2609fb9
Merge pull request #4 from Princeton-CDH/risky-food
rlskoeser 751fd55
Move stag hunt prototype into simulatingrisk project dir
rlskoeser a856b37
Merge branch 'main' into prototype-stag-hunt
rlskoeser 9a130cb
Add a minimal readme for stag hunt sim, documenting incomplete status
rlskoeser 1bdbb5f
Merge pull request #2 from Princeton-CDH/prototype-stag-hunt
rlskoeser 1342ef5
Preliminary implementation of risky bet game #6
rlskoeser 25a841b
Remove unused line of code
rlskoeser 49e5dda
Add data collection and chart for risk level quartiles
rlskoeser 2c55c68
Set size portrayal based on current wealth within wealth distribution
rlskoeser 1ea349e
Make risk adjustment strategy configurable
rlskoeser bb63922
Add data collection & chart to track the risk and payoff
rlskoeser 3640b77
Make agent count more efficient
rlskoeser 6a5a594
Correct colors and risk taking logic based on meeting review
rlskoeser 99738de
Refactor weighted choice into a resuable weighted coin flip method
rlskoeser edf3287
Start adding unit tests for risky bed model
rlskoeser 99237d1
Add more unit tests for risky bet model and agent
rlskoeser d292fe3
Use more efficient random method for weighted coin flip
rlskoeser 4c1dc0e
Rename agent to simplify and reduce redundancy
rlskoeser b0f9fda
Adjust risk indexing to use 11 bins, including 0-0.5 and 0.95-1
rlskoeser 396cd13
Add a readme to document the risky bet simulation
rlskoeser d85cb42
Fix typo
rlskoeser 8a64ab4
Merge pull request #9 from Princeton-CDH/risky-bet
rlskoeser 7245b34
Preliminary batch run script #7
rlskoeser c65e638
Notebook with preliminary analysis of risky bet batch run output
rlskoeser ef7ae22
Configure source directory; exclude notebooks dir when installing
rlskoeser fef2164
Set version and readme dynamically in pyproject
rlskoeser 8cdea17
Add risky food simulation to batch run script
rlskoeser 746cd69
Document how to run simulations (interactive & batch) in project readme
rlskoeser e8a0d4d
Add preliminary analysis of risky food batch run
rlskoeser 1c9b44d
Add unit tests for batch run script
rlskoeser 45aa0c1
Merge pull request #11 from Princeton-CDH/batch-run
rlskoeser b7b4fcc
Implement risky food types variant #5
rlskoeser dffb447
Split out server setup from server running code; add histogram #10
rlskoeser 9622760
Avoid unit tests error calculating median on empty list
rlskoeser b4d3e23
Adapt risk histogram for risky bet server
rlskoeser 1957a4b
Move risk histogram code into common location for reuse
rlskoeser def4129
Update batch run script for revised version of risky food sim
rlskoeser e50f395
Run analysis against batch run of new risky food sim
rlskoeser 3df943b
Update batch run test to match change in batch run params
rlskoeser b47ba17
Update for Mesa 2.1
rlskoeser 58040e0
Add tests for risky food model
rlskoeser c065646
Confirmed change in p > r comparison with @LaraBuchak
rlskoeser c75dda6
Add notes to the readme about the project and how we define risk level
rlskoeser e018ef0
Tweak batch run parameters to check for convergence in current sims
rlskoeser 304388d
Update analysis notebook to run against latest batch run data
rlskoeser dd5cf36
Update tests to match changes to batch run options
rlskoeser 8e3f0ce
Merge pull request #12 from Princeton-CDH/risky-food-types
rlskoeser 6479205
Tweak risky bet model for running with solara / jupyterviz
rlskoeser fecdcbe
Set risky bet to run in jupyter or mesa runserver; document in readme
rlskoeser f6508ac
Add matplotlib to dependencies
rlskoeser f6a28a3
Setup risky food to run with jupyterviz; generalize risk histogram plot
rlskoeser 7c258ec
Generalize runserver histogram module; handle missing chart labels
rlskoeser b586d32
Preliminary implemntation of hawk/dove game
rlskoeser f4deea4
Preliminary solara / jupyterviz app for hawkdove sim
rlskoeser de8bc99
Merge pull request #17 from Princeton-CDH/sims-in-colab
rlskoeser 2adfcba
Created using Colaboratory
rlskoeser 8235302
Created using Colaboratory
rlskoeser 414adc7
Add readme for notebooks folder
rlskoeser 4f73540
Implement custom agent space drawer with altair for hawk/dove game
rlskoeser 4d7966b
Implement option to initialize all hawk/dove with the same risk level
rlskoeser f273739
Add a 0-1 risk level diagram to readme
rlskoeser 6f550e9
Update hawk/dove rules to document revised logic for choosing play
rlskoeser 275b4c7
Update hawk/dove choice logic to calculate based on number of doves
rlskoeser 0b2bba8
Add risk/wealth plot to hawkdove simulation server
rlskoeser 6800f19
Implement option for initial hawk odds #22
rlskoeser 176a2f9
Revise label for 0.5/risk neutral in diagram
rlskoeser b74bb00
Update README.md
LaraBuchak c064517
Revise dove payoff to 2.1 to make EU maximizer clearer
rlskoeser 6e1c6de
Plot % hawks when displaying hawk/dove game
rlskoeser c61a742
Depend on bleeding edge mesa for latest jupyterviz code
rlskoeser b5730db
Update EU maximizer to 0.5⁻
rlskoeser 4bf4097
Merge pull request #23 from Princeton-CDH/readme-risklevel-diagram
rlskoeser 139f238
Merge pull request #16 from Princeton-CDH/feature/hawk-dove
rlskoeser feceb82
Update all apps and charts to work with current mesa / jupyterviz
rlskoeser 3d77cc7
Update README.md
LaraBuchak bb5dceb
Update README.md
LaraBuchak 92a7f42
Update README.md
LaraBuchak 566844f
Update README.md
LaraBuchak 4dcf443
Update README.md
LaraBuchak e7a6d97
Update README.md
LaraBuchak c4b72ef
Preliminary batch run for hawk/dove with single risk attitude
rlskoeser 43136a4
Run models as subcommands; add single/variable risk option to hawk/dove
rlskoeser 1c95b67
Include rolling average to % hawk chart for hawk/dove app
rlskoeser 5a89324
Handle risk level zero properly; include points in data collection
rlskoeser 5762569
Update batch run tests
rlskoeser 3965ff4
Notebooks for analyzing batch runs of single/variable risk hawk/dove
rlskoeser 5ad18e0
Don't try to calculate q1 when there are no risk levels
rlskoeser 6d27d3b
Merge pull request #28 from Princeton-CDH/feature/hawkdove-analysis
rlskoeser 152bcbd
Add diagrams to explain hawk/dove risk attitudes (#29)
rlskoeser 7a7fe5b
Calculate & collect rolling percent hawk; detect convergence & stop #…
rlskoeser b3d36ae
minimal solara app with access to all three current mesa models (#32)
rlskoeser 095554b
Split hawk/dove simulation into two variants for single and variable …
rlskoeser 105752c
Hawk/dove updating risk attitudes (#36)
rlskoeser 0ec6760
Add more charts to hawk/dove variable risk simulation (#37)
rlskoeser 9869fa2
address hawk/dove last choice sync error (#41)
rlskoeser dba6df3
implement logic for population risk states (#39)
rlskoeser c014969
Updated population risk state notebook using new enum & label method
rlskoeser 370977a
More options for hawk/dove neighborhoods (#46)
rlskoeser 492f786
Update to mesa v2.1.5
rlskoeser c0f86e4
Option to adjust risk attitude based on recent or total payoff
rlskoeser fd478e7
Add hawk/dove multi tests to version control; test adjust payoff
rlskoeser dc3179f
Ensure agents compare correct points for model config
rlskoeser 03bacc3
Simplify recent points init; test total/recent points tracking
rlskoeser f4b3459
Add option to initialize risk attitudes from different distributions
rlskoeser 862a95a
Update hawk/dove %hawk by risk level chart to use same color scheme
rlskoeser b036419
Merge pull request #54 from Princeton-CDH/hawkdove-adjust-recent-payoff
rlskoeser add9a14
Merge pull request #55 from Princeton-CDH/risk-distribution
rlskoeser 6293e82
Update hawk/dove game risk attitudes to include both endpoints
rlskoeser 2e5282c
Update chart showing hawk/dove choice by risk attitude
rlskoeser 7ccdd97
Update population risk categories for change to risk bounds 0-9
rlskoeser 528738d
Merge pull request #57 from Princeton-CDH/hawkdove-risk-endpoints
rlskoeser f0a1574
Fix hawk/dove multi color scheme for change to risk levels 0-9
rlskoeser bac1a48
Add parameter for chance of random hawk/dove play #45
rlskoeser 40d5883
Merge pull request #58 from Princeton-CDH/hawkdove-random-play
rlskoeser c9fe2b7
fine-tune variant distributions per feedback from @LaraBuchak
rlskoeser d61da2e
Merge pull request #59 from Princeton-CDH/revise-hawkdove-distributions
rlskoeser a65a856
Hawk/dove batch run code for data analysis (#60)
rlskoeser 7063027
Add a max runs option to batch run script for development
rlskoeser 1a5dd62
Add a readable status (running/converged) and include in data collection
rlskoeser 1c43deb
Document convergence logic
rlskoeser 8293f02
Correct mistake in play chart: r=0 always plays hawk
rlskoeser 6e130c7
Make collecting agent data optional (off by default)
rlskoeser 693da8d
Explicitly track total agents in model data collection
rlskoeser 818e0a9
Update data collection to include totals of agents per risk level
rlskoeser 3e24e0b
Merge pull request #65 from Princeton-CDH/doc-convergence
rlskoeser 5a6c84c
Merge pull request #66 from Princeton-CDH/collect-agent-totals
rlskoeser c23402a
Update agents to track whether risk attitude was updated or not
rlskoeser dd9f7e5
Implement new convergence logic; include agent change in data collection
rlskoeser 84b26ec
Add a line chart of # of agents who updated risk level
rlskoeser 09715eb
Update hawk/dove space to indicate agents who changed risk level
rlskoeser 9ac26d4
Document new convergence logic
rlskoeser b200b04
Turn adjustment on by default; add fallback convergence logic
rlskoeser e2cffdd
Preliminary code for batch running subsets for paired parameter testing
rlskoeser 2702706
Add reusable analysis methods for common analysis steps
rlskoeser b573d37
Add a command-line option to select parameter set
rlskoeser 40ae006
Add minimal sigint handling to batch run processing
rlskoeser 774a78d
Set default initial risk distribution to uniform instead of normal
rlskoeser 613ed15
Update tests to match revised default options
rlskoeser 2b5b955
Fix group and count logic so it counts the right thing
rlskoeser cd1c756
Add plot to show box plot of wealth by risk level; add titles to plots
rlskoeser 87211c4
Adjust batch run parameter sets
rlskoeser b7e70ac
Jupyter notebook analyzing population & risk distribution (new converge)
rlskoeser 2f66e01
Merge pull request #69 from Princeton-CDH/convergence-no-riskadjust
rlskoeser 76e2122
Merge branch 'main' into dh-code-review
rlskoeser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
| 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. | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.