|
66 | 66 | "pip install --upgrade mesa\n", |
67 | 67 | "```\n", |
68 | 68 | "\n", |
| 69 | + "If you want to use our newest features, you can also opt to install our latest pre-release version:\n", |
| 70 | + "\n", |
| 71 | + "```bash\n", |
| 72 | + "pip install --upgrade --pre mesa\n", |
| 73 | + "```\n", |
| 74 | + "\n", |
69 | 75 | "Install Jupyter Notebook (optional):\n", |
70 | 76 | "\n", |
71 | 77 | "```bash\n", |
|
1209 | 1215 | }, |
1210 | 1216 | { |
1211 | 1217 | "cell_type": "markdown", |
1212 | | - "source": [ |
1213 | | - "We can create different kinds of plot from this filtered DataFrame. For example, a point plot with error bars." |
1214 | | - ], |
1215 | 1218 | "metadata": { |
1216 | 1219 | "collapsed": false |
1217 | | - } |
| 1220 | + }, |
| 1221 | + "source": [ |
| 1222 | + "We can create different kinds of plot from this filtered DataFrame. For example, a point plot with error bars." |
| 1223 | + ] |
1218 | 1224 | }, |
1219 | 1225 | { |
1220 | 1226 | "cell_type": "code", |
| 1227 | + "execution_count": null, |
| 1228 | + "metadata": { |
| 1229 | + "collapsed": false |
| 1230 | + }, |
1221 | 1231 | "outputs": [], |
1222 | 1232 | "source": [ |
1223 | 1233 | "# Create a point plot with error bars\n", |
|
1228 | 1238 | " ylabel=\"Gini coefficient\",\n", |
1229 | 1239 | " title=\"Gini coefficient vs. number of agents\",\n", |
1230 | 1240 | ");" |
1231 | | - ], |
1232 | | - "metadata": { |
1233 | | - "collapsed": false |
1234 | | - }, |
1235 | | - "execution_count": null |
| 1241 | + ] |
1236 | 1242 | }, |
1237 | 1243 | { |
1238 | 1244 | "cell_type": "markdown", |
|
1284 | 1290 | }, |
1285 | 1291 | { |
1286 | 1292 | "cell_type": "markdown", |
| 1293 | + "metadata": { |
| 1294 | + "collapsed": false |
| 1295 | + }, |
1287 | 1296 | "source": [ |
1288 | 1297 | "### Analyzing model reporters: Comparing 5 scenarios\n", |
1289 | 1298 | "Other insights might be gathered when we compare the Gini coefficient of different scenarios. For example, we can compare the Gini coefficient of a population with 25 agents to the Gini coefficient of a population with 400 agents. While doing this, we increase the number of iterations to 25 to get a better estimate of the Gini coefficient for each population size and get usable error estimations." |
1290 | | - ], |
1291 | | - "metadata": { |
1292 | | - "collapsed": false |
1293 | | - } |
| 1299 | + ] |
1294 | 1300 | }, |
1295 | 1301 | { |
1296 | 1302 | "cell_type": "code", |
| 1303 | + "execution_count": null, |
| 1304 | + "metadata": { |
| 1305 | + "collapsed": false |
| 1306 | + }, |
1297 | 1307 | "outputs": [], |
1298 | 1308 | "source": [ |
1299 | 1309 | "params = {\"width\": 10, \"height\": 10, \"N\": [5, 10, 20, 40, 80]}\n", |
|
1309 | 1319 | ")\n", |
1310 | 1320 | "\n", |
1311 | 1321 | "results_5s_df = pd.DataFrame(results_5s)" |
1312 | | - ], |
1313 | | - "metadata": { |
1314 | | - "collapsed": false |
1315 | | - }, |
1316 | | - "execution_count": null |
| 1322 | + ] |
1317 | 1323 | }, |
1318 | 1324 | { |
1319 | 1325 | "cell_type": "code", |
| 1326 | + "execution_count": null, |
| 1327 | + "metadata": { |
| 1328 | + "collapsed": false |
| 1329 | + }, |
1320 | 1330 | "outputs": [], |
1321 | 1331 | "source": [ |
1322 | 1332 | "# Again filter the results to only contain the data of one agent (the Gini coefficient will be the same for the entire population at any time)\n", |
1323 | 1333 | "results_5s_df_filtered = results_5s_df[(results_5s_df.AgentID == 0)]\n", |
1324 | 1334 | "results_5s_df_filtered.head(3)" |
1325 | | - ], |
1326 | | - "metadata": { |
1327 | | - "collapsed": false |
1328 | | - }, |
1329 | | - "execution_count": null |
| 1335 | + ] |
1330 | 1336 | }, |
1331 | 1337 | { |
1332 | 1338 | "cell_type": "code", |
| 1339 | + "execution_count": null, |
| 1340 | + "metadata": { |
| 1341 | + "collapsed": false |
| 1342 | + }, |
1333 | 1343 | "outputs": [], |
1334 | 1344 | "source": [ |
1335 | 1345 | "# Create a lineplot with error bars\n", |
|
1344 | 1354 | "g.figure.set_size_inches(8, 4)\n", |
1345 | 1355 | "plot_title = \"Gini coefficient for different population sizes\\n(mean over 100 runs, with 95% confidence interval)\"\n", |
1346 | 1356 | "g.set(title=plot_title, ylabel=\"Gini coefficient\");" |
1347 | | - ], |
1348 | | - "metadata": { |
1349 | | - "collapsed": false |
1350 | | - }, |
1351 | | - "execution_count": null |
| 1357 | + ] |
1352 | 1358 | }, |
1353 | 1359 | { |
1354 | 1360 | "cell_type": "markdown", |
1355 | | - "source": [ |
1356 | | - "In this case it looks like the Gini coefficient increases slower for smaller populations. This can be because of different things, either because the Gini coefficient is a measure of inequality and the smaller the population, the more likely it is that the agents are all in the same wealth class, or because there are less interactions between agents in smaller populations, which means that the wealth of an agent is less likely to change." |
1357 | | - ], |
1358 | 1361 | "metadata": { |
1359 | 1362 | "collapsed": false |
1360 | | - } |
| 1363 | + }, |
| 1364 | + "source": [ |
| 1365 | + "In this case it looks like the Gini coefficient increases slower for smaller populations. This can be because of different things, either because the Gini coefficient is a measure of inequality and the smaller the population, the more likely it is that the agents are all in the same wealth class, or because there are less interactions between agents in smaller populations, which means that the wealth of an agent is less likely to change." |
| 1366 | + ] |
1361 | 1367 | }, |
1362 | 1368 | { |
1363 | 1369 | "cell_type": "markdown", |
| 1370 | + "metadata": { |
| 1371 | + "collapsed": false |
| 1372 | + }, |
1364 | 1373 | "source": [ |
1365 | 1374 | "### Analyzing agent reporters\n", |
1366 | 1375 | "From the agents we collected the wealth and the number of consecutive rounds without a transaction. We can compare the 5 different population sizes by plotting the average number of consecutive rounds without a transaction for each population size.\n", |
1367 | 1376 | "\n", |
1368 | 1377 | "Note that we're aggregating multiple times here: First we take the average of all agents for each single replication. Then we plot the averages for all replications, with the error band showing the 95% confidence interval of that first average (over all agents). So this error band is representing the uncertainty of the mean value of the number of consecutive rounds without a transaction for each population size." |
1369 | | - ], |
1370 | | - "metadata": { |
1371 | | - "collapsed": false |
1372 | | - } |
| 1378 | + ] |
1373 | 1379 | }, |
1374 | 1380 | { |
1375 | 1381 | "cell_type": "code", |
| 1382 | + "execution_count": null, |
| 1383 | + "metadata": { |
| 1384 | + "collapsed": false |
| 1385 | + }, |
1376 | 1386 | "outputs": [], |
1377 | 1387 | "source": [ |
1378 | 1388 | "# Calculate the mean of the wealth and the number of consecutive rounds for all agents in each episode\n", |
|
1382 | 1392 | " .reset_index()\n", |
1383 | 1393 | ")\n", |
1384 | 1394 | "agg_results_df.head(3)" |
1385 | | - ], |
1386 | | - "metadata": { |
1387 | | - "collapsed": false |
1388 | | - }, |
1389 | | - "execution_count": null |
| 1395 | + ] |
1390 | 1396 | }, |
1391 | 1397 | { |
1392 | 1398 | "cell_type": "code", |
| 1399 | + "execution_count": null, |
| 1400 | + "metadata": { |
| 1401 | + "collapsed": false |
| 1402 | + }, |
1393 | 1403 | "outputs": [], |
1394 | 1404 | "source": [ |
1395 | 1405 | "# Create a line plot with error bars\n", |
|
1401 | 1411 | " title=\"Average number of consecutive rounds without a transaction for different population sizes\\n(mean with 95% confidence interval)\",\n", |
1402 | 1412 | " ylabel=\"Consecutive rounds without a transaction\",\n", |
1403 | 1413 | ");" |
1404 | | - ], |
1405 | | - "metadata": { |
1406 | | - "collapsed": false |
1407 | | - }, |
1408 | | - "execution_count": null |
| 1414 | + ] |
1409 | 1415 | }, |
1410 | 1416 | { |
1411 | 1417 | "cell_type": "markdown", |
1412 | | - "source": [ |
1413 | | - "It can be clearly seen that the lower the number of agents, the higher the number of consecutive rounds without a transaction. This is because the agents have fewer interactions with each other and therefore the wealth of an agent is less likely to change." |
1414 | | - ], |
1415 | 1418 | "metadata": { |
1416 | 1419 | "collapsed": false |
1417 | | - } |
| 1420 | + }, |
| 1421 | + "source": [ |
| 1422 | + "It can be clearly seen that the lower the number of agents, the higher the number of consecutive rounds without a transaction. This is because the agents have fewer interactions with each other and therefore the wealth of an agent is less likely to change." |
| 1423 | + ] |
1418 | 1424 | }, |
1419 | 1425 | { |
1420 | 1426 | "cell_type": "markdown", |
| 1427 | + "metadata": { |
| 1428 | + "collapsed": false |
| 1429 | + }, |
1421 | 1430 | "source": [ |
1422 | 1431 | "#### General steps for analyzing results\n", |
1423 | 1432 | "\n", |
|
1430 | 1439 | "5. Transform, filter and aggregate the results to get the data you want to analyze. Make sure it's in long format, so that each row represents a single value.\n", |
1431 | 1440 | "6. Choose a plot type, what to plot on the x and y axis, which columns to use for the hue. Seaborn also has an amazing [Example Gallery](https://seaborn.pydata.org/examples/index.html).\n", |
1432 | 1441 | "7. Plot the data and analyze the results." |
1433 | | - ], |
1434 | | - "metadata": { |
1435 | | - "collapsed": false |
1436 | | - } |
| 1442 | + ] |
1437 | 1443 | }, |
1438 | 1444 | { |
1439 | 1445 | "cell_type": "markdown", |
|
0 commit comments