Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamamer20 committed Jan 13, 2024
1 parent 1cd08a5 commit 6247050
Show file tree
Hide file tree
Showing 8 changed files with 1,553 additions and 1,161 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class MyAgent(AgentDF):
def step(cls):
wealthy_agents = cls.model.agents.loc[cls.mask, "wealth"] > 0
if wealthy_agents.any():
#The next line finds the mask of a random sample of agents which ù
is of the same length as wealthy agents
#The next line finds the mask of a random sample of agents which is of the same length as wealthy agents
other_agents = cls.model.agents.index.isin(
cls.model.agents.sample(n=wealthy_agents.sum()).index
)
Expand Down
218 changes: 214 additions & 4 deletions docs/api/index.html

Large diffs are not rendered by default.

422 changes: 184 additions & 238 deletions docs/api/mesa_frames/agent.html

Large diffs are not rendered by default.

1,739 changes: 867 additions & 872 deletions docs/api/mesa_frames/model.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/api/search.js

Large diffs are not rendered by default.

238 changes: 238 additions & 0 deletions docs/api/streetcrime/space.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions mesa_frames/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AgentDF:
"""The AgentDF class is the base class for other agents.
It should be used as inherited class for new agents classes.
Attributes:
Attributes
----------
dtypes : dict[str, str]
The attributes of the Agent as a dictionary of columns and data types. It contains:
Expand Down Expand Up @@ -62,7 +62,7 @@ class GeoAgentDF(AgentDF):
"""The GeoAgentDF extends the AgentDF class to include a geometry attribute.
The agents will be stored in a GeoDataFrame.
Attributes:
Attributes
----------
dtypes : dict[str, str]
The attributes of the Agent as a dictionary of columns and data types. It contains:
Expand Down
88 changes: 46 additions & 42 deletions mesa_frames/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@


class ModelDF:
"""The base class for all models
Attributes
----------
unique_id : int
The unique_id of the model.
running : bool
Indicates if the model is running or not.
agents : pd.DataFrame | gpd.GeoDataFrame | None
The dataframe containing the agents of the model.
agent_types : list[tuple[type[AgentDF], float]] | None
The list of agent types and their proportions.
p_agents : dict[type[AgentDF], float] | None
The dictionary of agents to create. The keys are the types of agents,
the values are the percentages of each agent type. The sum of the values should be 1.
space
The space where the agents will be placed. Can be None if model does not have a space.
"""

def __new__(cls, *args, **kwargs):
"""Create a new model object and instantiate its RNG automatically
(adds supports to numpy with respect to base model)."""
Expand All @@ -35,22 +54,6 @@ def __init__(self, unique_id: int | None = None, space=None):
If None, a random unique_id is assigned using a 64-bit random integer.
space
The space where the agents will be placed. Can be None if model does not have a space.
Attributes
----------
unique_id : int
The unique_id of the model.
running : bool
Indicates if the model is running or not.
agents : pd.DataFrame | gpd.GeoDataFrame | None
The dataframe containing the agents of the model.
agent_types : list[tuple[type[AgentDF], float]] | None
The list of agent types and their proportions.
p_agents : dict[type[AgentDF], float] | None
The dictionary of agents to create. The keys are the types of agents,
the values are the percentages of each agent type. The sum of the values should be 1.
space
The space where the agents will be placed. Can be None if model does not have a space.
"""
# Initialize default attributes
self.running: bool = True
Expand Down Expand Up @@ -116,7 +119,7 @@ def step(self, merged_mro: bool = False) -> None:
Parameters
----------
merged_mro: bool
merged_mro : bool
If False, the model will execute one step for each class in p_agent. This is the default behaviour.
If True, the model will execute one step for each inherited agent type in the order of a "merged" MRO.
This may increase performance if there are multiple and complex inheritance as each agent_type (even if parents of different classes),
Expand All @@ -136,9 +139,10 @@ def step(self, merged_mro: bool = False) -> None:
def reset_randomizer(self, seed: int | None = None) -> None:
"""Reset the model random number generator.
Parameters:
Parameters
----------
seed: A new seed for the RNG; if None, reset using the current seed
seed : int | None
A new seed for the RNG; if None, reset using the current seed
"""
if seed is None:
seed = self._seed
Expand Down Expand Up @@ -264,29 +268,6 @@ def create_agents(

print("Created agents: " + "--- %s seconds ---" % (time() - start_time))

# TODO: implement different data collection frequencies (xw, xd, xh, weekly, daily, hourly, per every step):
"""def initialize_data_collector(
self,
model_reporters=None,
agent_reporters=None,
tables=None,
) -> None:
if not hasattr(self, "schedule") or self.schedule is None:
raise RuntimeError(
"You must initialize the scheduler (self.schedule) before initializing the data collector."
)
if self.schedule.get_agent_count() == 0:
raise RuntimeError(
"You must add agents to the scheduler before initializing the data collector."
)
self.datacollector = DataCollector(
model_reporters=model_reporters,
agent_reporters=agent_reporters,
tables=tables,
)
# Collect data for the first time during initialization.
self.datacollector.collect(self)"""

def _initialize_data_collection(self, how="2d") -> None:
"""Initializes the data collection of the model.
Expand All @@ -309,3 +290,26 @@ def update_agents_masks(self) -> None:
)
for agent_type in self.agent_types:
agent_type[0].mask = self.get_agents_of_type(agent_type[0])

# TODO: implement different data collection frequencies (xw, xd, xh, weekly, daily, hourly, per every step):
"""def initialize_data_collector(
self,
model_reporters=None,
agent_reporters=None,
tables=None,
) -> None:
if not hasattr(self, "schedule") or self.schedule is None:
raise RuntimeError(
"You must initialize the scheduler (self.schedule) before initializing the data collector."
)
if self.schedule.get_agent_count() == 0:
raise RuntimeError(
"You must add agents to the scheduler before initializing the data collector."
)
self.datacollector = DataCollector(
model_reporters=model_reporters,
agent_reporters=agent_reporters,
tables=tables,
)
# Collect data for the first time during initialization.
self.datacollector.collect(self)"""

0 comments on commit 6247050

Please sign in to comment.