You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,13 +88,13 @@ pip install -e .
88
88
89
89
### Creation of an Agent
90
90
91
-
The agent implementation differs from base mesa. Agents are only defined at the AgentSet level. You can import `AgentSetPolars`. As in mesa, you subclass and make sure to call `super().__init__(model)`. You can use the `add` method or the `+=` operator to add agents to the AgentSet. Most methods mirror the functionality of `mesa.AgentSet`. Additionally, `mesa-frames.AgentSet` implements many dunder methods such as `AgentSet[mask, attr]` to get and set items intuitively. All operations are by default inplace, but if you'd like to use functional programming, mesa-frames implements a fast copy method which aims to reduce memory usage, relying on reference-only and native copy methods.
91
+
The agent implementation differs from base mesa. Agents are only defined at the AgentSet level. You can import `AgentSet`. As in mesa, you subclass and make sure to call `super().__init__(model)`. You can use the `add` method or the `+=` operator to add agents to the AgentSet. Most methods mirror the functionality of `mesa.AgentSet`. Additionally, `mesa-frames.AgentSet` implements many dunder methods such as `AgentSet[mask, attr]` to get and set items intuitively. All operations are by default inplace, but if you'd like to use functional programming, mesa-frames implements a fast copy method which aims to reduce memory usage, relying on reference-only and native copy methods.
92
92
93
93
```python
94
-
from mesa-frames importAgentSetPolars
94
+
from mesa-frames importAgentSet
95
95
96
-
classMoneyAgentPolars(AgentSetPolars):
97
-
def__init__(self, n: int, model: ModelDF):
96
+
classMoneyAgents(AgentSet):
97
+
def__init__(self, n: int, model: Model):
98
98
super().__init__(model)
99
99
# Adding the agents to the agent set
100
100
self+= pl.DataFrame(
@@ -126,20 +126,20 @@ class MoneyAgentPolars(AgentSetPolars):
126
126
127
127
### Creation of the Model
128
128
129
-
Creation of the model is fairly similar to the process in mesa. You subclass `ModelDF` and call `super().__init__()`. The `model.agents` attribute has the same interface as `mesa-frames.AgentSet`. You can use `+=` or `self.agents.add` with a `mesa-frames.AgentSet` (or a list of `AgentSet`) to add agents to the model.
129
+
Creation of the model is fairly similar to the process in mesa. You subclass `Model` and call `super().__init__()`. The `model.sets` attribute has the same interface as `mesa-frames.AgentSet`. You can use `+=` or `self.sets.add` with a `mesa-frames.AgentSet` (or a list of `AgentSet`) to add agents to the model.
130
130
131
131
```python
132
-
from mesa-frames importModelDF
132
+
from mesa-frames importModel
133
133
134
-
classMoneyModelDF(ModelDF):
134
+
classMoneyModelDF(Model):
135
135
def__init__(self, N: int, agents_cls):
136
136
super().__init__()
137
137
self.n_agents = N
138
-
self.agents+=MoneyAgentPolars(N, self)
138
+
self.sets+=MoneyAgents(N, self)
139
139
140
140
defstep(self):
141
-
# Executes the step method for every agentset in self.agents
142
-
self.agents.do("step")
141
+
# Executes the step method for every agentset in self.sets
To create your own AgentSetDF class, you need to subclass the AgentSetPolars class and make sure to call `super().__init__(model)`.
5
+
To create your own AgentSet class, you need to subclass the AgentSet class and make sure to call `super().__init__(model)`.
6
6
7
-
Typically, the next step would be to populate the class with your agents. To do that, you need to add a DataFrame to the AgentSetDF. You can do `self += agents` or `self.add(agents)`, where `agents` is a DataFrame or something that could be passed to a DataFrame constructor, like a dictionary or lists of lists. You need to make sure your DataFrame doesn't have a 'unique_id' column because IDs are generated automatically, otherwise you will get an error raised. In the DataFrame, you should also put any attribute of the agent you are using.
7
+
Typically, the next step would be to populate the class with your agents. To do that, you need to add a DataFrame to the AgentSet. You can do `self += agents` or `self.add(agents)`, where `agents` is a DataFrame or something that could be passed to a DataFrame constructor, like a dictionary or lists of lists. You need to make sure your DataFrame doesn't have a 'unique_id' column because IDs are generated automatically, otherwise you will get an error raised. In the DataFrame, you should also put any attribute of the agent you are using.
8
8
9
9
How can you choose which agents should be in the same AgentSet? The idea is that you should minimize the missing values in the DataFrame (so they should have similar/same attributes) and mostly everybody should do the same actions.
10
10
11
11
Example:
12
12
13
13
```python
14
-
classMoneyAgent(AgentSetPolars):
15
-
def__init__(self, n: int, model: ModelDF):
14
+
classMoneyAgents(AgentSet):
15
+
def__init__(self, n: int, model: Model):
16
16
super().__init__(model)
17
17
self.initial_wealth = pl.ones(n)
18
18
self+= pl.DataFrame({
@@ -25,28 +25,28 @@ class MoneyAgent(AgentSetPolars):
25
25
26
26
You can access the underlying DataFrame where agents are stored with `self.df`. This allows you to use DataFrame methods like `self.df.sample` or `self.df.group_by("wealth")` and more.
27
27
28
-
## ModelDF 🏗️
28
+
## Model 🏗️
29
29
30
-
To add your AgentSetDF to your ModelDF, you should also add it to the agents with `+=` or `add`.
30
+
To add your AgentSet to your Model, you should also add it to the sets with `+=` or `add`.
31
31
32
-
NOTE: ModelDF.agents are stored in a class which is entirely similar to AgentSetDF called AgentsDF. The API of the two are the same. If you try accessing AgentsDF.df, you will get a dictionary of `[AgentSetDF, DataFrame]`.
32
+
NOTE: Model.sets are stored in a class which is entirely similar to AgentSet called AgentSetRegistry. The API of the two are the same. If you try accessing AgentSetRegistry.df, you will get a dictionary of `[AgentSet, DataFrame]`.
33
33
34
34
Example:
35
35
36
36
```python
37
-
classEcosystemModel(ModelDF):
37
+
classEcosystemModel(Model):
38
38
def__init__(self, n_prey, n_predators):
39
39
super().__init__()
40
-
self.agents+= Preys(n_prey, self)
41
-
self.agents+= Predators(n_predators, self)
40
+
self.sets+= Preys(n_prey, self)
41
+
self.sets+= Predators(n_predators, self)
42
42
43
43
defstep(self):
44
-
self.agents.do("move")
45
-
self.agents.do("hunt")
44
+
self.sets.do("move")
45
+
self.sets.do("hunt")
46
46
self.prey.do("reproduce")
47
47
```
48
48
49
-
## Space: GridDF 🌐
49
+
## Space: Grid 🌐
50
50
51
51
mesa-frames provides efficient implementations of spatial environments:
0 commit comments