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