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

Updates to Epstein example #2429

Merged
merged 7 commits into from
Oct 27, 2024
Merged

Updates to Epstein example #2429

merged 7 commits into from
Oct 27, 2024

Conversation

quaquel
Copy link
Member

@quaquel quaquel commented Oct 27, 2024

This is an update to the Epstein model to address #2423. Next to shifting to a von Neumann grid, there are several other changes.

  1. A minor change in the arrest_probability calculation by using round. This is based on an extensive literature that shows that without it, the original Epstein results cannot be reproduced.
  2. Shifting to using an enum for the state of the citizen (this has various knock-on consequences elsewhere in the code that make the code cleaner and shorter).
  3. Rework of app.py to only use stuff that actually works when drawing new-style discrete grids.

The net result is shown below.

Screenshot 2024-10-27 at 10 36 26

quaquel and others added 5 commits October 27, 2024 10:20
* shift to von neuman grid
* update of perceived risk with round operator
* introduction of enum for state
* cleanup of statistics gathering to use enum
* update of visualization code to be consistent with what is currently supported when drawing new_style discrete grids
@quaquel quaquel added the example Changes the examples or adds to them. label Oct 27, 2024
@quaquel quaquel linked an issue Oct 27, 2024 that may be closed by this pull request
@quaquel quaquel requested a review from EwoutH October 27, 2024 09:43
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.9% [-4.4%, -1.5%] 🔵 -0.9% [-1.1%, -0.8%]
BoltzmannWealth large 🔵 -1.2% [-1.6%, -0.9%] 🔵 -1.7% [-2.4%, -1.0%]
Schelling small 🔵 -1.1% [-1.7%, -0.4%] 🔵 -1.2% [-2.0%, -0.5%]
Schelling large 🔵 +0.8% [-0.1%, +1.7%] 🔵 -2.8% [-4.3%, -1.3%]
WolfSheep small 🔵 +0.7% [+0.4%, +1.0%] 🔵 +0.4% [+0.2%, +0.7%]
WolfSheep large 🔵 -1.2% [-2.0%, -0.3%] 🔵 -0.2% [-2.3%, +1.8%]
BoidFlockers small 🔵 -2.4% [-3.4%, -1.4%] 🔵 -1.1% [-2.0%, -0.3%]
BoidFlockers large 🔵 -1.5% [-1.9%, -1.0%] 🔵 -0.9% [-1.4%, -0.2%]

Comment on lines 75 to +78
for cell in self.grid.all_cells:
if self.random.random() < self.cop_density:
cop = Cop(self, vision=self.cop_vision)
cop.move_to(cell)
klass = self.random.choices(
[Citizen, Cop, None],
cum_weights=[citizen_density, citizen_density + cop_density, 1],
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit complicated. Can't we just generate cop_density * cells cops and citizen_density * cells citizens, and place them randomly?

Or aren't they allowed to start at the same cell?

Copy link
Member Author

Choose a reason for hiding this comment

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

There can be at most one agent per cell.

Copy link
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

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

Few minor comments, generally seems like a nice improvement.

Have you any idea about performance?

@quaquel
Copy link
Member Author

quaquel commented Oct 27, 2024

Have you any idea about performance?

I haven't done any testing, this was really focussed on getting the proper behavior back.

@quaquel quaquel merged commit aaf9026 into projectmesa:main Oct 27, 2024
10 of 12 checks passed
@quaquel quaquel deleted the epstein branch November 4, 2024 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
example Changes the examples or adds to them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

example: Update EpsteinCivilViolence to use OrthogonalVonNeumann
2 participants