|
153 | 153 | "outputs": [], |
154 | 154 | "source": [ |
155 | 155 | "import mesa\n", |
| 156 | + "from mesa.datacollection import DataCollector\n", |
156 | 157 | "\n", |
157 | 158 | "# Data visualization tools.\n", |
158 | 159 | "import seaborn as sns\n", |
|
751 | 752 | "\n", |
752 | 753 | "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", |
753 | 754 | "\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." |
755 | 756 | ] |
756 | 757 | }, |
757 | 758 | { |
|
818 | 819 | " y = self.random.randrange(self.grid.height)\n", |
819 | 820 | " self.grid.place_agent(a, (x, y))\n", |
820 | 821 | "\n", |
821 | | - " self.datacollector = mesa.DataCollector(\n", |
| 822 | + " self.datacollector = DataCollector(\n", |
822 | 823 | " model_reporters={\"Gini\": compute_gini}, agent_reporters={\"Wealth\": \"wealth\"}\n", |
823 | 824 | " )\n", |
824 | 825 | "\n", |
|
1060 | 1061 | " y = self.random.randrange(self.grid.height)\n", |
1061 | 1062 | " self.grid.place_agent(a, (x, y))\n", |
1062 | 1063 | "\n", |
1063 | | - " self.datacollector = mesa.DataCollector(\n", |
| 1064 | + " self.datacollector = DataCollector(\n", |
1064 | 1065 | " model_reporters={\"Gini\": compute_gini},\n", |
1065 | 1066 | " agent_reporters={\"Wealth\": \"wealth\", \"Steps_not_given\": \"steps_not_given\"},\n", |
1066 | 1067 | " )\n", |
|
0 commit comments