{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Running simulations using Pop2net\n", "\n", "In the previous part of this introduction, we have learned how to use Pop2net to build, evaluate and export networks.\n", "In the following part of this introduction, we will learn how to use Pop2net to directly run a simulation based on the defined network.\n", "To perform simulations, Pop2net relies on [AgentPy](https://agentpy.readthedocs.io/en/latest/#) - a general ABM framework.\n", "We recommend you to familiarize yourself with AgentPy first, as only some aspects of AgentPy are covered in this introduction.\n", "\n", "In the following, we programme a simple infection simulation as an example of how to use pop2net to run simulations." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "# this is a hidden cell which sets seeds for consistent outputs\n", "\n", "import random\n", "\n", "import numpy as np\n", "\n", "random.seed(0)\n", "np.random.seed(0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## DataFaker\n", "\n", "In the previous example, we used example data to create the population of agents.\n", "In this example, we also use *fake* data, but this time we use a data generator provided by Pop2net to generate the data.\n", "The DataFaker creates a data set of any size, which is similar to a classic survey data set.\n", "`pop2net.data_fakers.soep_faker` creates data similiar to the [German Socio-Economic Panel](https://www.diw.de/en/diw_01.c.678568.en/research_data_center_soep.html).\n", "\n", "We start by creating a dataset of 1000 rows:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | age | \n", "gender | \n", "work_hours_day | \n", "nace2_division | \n", "hid | \n", "pid | \n", "
---|---|---|---|---|---|---|
0 | \n", "74.0 | \n", "female | \n", "0.000000 | \n", "-2 | \n", "1434 | \n", "2344 | \n", "
1 | \n", "31.0 | \n", "female | \n", "7.473384 | \n", "87 | \n", "1434 | \n", "695 | \n", "
2 | \n", "24.0 | \n", "male | \n", "0.396244 | \n", "1 | \n", "1434 | \n", "2077 | \n", "
3 | \n", "77.0 | \n", "female | \n", "0.000000 | \n", "-2 | \n", "5711 | \n", "346 | \n", "
4 | \n", "26.0 | \n", "female | \n", "0.000000 | \n", "-2 | \n", "5711 | \n", "5288 | \n", "
\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"start | \\n: | \\n@start | \\n \\n
end | \\n: | \\n@end | \\n \\n
weight | \\n: | \\n@weight | \\n \\n
index | \\n: | \\n@index | \\n \\n
type | \\n: | \\n@type | \\n \\n
label | \\n: | \\n@label | \\n \\n
\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"start | \\n: | \\n@start | \\n \\n
end | \\n: | \\n@end | \\n \\n
weight | \\n: | \\n@weight | \\n \\n
index | \\n: | \\n@index | \\n \\n
type | \\n: | \\n@type | \\n \\n