Skip to content

Commit 37f89d3

Browse files
committed
Explicit datacollector import
Use from mesa.datacollection import DataCollector
1 parent de9e87f commit 37f89d3

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

benchmarks/BoltzmannWealth/boltzmann_wealth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import mesa
7+
from mesa.datacollection import DataCollector
78

89

910
def compute_gini(model):
@@ -44,7 +45,7 @@ def __init__(self, seed=None, n=100, width=10, height=10):
4445
self.num_agents = n
4546
self.grid = mesa.space.MultiGrid(width, height, True)
4647
self.schedule = mesa.time.RandomActivation(self)
47-
self.datacollector = mesa.DataCollector(
48+
self.datacollector = DataCollector(
4849
model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"}
4950
)
5051
# Create agents

docs/overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ You'd add a data collector to the model like this:
7171

7272
```python
7373
import mesa
74+
from mesa.datacollection import DataCollector
7475

7576
# ...
7677

7778
class MyModel(mesa.Model):
7879
def __init__(self, n_agents):
7980
# ...
80-
self.dc = mesa.DataCollector(model_reporters={"agent_count":
81+
self.dc = DataCollector(model_reporters={"agent_count":
8182
lambda m: m.schedule.get_agent_count()},
8283
agent_reporters={"name": lambda a: a.name})
8384

docs/tutorials/MoneyModel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""a simple version of the boltman wealth model"""
22

33
import mesa
4+
from mesa.datacollection import DataCollector
45

56

67
def compute_gini(model):
@@ -71,7 +72,7 @@ def __init__(self, N, width, height):
7172
y = self.random.randrange(self.grid.height)
7273
self.grid.place_agent(a, (x, y))
7374

74-
self.datacollector = mesa.DataCollector(
75+
self.datacollector = DataCollector(
7576
model_reporters={"Gini": compute_gini}, agent_reporters={"Wealth": "wealth"}
7677
)
7778

docs/tutorials/intro_tutorial.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"outputs": [],
154154
"source": [
155155
"import mesa\n",
156+
"from mesa.datacollection import DataCollector\n",
156157
"\n",
157158
"# Data visualization tools.\n",
158159
"import seaborn as sns\n",
@@ -751,7 +752,7 @@
751752
"\n",
752753
"The data collector stores three categories of data: model-level variables, agent-level variables, and tables (which are a catch-all for everything else). Model- and agent-level variables are added to the data collector along with a function for collecting them. Model-level collection functions take a model object as an input, while agent-level collection functions take an agent object as an input. Both then return a value computed from the model or each agent at their current state. When the data collector’s `collect` method is called, with a model object as its argument, it applies each model-level collection function to the model, and stores the results in a dictionary, associating the current value with the current step of the model. Similarly, the method applies each agent-level collection function to each agent currently in the schedule, associating the resulting value with the step of the model, and the agent’s `unique_id`.\n",
753754
"\n",
754-
"Let's add a DataCollector to the model with [`mesa.DataCollector`](https://github.com/projectmesa/mesa/blob/main/mesa/datacollection.py), and collect two variables. At the agent level, we want to collect every agent's wealth at every step. At the model level, let's measure the model's [Gini Coefficient](https://en.wikipedia.org/wiki/Gini_coefficient), a measure of wealth inequality."
755+
"Let's add a [`DataCollector`](https://github.com/projectmesa/mesa/blob/main/mesa/datacollection.py) to the model and collect two variables. At the agent level, we want to collect every agent's wealth at every step. At the model level, let's measure the model's [Gini Coefficient](https://en.wikipedia.org/wiki/Gini_coefficient), a measure of wealth inequality."
755756
]
756757
},
757758
{
@@ -818,7 +819,7 @@
818819
" y = self.random.randrange(self.grid.height)\n",
819820
" self.grid.place_agent(a, (x, y))\n",
820821
"\n",
821-
" self.datacollector = mesa.DataCollector(\n",
822+
" self.datacollector = DataCollector(\n",
822823
" model_reporters={\"Gini\": compute_gini}, agent_reporters={\"Wealth\": \"wealth\"}\n",
823824
" )\n",
824825
"\n",
@@ -1060,7 +1061,7 @@
10601061
" y = self.random.randrange(self.grid.height)\n",
10611062
" self.grid.place_agent(a, (x, y))\n",
10621063
"\n",
1063-
" self.datacollector = mesa.DataCollector(\n",
1064+
" self.datacollector = DataCollector(\n",
10641065
" model_reporters={\"Gini\": compute_gini},\n",
10651066
" agent_reporters={\"Wealth\": \"wealth\", \"Steps_not_given\": \"steps_not_given\"},\n",
10661067
" )\n",

0 commit comments

Comments
 (0)