-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from Princeton-CDH/convergence-no-riskadjust
track when agents update risk level; implement convergence check based on stable risk attitudes
- Loading branch information
Showing
8 changed files
with
990 additions
and
26 deletions.
There are no files selected for viewing
738 changes: 738 additions & 0 deletions
738
notebooks/new_convergence/hdm_c7_riskdistribution.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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,52 @@ | ||
""" | ||
utility methods for analyzing data collected generated by this model | ||
""" | ||
import altair as alt | ||
import polars as pl | ||
|
||
from simulatingrisk.hawkdovemulti.model import RiskState | ||
|
||
|
||
def groupby_population_risk_category(df): | ||
"""takes a polars dataframe populated with model data generated | ||
by hawk/dove multi model, groups by population risk category and | ||
adds group labels.""" | ||
# currently written for polars dataframe | ||
|
||
# group on risk category to get totals for the number of runs that | ||
# ended up in each different type | ||
poprisk_grouped = df.group_by("population_risk_category").count() | ||
poprisk_grouped = poprisk_grouped.rename( | ||
{"population_risk_category": "risk_category"} | ||
) | ||
poprisk_grouped = poprisk_grouped.sort("risk_category") | ||
|
||
# add column with readable group labels for the numeric categories | ||
poprisk_grouped = poprisk_grouped.with_columns( | ||
pl.Series( | ||
name="type", | ||
values=poprisk_grouped["risk_category"].map_elements(RiskState.category), | ||
) | ||
) | ||
return poprisk_grouped | ||
|
||
|
||
def graph_population_risk_category(poprisk_grouped): | ||
"""given a dataframe grouped by :meth:`groupby_population_risk_category`, | ||
generate an altair chart graphing the number of runs in each type, | ||
grouped and labeled by the larger categories.""" | ||
return ( | ||
alt.Chart(poprisk_grouped) | ||
.mark_bar(width=15) | ||
.encode( | ||
x=alt.X( | ||
"risk_category", | ||
title="risk category", | ||
axis=alt.Axis(tickCount=13), # 13 categories | ||
scale=alt.Scale(domain=[1, 13]), | ||
), | ||
y=alt.Y("count", title="Number of runs"), | ||
color=alt.Color("type", title="type"), | ||
) | ||
.properties(title="Distribution of runs by final population risk category") | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.