Skip to content

Commit 2439a1f

Browse files
fix: model name in visualization tutorial (projectmesa#2591)
Updated the model name to a more descriptive name in visualization tutorial
1 parent f751651 commit 2439a1f

File tree

3 files changed

+67
-52
lines changed

3 files changed

+67
-52
lines changed

docs/tutorials/visualization_tutorial.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@
128128
"outputs": [],
129129
"source": [
130130
"# Create initial model instance\n",
131-
"model1 = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
131+
"money_model = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
132132
"\n",
133133
"SpaceGraph = make_space_component(agent_portrayal)\n",
134134
"GiniPlot = make_plot_component(\"Gini\")\n",
135135
"\n",
136136
"page = SolaraViz(\n",
137-
" model1,\n",
137+
" money_model,\n",
138138
" components=[SpaceGraph, GiniPlot],\n",
139139
" model_params=model_params,\n",
140140
" name=\"Boltzmann Wealth Model\",\n",
@@ -207,13 +207,13 @@
207207
"outputs": [],
208208
"source": [
209209
"# Create initial model instance\n",
210-
"model = MoneyModel(n=50, width=10, height=10)\n",
210+
"money_model = MoneyModel(n=50, width=10, height=10)\n",
211211
"\n",
212212
"SpaceGraph = make_space_component(agent_portrayal)\n",
213213
"GiniPlot = make_plot_component(\"Gini\")\n",
214214
"\n",
215215
"page = SolaraViz(\n",
216-
" model1,\n",
216+
" money_model,\n",
217217
" components=[SpaceGraph, GiniPlot],\n",
218218
" model_params=model_params,\n",
219219
" name=\"Boltzmann Wealth Model\",\n",
@@ -318,7 +318,7 @@
318318
"outputs": [],
319319
"source": [
320320
"# Create initial model instance\n",
321-
"model = MoneyModel(n=50, width=10, height=10)\n",
321+
"money_model = MoneyModel(n=50, width=10, height=10)\n",
322322
"\n",
323323
"SpaceGraph = make_space_component(agent_portrayal)\n",
324324
"GiniPlot = make_plot_component(\"Gini\")"
@@ -354,7 +354,7 @@
354354
],
355355
"source": [
356356
"page = SolaraViz(\n",
357-
" model,\n",
357+
" money_model,\n",
358358
" components=[SpaceGraph, GiniPlot, Histogram],\n",
359359
" model_params=model_params,\n",
360360
" name=\"Boltzmann Wealth Model\",\n",
@@ -399,7 +399,7 @@
399399
}
400400
],
401401
"source": [
402-
"Histogram(model)"
402+
"Histogram(money_model)"
403403
]
404404
},
405405
{

mesa/examples/advanced/pd_grid/analysis.ipynb

Lines changed: 18 additions & 9 deletions
Large diffs are not rendered by default.

mesa/examples/basic/schelling/analysis.ipynb

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
},
1818
{
1919
"cell_type": "code",
20+
"execution_count": null,
2021
"metadata": {},
22+
"outputs": [],
2123
"source": [
2224
"import matplotlib.pyplot as plt\n",
2325
"import pandas as pd\n",
2426
"\n",
2527
"%matplotlib inline\n",
2628
"\n",
2729
"from model import Schelling"
28-
],
29-
"outputs": [],
30-
"execution_count": null
30+
]
3131
},
3232
{
3333
"cell_type": "markdown",
@@ -38,10 +38,14 @@
3838
},
3939
{
4040
"cell_type": "code",
41+
"execution_count": null,
4142
"metadata": {},
42-
"source": "model = Schelling(height=10, width=10, homophily=3, density=0.8, minority_pc=0.2)",
4343
"outputs": [],
44-
"execution_count": null
44+
"source": [
45+
"schelling_model = Schelling(\n",
46+
" height=10, width=10, homophily=3, density=0.8, minority_pc=0.2\n",
47+
")"
48+
]
4549
},
4650
{
4751
"cell_type": "markdown",
@@ -52,14 +56,14 @@
5256
},
5357
{
5458
"cell_type": "code",
59+
"execution_count": null,
5560
"metadata": {},
56-
"source": [
57-
"while model.running and model.steps < 100:\n",
58-
" model.step()\n",
59-
"print(model.steps) # Show how many steps have actually run"
60-
],
6161
"outputs": [],
62-
"execution_count": null
62+
"source": [
63+
"while schelling_model.running and schelling_model.steps < 100:\n",
64+
" schelling_model.step()\n",
65+
"print(schelling_model.steps) # Show how many steps have actually run"
66+
]
6367
},
6468
{
6569
"cell_type": "markdown",
@@ -70,21 +74,21 @@
7074
},
7175
{
7276
"cell_type": "code",
77+
"execution_count": null,
7378
"metadata": {},
74-
"source": [
75-
"model_out = model.datacollector.get_model_vars_dataframe()"
76-
],
7779
"outputs": [],
78-
"execution_count": null
80+
"source": [
81+
"model_out = schelling_model.datacollector.get_model_vars_dataframe()"
82+
]
7983
},
8084
{
8185
"cell_type": "code",
86+
"execution_count": null,
8287
"metadata": {},
88+
"outputs": [],
8389
"source": [
8490
"model_out.head()"
85-
],
86-
"outputs": [],
87-
"execution_count": null
91+
]
8892
},
8993
{
9094
"cell_type": "markdown",
@@ -95,12 +99,12 @@
9599
},
96100
{
97101
"cell_type": "code",
102+
"execution_count": null,
98103
"metadata": {},
104+
"outputs": [],
99105
"source": [
100106
"model_out.happy.plot()"
101-
],
102-
"outputs": [],
103-
"execution_count": null
107+
]
104108
},
105109
{
106110
"cell_type": "markdown",
@@ -115,10 +119,12 @@
115119
},
116120
{
117121
"cell_type": "code",
122+
"execution_count": null,
118123
"metadata": {},
119-
"source": "from mesa.batchrunner import batch_run",
120124
"outputs": [],
121-
"execution_count": null
125+
"source": [
126+
"from mesa.batchrunner import batch_run"
127+
]
122128
},
123129
{
124130
"cell_type": "markdown",
@@ -129,52 +135,52 @@
129135
},
130136
{
131137
"cell_type": "code",
138+
"execution_count": null,
132139
"metadata": {},
140+
"outputs": [],
133141
"source": [
134142
"fixed_params = {\"height\": 10, \"width\": 10, \"density\": 0.8, \"minority_pc\": 0.2}\n",
135143
"variable_parms = {\"homophily\": range(1, 9)}\n",
136144
"all_params = fixed_params | variable_parms"
137-
],
138-
"outputs": [],
139-
"execution_count": null
145+
]
140146
},
141147
{
142148
"cell_type": "code",
149+
"execution_count": null,
143150
"metadata": {},
151+
"outputs": [],
144152
"source": [
145153
"results = batch_run(\n",
146154
" Schelling,\n",
147155
" parameters=all_params,\n",
148156
" iterations=10,\n",
149157
" max_steps=200,\n",
150158
")"
151-
],
152-
"outputs": [],
153-
"execution_count": null
159+
]
154160
},
155161
{
156-
"metadata": {},
157162
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {},
165+
"outputs": [],
158166
"source": [
159167
"df = pd.DataFrame(results)\n",
160168
"df"
161-
],
162-
"outputs": [],
163-
"execution_count": null
169+
]
164170
},
165171
{
166172
"cell_type": "code",
173+
"execution_count": null,
167174
"metadata": {},
175+
"outputs": [],
168176
"source": [
169177
"plt.scatter(df.homophily, df.happy)\n",
170178
"plt.xlabel(\"Homophily\")\n",
171179
"plt.ylabel(\"Happy Agents\")\n",
172180
"plt.grid()\n",
173181
"plt.title(\"Effect of Homophily on segregation\")\n",
174182
"plt.show()"
175-
],
176-
"outputs": [],
177-
"execution_count": null
183+
]
178184
}
179185
],
180186
"metadata": {

0 commit comments

Comments
 (0)