simulatingrisk 1.0.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/.github/workflows/unit_tests.yml +24 -21
- simulatingrisk-1.1.0/.justfile +16 -0
- simulatingrisk-1.1.0/.pre-commit-config.yaml +10 -0
- simulatingrisk-1.1.0/CHANGELOG.md +36 -0
- simulatingrisk-1.1.0/CITATION.cff +35 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/PKG-INFO +75 -51
- simulatingrisk-1.1.0/README.md +123 -0
- simulatingrisk-1.1.0/data/hawkdovemulti/payoff_bootstrap_stats_2pct_10k.csv +100001 -0
- simulatingrisk-1.1.0/docs/analysis/prev/notebooks/hawkdovemulti-adjust/hdm_c7_hawkodds.html +10623 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/hdm_c7_riskdistribution.html +264 -81
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-noadjust/index.html +744 -461
- simulatingrisk-1.1.0/docs/css/pico.min.css +4 -0
- simulatingrisk-1.1.0/docs/index.html +39 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/README.md +2 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hawkdovevar_population_risk_category.ipynb +42 -42
- simulatingrisk-1.1.0/notebooks/archive/hawkdovemulti_adjust/hdm_analysis.ipynb +925 -0
- simulatingrisk-1.1.0/notebooks/archive/hawkdovemulti_adjust/hdm_c7_hawkodds.ipynb +3214 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hdm_c7_riskdistribution.ipynb +269 -94
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_noadjust/analyze_batchrun_data.ipynb +765 -480
- simulatingrisk-1.1.0/notebooks/archive/hawkdovemulti_noadjust/bootstrap_sample_stats.py +127 -0
- simulatingrisk-1.1.0/notebooks/archive/hawkdovemulti_noadjust/payoff_significance.ipynb +1677 -0
- simulatingrisk-1.1.0/notebooks/evolv/convergence-population-category.py +190 -0
- simulatingrisk-1.1.0/notebooks/evolv/convergence.py +236 -0
- simulatingrisk-1.1.0/notebooks/evolv/parameter-significance.py +130 -0
- simulatingrisk-1.1.0/notebooks/multi/overview.py +151 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/pyproject.toml +17 -9
- simulatingrisk-1.1.0/simulatingrisk/__init__.py +1 -0
- simulatingrisk-1.1.0/simulatingrisk/app.py +269 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdove/model.py +39 -13
- simulatingrisk-1.1.0/simulatingrisk/hawkdove/ui.py +208 -0
- simulatingrisk-1.0.0/simulatingrisk/hawkdove/app.py → simulatingrisk-1.1.0/simulatingrisk/hawkdove/viz.py +15 -35
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdovemulti/README.md +18 -11
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdovemulti/analysis_utils.py +8 -11
- simulatingrisk-1.1.0/simulatingrisk/hawkdovemulti/batch_run.py +392 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdovemulti/model.py +161 -47
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdovemulti/simrisk_batch.slurm +7 -8
- simulatingrisk-1.1.0/simulatingrisk/hawkdovemulti/ui.py +52 -0
- simulatingrisk-1.0.0/simulatingrisk/hawkdovemulti/app.py → simulatingrisk-1.1.0/simulatingrisk/hawkdovemulti/viz.py +28 -98
- simulatingrisk-1.1.0/simulatingrisk/mo_app.py +158 -0
- simulatingrisk-1.1.0/simulatingrisk/poc_app.py +77 -0
- simulatingrisk-1.1.0/simulatingrisk/ui_common.py +55 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk.egg-info/PKG-INFO +75 -51
- simulatingrisk-1.1.0/simulatingrisk.egg-info/SOURCES.txt +98 -0
- simulatingrisk-1.1.0/simulatingrisk.egg-info/requires.txt +3 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_hawkdove.py +49 -1
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_hawkdovemulti.py +254 -9
- simulatingrisk-1.1.0/tests/test_hawkdovemulti_batch_run.py +185 -0
- simulatingrisk-1.0.0/.pre-commit-config.yaml +0 -13
- simulatingrisk-1.0.0/README.md +0 -83
- simulatingrisk-1.0.0/docs/notebooks/hawkdovemulti-adjust/hdm_c7_hawkodds.html +0 -10639
- simulatingrisk-1.0.0/notebooks/hawkdovemulti_adjust/hdm_analysis.ipynb +0 -1429
- simulatingrisk-1.0.0/notebooks/hawkdovemulti_adjust/hdm_c7_hawkodds.ipynb +0 -3230
- simulatingrisk-1.0.0/simulatingrisk/__init__.py +0 -1
- simulatingrisk-1.0.0/simulatingrisk/app.py +0 -50
- simulatingrisk-1.0.0/simulatingrisk/hawkdove/server.py +0 -189
- simulatingrisk-1.0.0/simulatingrisk/hawkdovemulti/batch_run.py +0 -328
- simulatingrisk-1.0.0/simulatingrisk.egg-info/SOURCES.txt +0 -81
- simulatingrisk-1.0.0/simulatingrisk.egg-info/requires.txt +0 -21
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/.gitignore +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/LICENSE +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/index.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/hdm_analysis.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/hdm_convergence_runlength.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/hdm_riskadjust_runlength.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/index.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/hawkdovemulti-adjust/parameter_analysis.html +0 -0
- {simulatingrisk-1.0.0/docs → simulatingrisk-1.1.0/docs/analysis/prev}/notebooks/index.html +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/docs/simulatingrisk-0.1.0.dev0-py3-none-any.whl +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdove_single_r/hawkdove_single_r_analysis.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hawkdovemulti_agentrisktotals.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hawkdovemulti_polars.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hawkdovemulti_runlength.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_adjust/hdm_riskadjust_runlength.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/hawkdovemulti_noadjust/hawkdove_variable_r_analysis.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/new_convergence/hdm_convergence_runlength.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/riskybet/riskybet_batch_analysis.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/riskybet/riskybet_simulation.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/riskyfood/riskyfood_batch_analysis.ipynb +0 -0
- {simulatingrisk-1.0.0/notebooks → simulatingrisk-1.1.0/notebooks/archive}/riskyfood/riskyfood_simulation.ipynb +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/postBuild +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/setup.cfg +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/about_app.md +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/batch_run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/charts/histogram.js +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/charts/histogram.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdove/README.md +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdove/run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/hawkdovemulti/run_simulation.ipynb +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_bet/README.md +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_bet/app.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_bet/model.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_bet/run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_bet/server.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/README.md +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/__init__.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/app.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/model.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/risky_food/server.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/stag_hunt/README.md +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/stag_hunt/__init__.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/stag_hunt/model.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/stag_hunt/run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk/utils.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk.egg-info/dependency_links.txt +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk.egg-info/entry_points.txt +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/simulatingrisk.egg-info/top_level.txt +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_batch_run.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_risky_bet.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_risky_food.py +0 -0
- {simulatingrisk-1.0.0 → simulatingrisk-1.1.0}/tests/test_utils.py +0 -0
|
@@ -4,6 +4,20 @@ on:
|
|
|
4
4
|
push: # run on every push or PR to any branch
|
|
5
5
|
pull_request:
|
|
6
6
|
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
# Cancel existing job(s) for workflow when a new one is queued
|
|
12
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
env:
|
|
16
|
+
# Prevent uv from including develop dependencies by default
|
|
17
|
+
UV_NO_DEV: 1
|
|
18
|
+
# Prevent uv run from syncing by default
|
|
19
|
+
UV_NO_SYNC: 1
|
|
20
|
+
|
|
7
21
|
jobs:
|
|
8
22
|
python-unit:
|
|
9
23
|
name: Python unit tests
|
|
@@ -11,33 +25,22 @@ jobs:
|
|
|
11
25
|
|
|
12
26
|
steps:
|
|
13
27
|
- name: Checkout repository
|
|
14
|
-
uses: actions/checkout@
|
|
15
|
-
|
|
16
|
-
- name: Setup Python
|
|
17
|
-
uses: actions/setup-python@v5
|
|
28
|
+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
18
29
|
with:
|
|
19
|
-
|
|
30
|
+
persist-credentials: false
|
|
20
31
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
- name: Cache pip
|
|
25
|
-
uses: actions/cache@v4
|
|
26
|
-
with:
|
|
27
|
-
path: ~/.cache/pip
|
|
28
|
-
key: pip-${{ hashFiles('pyproject.toml') }}
|
|
29
|
-
restore-keys: |
|
|
30
|
-
pip-${{ hashFiles('pyproject.toml') }}
|
|
31
|
-
pip-
|
|
32
|
+
- name: Install uv and Python version
|
|
33
|
+
uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v.8.2.0
|
|
34
|
+
# pull version from .python-version file, currently 3.12
|
|
32
35
|
|
|
33
|
-
- name: Install dependencies
|
|
34
|
-
run:
|
|
36
|
+
- name: Install package dependencies, including test dependencies
|
|
37
|
+
run: uv sync --group test
|
|
35
38
|
|
|
36
39
|
- name: Run pytest
|
|
37
|
-
run: pytest --cov=./ --cov-report=xml
|
|
40
|
+
run: uv run pytest --cov=./ --cov-report=xml
|
|
38
41
|
|
|
39
42
|
- name: Upload test coverage to Codecov
|
|
40
|
-
uses: codecov/codecov-action@
|
|
43
|
+
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
|
|
41
44
|
|
|
42
45
|
# Set the color of the slack message used in the next step based on the
|
|
43
46
|
# status of the build: "danger" for failure, "good" for success,
|
|
@@ -61,4 +64,4 @@ jobs:
|
|
|
61
64
|
SLACK_TITLE: "Workflow `${{ github.workflow }}`: ${{ job.status }}"
|
|
62
65
|
SLACK_MESSAGE: "Run <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}> on <https://github.com/${{ github.repository }}/|${{ github.repository }}@${{ github.ref }}>"
|
|
63
66
|
SLACK_FOOTER: "<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|View commit>"
|
|
64
|
-
MSG_MINIMAL: true
|
|
67
|
+
MSG_MINIMAL: true # use compact slack message format
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# justfile for building and serving notebooks as local html
|
|
2
|
+
set default-list := true
|
|
3
|
+
|
|
4
|
+
# TODO: may need base url option with exports to run properly on github pages
|
|
5
|
+
|
|
6
|
+
# Export marimo app and analysis notebooks to html docs
|
|
7
|
+
docs:
|
|
8
|
+
@echo "Exporting app ui to html-wasm in docs/sim/"
|
|
9
|
+
uv run marimo --quiet export html-wasm simulatingrisk/app.py -o docs/sim/ --mode run --no-sandbox --force
|
|
10
|
+
|
|
11
|
+
#uv run marimo export html notebooks/evolv/convergence.py -o docs/analysis/evolve/convergence.html
|
|
12
|
+
|
|
13
|
+
# serve documentation locally for dev/
|
|
14
|
+
serve-docs:
|
|
15
|
+
@echo "Serving docs/ at http://localhost:8000/"
|
|
16
|
+
python -m http.server --directory docs/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
# Ruff Python linter and formatter (configs in pyproject.toml)
|
|
3
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
4
|
+
rev: 22f0422809455ec89ffdcf5a00170ba816e42ddb # frozen: v0.15.16
|
|
5
|
+
hooks:
|
|
6
|
+
# Run the linter
|
|
7
|
+
- id: ruff-check
|
|
8
|
+
args: [--fix, --show-fixes] # enable lint fixes
|
|
9
|
+
# Run the formatter
|
|
10
|
+
- id: ruff-format
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# 1.1.0 - 2026-07-10
|
|
2
|
+
|
|
3
|
+
Updates to support the paper "Playing Risky Games."
|
|
4
|
+
|
|
5
|
+
Changes that affect both versions of the Hawk/Dove model:
|
|
6
|
+
|
|
7
|
+
- Revise default random play odds to 0.1 ; add to default batch run parameters
|
|
8
|
+
- Add boolean parameter to control whether to include extreme risk-attitudes 0 and 9 (`include_endpoints`, default is True)
|
|
9
|
+
- Add `include_endpoints` parameter to interactive simulation controls
|
|
10
|
+
- Update labels and legends in the interactive simulation and analysis notebooks to match language in the paper.
|
|
11
|
+
- Add a marimo notebook to serve as the interface for running the Hawk/Dove simulation interactively; supports export to html+wasm for publication via static site.
|
|
12
|
+
|
|
13
|
+
Model-specific changes:
|
|
14
|
+
|
|
15
|
+
## Sim 1. Multiple Risk-Attiudes (no adjustment)
|
|
16
|
+
|
|
17
|
+
- Significance testing for payoff results from previous batch run data
|
|
18
|
+
- Set minimum number of rounds to 50 before checking for convergence
|
|
19
|
+
|
|
20
|
+
## Sim 2. Evolving Risk-Attiudes (with adjustment)
|
|
21
|
+
|
|
22
|
+
- Tie-breaker: chose randomly when there is a tie for best payoff when selecting neighbor to emulate
|
|
23
|
+
- Set minimum number of rounds to 300 before checking for convergence
|
|
24
|
+
- Improved logic for sum of agents with changed risk attitudes in the last adjustment round (part of convergence check)
|
|
25
|
+
|
|
26
|
+
## Improvements to custom batch run script
|
|
27
|
+
|
|
28
|
+
- Improve multiprocessing logic
|
|
29
|
+
- Add a timeout on the wait so main loop doesn't wait forever
|
|
30
|
+
- Cycle workers to avoid memory leaks on long runs
|
|
31
|
+
- Shift data collection schedule logic to the model: only collect data needed for convergence checks and requested reporting (agent data optional; end of round or adjustment rounds only)
|
|
32
|
+
|
|
33
|
+
## Miscellaneous
|
|
34
|
+
|
|
35
|
+
- Jupyter notebooks from prior analysis have been moved to `notebooks/archive/`
|
|
36
|
+
- Static html exports from jupyter notebooks have to `docs/analysis/prev/`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# This CITATION.cff file was generated doi2cff, updated with cffinit.
|
|
2
|
+
cff-version: 1.2.0
|
|
3
|
+
title: simulating-risk v1.0
|
|
4
|
+
message: >-
|
|
5
|
+
If you use this software, please cite it using these
|
|
6
|
+
metadata.
|
|
7
|
+
type: software
|
|
8
|
+
authors:
|
|
9
|
+
- given-names: Rebecca Sutton
|
|
10
|
+
family-names: Koeser
|
|
11
|
+
affiliation: Princeton University
|
|
12
|
+
orcid: 'https://orcid.org/0000-0002-8762-8057'
|
|
13
|
+
- given-names: Lara
|
|
14
|
+
family-names: Buchak
|
|
15
|
+
affiliation: Princeton University
|
|
16
|
+
orcid: 'https://orcid.org/0000-0002-0232-4274'
|
|
17
|
+
repository-code: 'https://github.com/Princeton-CDH/simulating-risk'
|
|
18
|
+
url: 'https://cdh.princeton.edu/projects/simulating-risk/'
|
|
19
|
+
abstract: >-
|
|
20
|
+
Code associated with the "Simulating risk, risking
|
|
21
|
+
simulations" led by Lara Buchak, supported by the Center
|
|
22
|
+
for Digital Humanities at Princeton University
|
|
23
|
+
Simulations are implemented in the Mesa Framework, using
|
|
24
|
+
Agent Based Modeling to explore risk attitudes within
|
|
25
|
+
populations.
|
|
26
|
+
keywords:
|
|
27
|
+
- Computer Simulation
|
|
28
|
+
- Decision Theory
|
|
29
|
+
- Game Theory
|
|
30
|
+
- Risk Attitudes
|
|
31
|
+
- Risk-Weighted Expected Utility
|
|
32
|
+
license: Apache-2.0
|
|
33
|
+
version: '1.0'
|
|
34
|
+
date-released: '2026-01-24'
|
|
35
|
+
doi: 10.5281/zenodo.18361157
|
|
@@ -1,54 +1,40 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simulatingrisk
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Agent-based modeling for simulations related to risk and rationality
|
|
5
5
|
License: Apache-2
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
7
|
-
Requires-Python: >=3.
|
|
8
|
-
Description-Content-Type: text/
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
Requires-Dist: mesa==2.1.5
|
|
11
|
-
Requires-Dist:
|
|
12
|
-
Requires-Dist:
|
|
13
|
-
Provides-Extra: dev
|
|
14
|
-
Requires-Dist: pre-commit; extra == "dev"
|
|
15
|
-
Requires-Dist: pytest; extra == "dev"
|
|
16
|
-
Requires-Dist: pytest-cov; extra == "dev"
|
|
17
|
-
Provides-Extra: analysis
|
|
18
|
-
Requires-Dist: jupyterlab; extra == "analysis"
|
|
19
|
-
Requires-Dist: polars; extra == "analysis"
|
|
20
|
-
Requires-Dist: hvplot; extra == "analysis"
|
|
21
|
-
Requires-Dist: pyarrow; extra == "analysis"
|
|
22
|
-
Requires-Dist: altair; extra == "analysis"
|
|
23
|
-
Requires-Dist: scipy; extra == "analysis"
|
|
24
|
-
Requires-Dist: scikit-learn; extra == "analysis"
|
|
25
|
-
Requires-Dist: seaborn; extra == "analysis"
|
|
26
|
-
Requires-Dist: vegafusion[embed]>=1.5.0; extra == "analysis"
|
|
27
|
-
Requires-Dist: vl-convert-python; extra == "analysis"
|
|
28
|
-
Requires-Dist: great-tables; extra == "analysis"
|
|
11
|
+
Requires-Dist: altair>=6.0
|
|
12
|
+
Requires-Dist: marimo>=0.23.11
|
|
29
13
|
Dynamic: license-file
|
|
30
14
|
|
|
31
15
|
# Simulating Risk
|
|
32
16
|
|
|
17
|
+
[](https://doi.org/10.5281/zenodo.18361156)
|
|
33
18
|
[](https://github.com/DHCodeReview/simulating-risk/pull/1) [](https://github.com/Princeton-CDH/simulating-risk/actions/workflows/unit_tests.yml)
|
|
34
19
|
|
|
35
20
|
The code in this repository is associated with the CDH project [Simulating risk, risking simulations](https://cdh.princeton.edu/projects/simulating-risk/).
|
|
36
21
|
|
|
37
22
|
Simulations are implemented with [Mesa](https://mesa.readthedocs.io/en/stable/), using Agent Based Modeling to explore risk attitudes within populations.
|
|
38
23
|
|
|
39
|
-
|
|
24
|
+
---
|
|
40
25
|
|
|
41
|
-
## Simulations with agent interaction
|
|
26
|
+
## Simulations with risk attitudes and agent interaction
|
|
42
27
|
|
|
43
28
|
- [Hawk/Dove with risk attitudes](simulatingrisk/hawkdove)
|
|
44
29
|
- [Hawk/Dove with multiple risk attitudes and adjustment](simulatingrisk/hawkdovemulti)
|
|
45
30
|
|
|
46
|
-
|
|
31
|
+
> [!TIP]
|
|
32
|
+
> Run an interactive version of the simulation online: [Hawk/Dove with multiple risk attitudes](https://py.cafe/rlskoeser/simulatingrisk-hawk-dove-multirisk)
|
|
47
33
|
|
|
34
|
+
> [!NOTE]
|
|
35
|
+
> Altenately, run the simulation in a Jupyter notebook: [](https://mybinder.org/v2/gh/Princeton-CDH/simulating-risk.git/HEAD?urlpath=%2Fdoc%2Ftree%2Fsimulatingrisk%2Fhawkdovemulti%2Frun_simulation.ipynb)
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
The simulation can also be run in a Jupyter notebook: [](https://mybinder.org/v2/gh/Princeton-CDH/simulating-risk.git/HEAD?urlpath=%2Fdoc%2Ftree%2Fsimulatingrisk%2Fhawkdovemulti%2Frun_simulation.ipynb)
|
|
37
|
+
The code for **Hawk/Dove with risk attitudes** and **Hawk/Dove with multiple risk attitudes** in this codebase was [reviewed](https://github.com/DHCodeReview/simulating-risk/pull/1) in June 2024 by [Scott Foster](https://github.com/sgfost) and [Malte Vogl](https://github.com/maltevogl) (Senior Research Fellow, Max Planck Institute of Geoanthropology) via [DHTech Community Code Review](https://dhcodereview.github.io/); review was facilitated by [Cole Crawford](https://github.com/ColeDCrawford) (Senior Software Engineer, Harvard Arts and Humanities Research Computing).
|
|
52
38
|
|
|
53
39
|
## Simulations with risky choices (environment)
|
|
54
40
|
|
|
@@ -61,53 +47,91 @@ Across simulations, we define agents with risk attitudes tracked via a numeric `
|
|
|
61
47
|
|
|
62
48
|
When the risky bet might be better or worse than the safe bet by the same amount (for example, the risky bet yields 3 or 1 and the safe bet yields 2), an agent who maximizes expected utility will prefer the risky bet when p > 0.5 and will prefer the safe bet when 'p < 0.5'; and they will be indifferent between the risky bet and the safe bet. Thus, r = 0.5 corresponds to expected utility maximization except in the case in which the probability is exactly 0.5 (or, we might say, a point epsilon units to the left of 0.5, where epsilon is smaller than the fineness of our random number generator, corresponds to expected utility maximization). These complications make no difference in practice, so we can simply say that r = 0.5 corresponds to expected utility maximization.
|
|
63
49
|
|
|
50
|
+
```mermaid
|
|
51
|
+
---
|
|
52
|
+
title: risk attitude / risk level (for probabilistic choices)
|
|
53
|
+
---
|
|
54
|
+
flowchart LR
|
|
55
|
+
r0["<b>0.0</b>
|
|
56
|
+
always takes risky choice
|
|
57
|
+
(any risk is acceptable)"]
|
|
58
|
+
reu["<b>0.5</b>
|
|
59
|
+
risk neutral
|
|
60
|
+
(expected utility maximizer)"]
|
|
61
|
+
r1["<b>1.0</b>
|
|
62
|
+
always takes safe choice
|
|
63
|
+
(no risk is acceptable)"]
|
|
64
|
+
r0 ---|risk seeking|reu---|risk averse|r1
|
|
65
|
+
```
|
|
64
66
|
|
|
65
67
|
## Development instructions
|
|
66
68
|
|
|
67
69
|
Initial setup and installation:
|
|
68
70
|
|
|
69
|
-
-
|
|
71
|
+
- _Recommmended_: use [`uv`](https://docs.astral.sh/uv/) to create a Python 3.12 virtualenv and install dependencies, including development dependencies:
|
|
70
72
|
|
|
71
73
|
```sh
|
|
72
|
-
|
|
73
|
-
source simrisk/bin/activate
|
|
74
|
+
uv sync
|
|
74
75
|
```
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
### Install pre-commit hooks
|
|
78
|
+
|
|
79
|
+
Install pre-commit hooks (currently [black](https://github.com/psf/black) and [ruff](https://beta.ruff.rs/docs/)):
|
|
77
80
|
|
|
78
81
|
```sh
|
|
79
|
-
|
|
80
|
-
pip install -e ".[dev]"
|
|
82
|
+
pre-commit install
|
|
81
83
|
```
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
### Interactive interface to the simulations
|
|
86
|
+
|
|
87
|
+
We use a marimo notebook as the interface for running the Hawk/Dove simulation interactively. To run locally for development, using
|
|
88
|
+
the local development environment, run with sandbox disabled:
|
|
89
|
+
|
|
84
90
|
```sh
|
|
85
|
-
|
|
91
|
+
uv run marimo edit simulatingrisk/app.py --no-sandbox
|
|
86
92
|
```
|
|
87
93
|
|
|
88
|
-
|
|
94
|
+
For publication via static site, this notebook should be saved as html + web assembly. This requires a version of the `simulatingrisk` package that can be installed in pyodide, either by a published version on pypi or a local wheel for testing.
|
|
95
|
+
|
|
96
|
+
To export as html+wasm in edit mode, to debug any wasm-specific problems:
|
|
97
|
+
|
|
89
98
|
```sh
|
|
90
|
-
|
|
99
|
+
uv run marimo export html-wasm simulatingrisk/app.py -o docs/sim/ --mode edit
|
|
91
100
|
```
|
|
92
101
|
|
|
93
|
-
|
|
94
|
-
is available online.
|
|
102
|
+
For convenience, a `.justfile` is included for building documentation and serving locally. Requires [just](https://github.com/casey/just) version 1.52 or newer.
|
|
95
103
|
|
|
104
|
+
With `just` installed, run the following to build the documentation and serve it locally:
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
````sh
|
|
107
|
+
just docs
|
|
108
|
+
just serve-docs
|
|
109
|
+
```
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
the path to the model, e.g. `mesa runserver simulatingrisk/risky_bet/`
|
|
101
|
-
Refer to the readme for each model for more details.
|
|
102
|
-
- Simulations can be run in batches to aggregate data across multiple
|
|
103
|
-
runs and different parameters. For example,
|
|
104
|
-
`./simulatingrisk/batch_run.py riskyfood`
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
### Install pre-commit hooks
|
|
111
|
+
That is equivalent to running the following commands. To export manually in run mode:
|
|
108
112
|
|
|
109
|
-
|
|
113
|
+
```sh
|
|
114
|
+
uv run marimo export html-wasm simulatingrisk/app.py -o docs/sim/ --mode run --no-sandbox -f
|
|
115
|
+
````
|
|
116
|
+
|
|
117
|
+
To view locally, start a python webserver:
|
|
110
118
|
|
|
111
119
|
```sh
|
|
112
|
-
|
|
120
|
+
python -m http.server --directory docs/
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The interacvite simulation will be available at http://localhost:8000/sim/
|
|
124
|
+
|
|
125
|
+
For testing the html+wasm application notebook with a local version of the simrisk code (notebook must be updated
|
|
126
|
+
to install simulatingrisk from the wheel).
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
uv build --wheel -o docs/sim/
|
|
130
|
+
uv run marimo export html-wasm simulatingrisk/app.py --mode edit -o docs/sim/ --no-sandbox -f
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
To export static html copies of analysis notebooks:
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
uv run marimo export html notebooks/evolv-risk-attitudes/convergence.py -o docs/analysis/evolve/index.html
|
|
113
137
|
```
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Simulating Risk
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.18361156)
|
|
4
|
+
[](https://github.com/DHCodeReview/simulating-risk/pull/1) [](https://github.com/Princeton-CDH/simulating-risk/actions/workflows/unit_tests.yml)
|
|
5
|
+
|
|
6
|
+
The code in this repository is associated with the CDH project [Simulating risk, risking simulations](https://cdh.princeton.edu/projects/simulating-risk/).
|
|
7
|
+
|
|
8
|
+
Simulations are implemented with [Mesa](https://mesa.readthedocs.io/en/stable/), using Agent Based Modeling to explore risk attitudes within populations.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Simulations with risk attitudes and agent interaction
|
|
13
|
+
|
|
14
|
+
- [Hawk/Dove with risk attitudes](simulatingrisk/hawkdove)
|
|
15
|
+
- [Hawk/Dove with multiple risk attitudes and adjustment](simulatingrisk/hawkdovemulti)
|
|
16
|
+
|
|
17
|
+
> [!TIP]
|
|
18
|
+
> Run an interactive version of the simulation online: [Hawk/Dove with multiple risk attitudes](https://py.cafe/rlskoeser/simulatingrisk-hawk-dove-multirisk)
|
|
19
|
+
|
|
20
|
+
> [!NOTE]
|
|
21
|
+
> Altenately, run the simulation in a Jupyter notebook: [](https://mybinder.org/v2/gh/Princeton-CDH/simulating-risk.git/HEAD?urlpath=%2Fdoc%2Ftree%2Fsimulatingrisk%2Fhawkdovemulti%2Frun_simulation.ipynb)
|
|
22
|
+
|
|
23
|
+
The code for **Hawk/Dove with risk attitudes** and **Hawk/Dove with multiple risk attitudes** in this codebase was [reviewed](https://github.com/DHCodeReview/simulating-risk/pull/1) in June 2024 by [Scott Foster](https://github.com/sgfost) and [Malte Vogl](https://github.com/maltevogl) (Senior Research Fellow, Max Planck Institute of Geoanthropology) via [DHTech Community Code Review](https://dhcodereview.github.io/); review was facilitated by [Cole Crawford](https://github.com/ColeDCrawford) (Senior Software Engineer, Harvard Arts and Humanities Research Computing).
|
|
24
|
+
|
|
25
|
+
## Simulations with risky choices (environment)
|
|
26
|
+
|
|
27
|
+
- [Risky Food](simulatingrisk/risky_food)
|
|
28
|
+
- [Risky Bet](simulatingrisk/risky_bet)
|
|
29
|
+
|
|
30
|
+
## Risk attitude definitions
|
|
31
|
+
|
|
32
|
+
Across simulations, we define agents with risk attitudes tracked via a numeric `r` or `risk_level` 0.0 - 1.0, where `r` is that agent's minimum acceptable risk level for taking the risky bet. When the probability 'p' of the risky bet paying off is greater than an agent's 'r', that agent will take the bet. An agent with `r=1` will always take the safe option (no risk is acceptable); an agent with `r=0` will always take the risky choice (any risk is acceptable). Notice that the agent is never indifferent; allowing indifference would require introducing a tie-breaking rule, which would be a further parameter.
|
|
33
|
+
|
|
34
|
+
When the risky bet might be better or worse than the safe bet by the same amount (for example, the risky bet yields 3 or 1 and the safe bet yields 2), an agent who maximizes expected utility will prefer the risky bet when p > 0.5 and will prefer the safe bet when 'p < 0.5'; and they will be indifferent between the risky bet and the safe bet. Thus, r = 0.5 corresponds to expected utility maximization except in the case in which the probability is exactly 0.5 (or, we might say, a point epsilon units to the left of 0.5, where epsilon is smaller than the fineness of our random number generator, corresponds to expected utility maximization). These complications make no difference in practice, so we can simply say that r = 0.5 corresponds to expected utility maximization.
|
|
35
|
+
|
|
36
|
+
```mermaid
|
|
37
|
+
---
|
|
38
|
+
title: risk attitude / risk level (for probabilistic choices)
|
|
39
|
+
---
|
|
40
|
+
flowchart LR
|
|
41
|
+
r0["<b>0.0</b>
|
|
42
|
+
always takes risky choice
|
|
43
|
+
(any risk is acceptable)"]
|
|
44
|
+
reu["<b>0.5</b>
|
|
45
|
+
risk neutral
|
|
46
|
+
(expected utility maximizer)"]
|
|
47
|
+
r1["<b>1.0</b>
|
|
48
|
+
always takes safe choice
|
|
49
|
+
(no risk is acceptable)"]
|
|
50
|
+
r0 ---|risk seeking|reu---|risk averse|r1
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Development instructions
|
|
54
|
+
|
|
55
|
+
Initial setup and installation:
|
|
56
|
+
|
|
57
|
+
- _Recommmended_: use [`uv`](https://docs.astral.sh/uv/) to create a Python 3.12 virtualenv and install dependencies, including development dependencies:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
uv sync
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Install pre-commit hooks
|
|
64
|
+
|
|
65
|
+
Install pre-commit hooks (currently [black](https://github.com/psf/black) and [ruff](https://beta.ruff.rs/docs/)):
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
pre-commit install
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Interactive interface to the simulations
|
|
72
|
+
|
|
73
|
+
We use a marimo notebook as the interface for running the Hawk/Dove simulation interactively. To run locally for development, using
|
|
74
|
+
the local development environment, run with sandbox disabled:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
uv run marimo edit simulatingrisk/app.py --no-sandbox
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For publication via static site, this notebook should be saved as html + web assembly. This requires a version of the `simulatingrisk` package that can be installed in pyodide, either by a published version on pypi or a local wheel for testing.
|
|
81
|
+
|
|
82
|
+
To export as html+wasm in edit mode, to debug any wasm-specific problems:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
uv run marimo export html-wasm simulatingrisk/app.py -o docs/sim/ --mode edit
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For convenience, a `.justfile` is included for building documentation and serving locally. Requires [just](https://github.com/casey/just) version 1.52 or newer.
|
|
89
|
+
|
|
90
|
+
With `just` installed, run the following to build the documentation and serve it locally:
|
|
91
|
+
|
|
92
|
+
````sh
|
|
93
|
+
just docs
|
|
94
|
+
just serve-docs
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
That is equivalent to running the following commands. To export manually in run mode:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
uv run marimo export html-wasm simulatingrisk/app.py -o docs/sim/ --mode run --no-sandbox -f
|
|
101
|
+
````
|
|
102
|
+
|
|
103
|
+
To view locally, start a python webserver:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
python -m http.server --directory docs/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The interacvite simulation will be available at http://localhost:8000/sim/
|
|
110
|
+
|
|
111
|
+
For testing the html+wasm application notebook with a local version of the simrisk code (notebook must be updated
|
|
112
|
+
to install simulatingrisk from the wheel).
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
uv build --wheel -o docs/sim/
|
|
116
|
+
uv run marimo export html-wasm simulatingrisk/app.py --mode edit -o docs/sim/ --no-sandbox -f
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
To export static html copies of analysis notebooks:
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
uv run marimo export html notebooks/evolv-risk-attitudes/convergence.py -o docs/analysis/evolve/index.html
|
|
123
|
+
```
|