-
Notifications
You must be signed in to change notification settings - Fork 163
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
Epstein civil violence: Switch to experimental datacollector #158
Open
rht
wants to merge
2
commits into
projectmesa:main
Choose a base branch
from
rht:epstein_experimental
base: main
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
2 commits
Select commit
Hold shift + click to select a range
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 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,58 @@ | ||
from mesa.visualization import Slider, SolaraViz | ||
|
||
from epstein_civil_violence.agent import Citizen, Cop | ||
from epstein_civil_violence.model import EpsteinCivilViolence | ||
|
||
|
||
COP_COLOR = "#000000" | ||
AGENT_QUIET_COLOR = "#648FFF" | ||
AGENT_REBEL_COLOR = "#FE6100" | ||
JAIL_COLOR = "#808080" | ||
JAIL_SHAPE = "rect" | ||
|
||
|
||
def citizen_cop_portrayal(agent): | ||
portrayal = { | ||
"Shape": "circle", | ||
"x": agent.pos[0], | ||
"y": agent.pos[1], | ||
"Filled": "true", | ||
} | ||
|
||
if isinstance(agent, Citizen): | ||
color = ( | ||
AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR | ||
) | ||
color = JAIL_COLOR if agent.jail_sentence else color | ||
shape = JAIL_SHAPE if agent.jail_sentence else "circle" | ||
portrayal["color"] = color | ||
portrayal["Shape"] = shape | ||
# TODO add marker to SolaraViz to display rectangle. | ||
portrayal["size"] = 0.5 | ||
portrayal["Filled"] = "false" | ||
|
||
else: | ||
assert isinstance(agent, Cop) | ||
portrayal["color"] = COP_COLOR | ||
portrayal["size"] = 0.9 | ||
|
||
return portrayal | ||
|
||
|
||
model_params = { | ||
"height": 40, | ||
"width": 40, | ||
"citizen_density": Slider("Initial Agent Density", 0.7, 0.0, 0.9, 0.1), | ||
"cop_density": Slider("Initial Cop Density", 0.04, 0.0, 0.1, 0.01), | ||
"citizen_vision": Slider("Citizen Vision", 7, 1, 10, 1), | ||
"cop_vision": Slider("Cop Vision", 7, 1, 10, 1), | ||
"legitimacy": Slider("Government Legitimacy", 0.82, 0.0, 1, 0.01), | ||
"max_jail_term": Slider("Max Jail Term", 30, 0, 50, 1), | ||
} | ||
page = SolaraViz( | ||
EpsteinCivilViolence, | ||
model_params, | ||
measures=[{"Quiescent": "#648FFF", "Active": "#FE6100", "Jailed": "#808080"}], | ||
agent_portrayal=citizen_cop_portrayal, | ||
) | ||
page # noqa |
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.
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.
This API is awkward. It is better to use instead
lambda a: a.pos[0]
. But this meansAgentSet
needs to have the feature of.apply()
along the line of DataFrame's apply.This also means that the new
DataCollector
heavily relies onAgentSet
in order to remain simple. Simple is good.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.
I think @quaquel was also thinking in this direction: projectmesa/mesa#1944 (comment)
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.
I am back in office and do have some time. However, I lot has been happening wrt to MESA so @EwoutH if you have 30 minutes to bring me up to speed, I am happy to take a look at the apply idea.
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.
Good to hear! Let me get back to you what works.
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.
@quaquel would tomorrow early afternoon work?
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.
yes, just email me a time and place (online or my office)