Skip to content
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

Risky food simulation #4

Merged
merged 13 commits into from
Jun 14, 2023
Merged

Risky food simulation #4

merged 13 commits into from
Jun 14, 2023

Conversation

rlskoeser
Copy link
Contributor

@rlskoeser rlskoeser commented Jun 2, 2023

implements the "risky food" game as described in #3

  • includes preliminary readme describing the model and how to run it
  • preliminary data collection for reporting/analysis
  • prelininary unit testing to confirm logic

@rlskoeser rlskoeser requested a review from quadrismegistus June 2, 2023 18:20
@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@90ee4d8). Click here to learn what that means.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main       #4   +/-   ##
=======================================
  Coverage        ?   17.20%           
=======================================
  Files           ?        3           
  Lines           ?       93           
  Branches        ?        0           
=======================================
  Hits            ?       16           
  Misses          ?       77           
  Partials        ?        0           

Copy link

@quadrismegistus quadrismegistus left a comment

Choose a reason for hiding this comment

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

Really exciting work. Runs perfectly and code reads well!

Comment on lines +20 to +36
# initialize model with one agent
model = RiskyFoodModel(1)
model.prob_notcontaminated = prob_notcontaminated

results = []
total_runs = 100
for i in range(total_runs):
results.append(model.get_risky_food_status())

# use counter to tally the results
result_count = Counter(results)

# the expected value is the probability times number of times we ran it
expected = total_runs * model.prob_notcontaminated
assert math.isclose(
result_count[FoodStatus.NOTCONTAMINATED], expected, abs_tol=total_runs * 0.1
)

Choose a reason for hiding this comment

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

This is nice. 'Testing' takes on an interesting meaning here. One knows (from the scholarship) what expected outcomes of particular models ought to be. These can be written into our implementations directly as tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't have thought of using unit tests for checking reproducibility / replicability for known models, but would be interesting to automate (maybe more like integration testing?) that if we are working on a known model with expected outputs. But IDK if we'll be working much with simulations where we know the expected outputs, seems they are less interesting for investigating risk attitudes.

Comment on lines +10 to +22
Every agent gets a parameter `r` between 0 and 1. [or DISCRETE: 8 buckets etc.]

EACH ROUND:
- Nature selects a probability `p` for **N**
- For each agent: if `r` > `p`, then they choose RISKY; else SAFE
- Nature flips a coin with bias `p` for **N**, and announces **N** or **C**
- If **N**: everyone who chose RISKY gets 3, everyone who chose SAFE gets 2
- If **C**: everyone who chose RISKY gets 1, everyone SAFE 2
- Reproduce in proportion to payoff
- Either agent gets # of offspring = payoff [they replace–original “dies off”]
- OR: take the total payoff for RISKYs over total for everyone, there are that proportion of RISKYs in the new population

END ROUND

Choose a reason for hiding this comment

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

I like this semi-formal way of describing a 'round'! Very clear articulation of the steps/rules of the game.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is all from Lara! I just added some formatting. very clear, right?

Comment on lines +26 to +32
## Running the simulation

- Install python dependencies as described in the main project readme (requires mesa)
- To run from the main `simulating-risk` project directory:
- Configure python to include the current directory in import path;
for C-based shells, run `setenv PYTHONPATH .` ; for bash, run `export $PYTHONPATH=.`
- To run interactively with mesa runserver: `mesa runserver simulatingrisk/risky_food/`

Choose a reason for hiding this comment

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

Works for me!

Comment on lines +23 to +29
def step(self):
# choose food based on the probability not contaminated and risk tolerance
if self.risk_level > self.model.prob_notcontaminated:
choice = FoodChoice.RISKY
else:
choice = FoodChoice.SAFE
self.payoff = self.model.payoff(choice)

Choose a reason for hiding this comment

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

Again I feel like a 1st-person POV might be more legible as a way of describing what's happening

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you say more, I don't understand?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, read in the wrong order - I see your comments on the other PR now

Comment on lines +45 to +55
self.datacollector = mesa.DataCollector(
model_reporters={
"prob_notcontaminated": "prob_notcontaminated",
"contaminated": "contaminated",
"average_risk_level": "avg_risk_level",
"min_risk_level": "min_risk_level",
"max_risk_level": "max_risk_level",
"num_agents": "total_agents",
},
agent_reporters={"risk_level": "risk_level", "payoff": "payoff"},
)

Choose a reason for hiding this comment

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

Interesting setup they provid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems very verbose / redundant to me, but at least workable enough for now

@rlskoeser rlskoeser merged commit a23f747 into main Jun 14, 2023
@rlskoeser rlskoeser deleted the risky-food branch June 14, 2023 16:04
rlskoeser added a commit that referenced this pull request Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants