Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: model name in visualization tutorial #2591

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/tutorials/visualization_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model1 = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
"money_model = MoneyModel(n=50, width=10, height=10) #keyword arguments\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")\n",
"\n",
"page = SolaraViz(\n",
" model1,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -207,13 +207,13 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model = MoneyModel(n=50, width=10, height=10)\n",
"money_model = MoneyModel(n=50, width=10, height=10)\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")\n",
"\n",
"page = SolaraViz(\n",
" model1,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -318,7 +318,7 @@
"outputs": [],
"source": [
"# Create initial model instance\n",
"model = MoneyModel(n=50, width=10, height=10)\n",
"money_model = MoneyModel(n=50, width=10, height=10)\n",
"\n",
"SpaceGraph = make_space_component(agent_portrayal)\n",
"GiniPlot = make_plot_component(\"Gini\")"
Expand Down Expand Up @@ -354,7 +354,7 @@
],
"source": [
"page = SolaraViz(\n",
" model,\n",
" money_model,\n",
" components=[SpaceGraph, GiniPlot, Histogram],\n",
" model_params=model_params,\n",
" name=\"Boltzmann Wealth Model\",\n",
Expand Down Expand Up @@ -399,7 +399,7 @@
}
],
"source": [
"Histogram(model)"
"Histogram(money_model)"
]
},
{
Expand Down
27 changes: 18 additions & 9 deletions mesa/examples/advanced/pd_grid/analysis.ipynb

Large diffs are not rendered by default.

78 changes: 42 additions & 36 deletions mesa/examples/basic/schelling/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"\n",
"%matplotlib inline\n",
"\n",
"from model import Schelling"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -38,10 +38,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": "model = Schelling(height=10, width=10, homophily=3, density=0.8, minority_pc=0.2)",
"outputs": [],
"execution_count": null
"source": [
"schelling_model = Schelling(\n",
" height=10, width=10, homophily=3, density=0.8, minority_pc=0.2\n",
")"
]
},
{
"cell_type": "markdown",
Expand All @@ -52,14 +56,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"while model.running and model.steps < 100:\n",
" model.step()\n",
"print(model.steps) # Show how many steps have actually run"
],
"outputs": [],
"execution_count": null
"source": [
"while schelling_model.running and schelling_model.steps < 100:\n",
" schelling_model.step()\n",
"print(schelling_model.steps) # Show how many steps have actually run"
]
},
{
"cell_type": "markdown",
Expand All @@ -70,21 +74,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"model_out = model.datacollector.get_model_vars_dataframe()"
],
"outputs": [],
"execution_count": null
"source": [
"model_out = schelling_model.datacollector.get_model_vars_dataframe()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_out.head()"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -95,12 +99,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"model_out.happy.plot()"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "markdown",
Expand All @@ -115,10 +119,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": "from mesa.batchrunner import batch_run",
"outputs": [],
"execution_count": null
"source": [
"from mesa.batchrunner import batch_run"
]
},
{
"cell_type": "markdown",
Expand All @@ -129,52 +135,52 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fixed_params = {\"height\": 10, \"width\": 10, \"density\": 0.8, \"minority_pc\": 0.2}\n",
"variable_parms = {\"homophily\": range(1, 9)}\n",
"all_params = fixed_params | variable_parms"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results = batch_run(\n",
" Schelling,\n",
" parameters=all_params,\n",
" iterations=10,\n",
" max_steps=200,\n",
")"
],
"outputs": [],
"execution_count": null
]
},
{
"metadata": {},
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(results)\n",
"df"
],
"outputs": [],
"execution_count": null
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.scatter(df.homophily, df.happy)\n",
"plt.xlabel(\"Homophily\")\n",
"plt.ylabel(\"Happy Agents\")\n",
"plt.grid()\n",
"plt.title(\"Effect of Homophily on segregation\")\n",
"plt.show()"
],
"outputs": [],
"execution_count": null
]
}
],
"metadata": {
Expand Down
Loading