2017-10-18 18:28:42 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-10-19T12:41:48.007238Z",
"start_time": "2017-10-19T14:41:47.980725+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"# Soil Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-02T16:44:14.120953Z",
"start_time": "2017-07-02T18:44:14.117152+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"## Introduction"
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_style": "center",
2023-04-20 15:56:44 +00:00
"collapsed": true,
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"This notebook is an introduction to the soil agent-based social network simulation framework.\n",
2023-04-24 16:46:09 +00:00
"It will focus on a specific use case: studying the propagation of disinformation through TV and social networks.\n",
"\n",
2017-10-18 18:28:42 +00:00
"\n",
"The steps we will follow are:\n",
"\n",
2023-04-24 16:46:09 +00:00
"* Cover some basics about simulations in Soil (environments, agents, etc.)\n",
"* Simulate a basic scenario with a single agent\n",
"* Add more complexity to our scenario\n",
2017-10-18 18:28:42 +00:00
"* Running the simulation using different configurations\n",
2023-04-24 16:46:09 +00:00
"* Analysing the results of each simulation\n",
"\n",
"The simulations in this tutorial will be kept simple, for the sake of clarity.\n",
"However, they provide all the building blocks necessary to model, run and analyse more complex scenarios."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T13:38:48.052876Z",
"start_time": "2017-07-03T15:38:48.044762+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"But before that, let's import the soil module and networkx."
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 64,
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2018-05-04 08:01:49 +00:00
"end_time": "2017-11-03T10:58:13.451481Z",
"start_time": "2017-11-03T11:58:12.643469+01:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-03-23 13:49:09 +00:00
"outputs": [],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"from soil import *\n",
2023-05-03 10:14:49 +00:00
"from soil import analysis\n",
2017-10-18 18:28:42 +00:00
"import networkx as nx\n",
"\n",
2023-04-20 15:56:44 +00:00
"import matplotlib.pyplot as plt"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T13:41:19.788717Z",
"start_time": "2017-07-03T15:41:19.785448+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"## Basic concepts"
]
},
{
"cell_type": "markdown",
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"There are two main elements in a soil simulation:\n",
2017-10-18 18:28:42 +00:00
" \n",
2023-04-24 16:46:09 +00:00
"* The **environment** or model. It assigns agents to nodes in the network, and stores the environment parameters (shared state for all agents).\n",
2023-04-24 17:23:04 +00:00
" - `soil.NetworkEnvironment` models also contain a network topology (accessible through through `self.G`). A simulation may use an existing NetworkX topology, or generate one on the fly. The `NetworkEnvironment` class is parameterized, which makes it easy to initialize environments with a variety of network topologies. **In this tutorial, we will manually add a network to each environment**.\n",
2023-04-24 16:46:09 +00:00
"* One or more **agents**. Agents are programmed with their individual behaviors, and they can communicate with the environment and with other agents. There are several types of agents, depending on their behavior and their capabilities. Some examples of built-in types of agents are:\n",
2023-04-24 17:23:04 +00:00
" - Network agents, which are linked to a node in the topology. They have additional methods to access their neighbors.\n",
" - FSM (Finite state machine) agents. Their behavior is defined in terms of states, and an agent will move from one state to another.\n",
" - Evented agents, an actor-based model of agents, which can communicate with one another through message passing.\n",
" - For convenience, a general `soil.Agent` class is provided, which inherits from Network, FSM and Evented at the same time.\n",
2017-10-18 18:28:42 +00:00
"\n",
"Soil provides several abstractions over events to make developing agents easier.\n",
2023-04-20 15:56:44 +00:00
"This means you can use events (timeouts, delays) in soil, but for the most part we will assume your models will be step-based o.\n"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-02T15:55:12.933978Z",
"start_time": "2017-07-02T17:55:12.930860+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"## Modeling behaviour"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T13:49:31.269687Z",
"start_time": "2017-07-03T15:49:31.257850+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"Our first step will be to model how every person in the social network reacts to hearing a piece of disinformation (news).\n",
"We will follow a very simple model based on a finite state machine.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"A person may be in one of two states: **neutral** (the default state) and **infected**.\n",
"A neutral person may hear about a piece of disinformation either on the TV (with probability **prob_tv_spread**) or through their friends.\n",
2017-10-18 18:28:42 +00:00
"Once a person has heard the news, they will spread it to their friends (with a probability **prob_neighbor_spread**).\n",
2023-04-20 15:56:44 +00:00
"Some users do not have a TV, so they will only be infected by their friends.\n",
2017-10-18 18:28:42 +00:00
"\n",
"The spreading probabilities will change over time due to different factors.\n",
2023-04-20 15:56:44 +00:00
"We will represent this variance using an additional agent which will not be a part of the social network."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"### Modelling Agents\n",
"\n",
"The following sections will cover the basics of developing agents in SOIL.\n",
"\n",
"For more advanced patterns, please check the **examples** folder in the repository."
]
},
{
"cell_type": "markdown",
"metadata": {
"hideCode": false,
"hidePrompt": false
},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"#### Basic agents"
2017-10-18 18:28:42 +00:00
]
},
{
2023-05-03 10:14:49 +00:00
"attachments": {},
2017-10-18 18:28:42 +00:00
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T14:03:07.171127Z",
"start_time": "2017-07-03T16:03:07.165779+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"The most basic agent in Soil is ``soil.BaseAgent``.\n",
"These agents implement their behavior by overriding the `step` method, which will be run in every simulation step.\n",
"Only one agent will be running at any given time, and it will be doing so until the `step` function returns.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"Agents can access their environment through their ``self.model`` attribute.\n",
"This is most commonly used to get access to the environment parameters and methods.\n",
"Here is a simple example of an agent:\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"\n",
"```python\n",
"class ExampleAgent(BaseAgent):\n",
" def init(self):\n",
" self.is_infected = False\n",
" self.steps_neutral = 0\n",
" \n",
" def step(self):\n",
" # Implement agent logic\n",
" if self.is_infected:\n",
" ... # Do something, like infecting other agents\n",
" return self.die(\"No need to do anything else\") # Stop forever\n",
" else:\n",
" ... # Do something\n",
" self.steps_neutral += 1\n",
" if self.steps_neutral > self.model.max_steps_neutral:\n",
" self.is_infected = True\n",
2017-10-18 18:28:42 +00:00
"```\n",
"\n",
"\n",
"\n",
2023-04-20 15:56:44 +00:00
"Any kind of agent behavior can be implemented with this `step` function.\n",
2023-05-03 10:14:49 +00:00
"dead, it has two main drawbacks: 1) complex behaviors can get difficult both write and understand; 2) these behaviors are not composable."
2023-04-20 15:56:44 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T14:03:07.171127Z",
"start_time": "2017-07-03T16:03:07.165779+02:00"
},
"hideCode": false,
"hidePrompt": false
},
"source": [
"#### FSM agents\n",
"\n",
"One way to solve both issues is to model agents as **[Finite-state Machines](https://en.wikipedia.org/wiki/Finite-state_machine)** (FSM, for short).\n",
"FSM define a series of possible states for the agent, and changes between these states.\n",
"These states can be modelled and extended independently.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"This is modelled in Soil through the `soil.FSM` class.\n",
"Agents that inherit from ``soil.FSM`` do not need to specify a ``step`` method.\n",
2020-10-19 11:14:48 +00:00
"Instead, we describe each finite state with a function.\n",
"To change to another state, a function may return the new state, or the ``id`` of a state.\n",
"If no state is returned, the state remains unchanged.\n",
"\n",
2023-04-20 15:56:44 +00:00
"The current state of the agent can be checked with ``agent.state_id``.\n",
"That state id can be used to look for other agents in that specific state.\n",
2020-10-19 11:14:48 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"Our previous example could be expressed like this:\n",
2020-10-19 11:14:48 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"```python\n",
"class FSMExample(FSM):\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
" def init(self):\n",
" self.steps_neutral = 0\n",
" \n",
" @state(default=True)\n",
" def neutral(self):\n",
" ... # Do something\n",
" self.steps_neutral += 1\n",
" if self.steps_neutral > self.model.max_steps_neutral:\n",
" return self.infected # Change state\n",
"\n",
" @state\n",
" def infected(self):\n",
" ... # Do something\n",
" return self.die(\"No need to do anything else\")\n",
"```"
2017-10-18 18:28:42 +00:00
]
},
{
2023-05-03 10:14:49 +00:00
"attachments": {},
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-05-03 10:14:49 +00:00
"#### Async agents\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-05-03 10:14:49 +00:00
"Another design pattern that can be very useful in some cases is to model each step (or a specific state) using asynchronous functions (and the `await` keyword).\n",
"Asynchronous functions will be paused on `await`, and resumed at a later step from the same point.\n",
"\n",
"The following agent will do something for `self.model.max_steps` and then stop forever.\n",
2023-04-20 15:56:44 +00:00
"\n",
"\n",
"\n",
"```python\n",
2023-05-03 10:14:49 +00:00
"class AsyncExample(BaseAgent):\n",
" async def step(self):\n",
" for i in range(self.model.max_steps):\n",
" self.do_something()\n",
" await self.delay() # Signal the scheduler that this agent is done for now\n",
2023-04-20 15:56:44 +00:00
" return self.die(\"No need to do anything else\") \n",
2023-05-03 10:14:49 +00:00
"```\n",
"\n",
"Notice that this trivial example could be implemented with a regular `step` and an attribute with the counts of times the agent has run so far.\n",
"By using an `async` we avoid complicating the logic of our function or adding spurious attributes."
2023-04-20 15:56:44 +00:00
]
},
{
2023-05-03 10:14:49 +00:00
"attachments": {},
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"#### Telling the scheduler when to wake up an agent\n",
"\n",
"By default, every agent will be called in every simulation step, and the time elapsed between two steps is controlled by the `interval` attribute in the environment.\n",
"\n",
2023-05-03 10:14:49 +00:00
"But agents may signal the scheduler how long to wait before calling them again by returning (or `yield`ing) a value other than `None`.\n",
2023-04-20 15:56:44 +00:00
"This is especially useful when an agent is going to be dormant for a long time.\n",
2023-05-03 10:14:49 +00:00
"There are two convenience methods to calculate the value to return: `Agent.delay`, which takes a time delay; and `Agent.at`, which takes an absolute time at which the agent should be awaken.\n",
"A return (or `yield`) value of `None` will default to a wait of 1 unit of time.\n",
"\n",
"When an `FSM` agent returns, it may signal two things: how long to wait, and a state to transition to.\n",
"This can be done by using the `delay` and `at` methods of each state."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-02T12:22:53.931963Z",
"start_time": "2017-07-02T14:22:53.928340+02:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
"### Environment agents"
]
},
{
2023-05-03 10:14:49 +00:00
"attachments": {},
2017-10-18 18:28:42 +00:00
"cell_type": "markdown",
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
2017-10-18 18:28:42 +00:00
"source": [
2023-05-03 10:14:49 +00:00
"In our simulation, we need a way to model how TV broadcasts news, and those that have a TV are susceptible to it.\n",
"We will only model one very viral TV broadcast, which we will call an `event`, which has a high chance of infecting users with a TV.\n",
"\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-05-03 10:14:49 +00:00
"There are several ways to model this behavior.\n",
"We will do it with an Environment Agent.\n",
"Environment agents are regular agents that interact with the environment but are invisible to other agents."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 65,
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2018-05-04 08:01:49 +00:00
"end_time": "2017-11-03T10:58:17.653736Z",
"start_time": "2017-11-03T11:58:17.612944+01:00"
2023-04-20 15:56:44 +00:00
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"outputs": [],
"source": [
2023-04-20 15:56:44 +00:00
"import logging\n",
2020-10-19 11:14:48 +00:00
"\n",
2023-04-24 16:46:09 +00:00
"class EventGenerator(BaseAgent):\n",
2023-04-20 15:56:44 +00:00
" level = logging.INFO\n",
" \n",
2023-05-03 10:14:49 +00:00
" async def step(self):\n",
2023-04-20 15:56:44 +00:00
" # Do nothing until the time of the event\n",
2023-05-03 10:14:49 +00:00
" await self.at(self.model.event_time)\n",
2023-04-20 15:56:44 +00:00
" self.info(\"TV event happened\")\n",
" self.model.prob_tv_spread = 0.5\n",
" self.model.prob_neighbor_spread *= 2\n",
" self.model.prob_neighbor_spread = min(self.model.prob_neighbor_spread, 1)\n",
2023-05-03 10:14:49 +00:00
" await self.delay()\n",
2023-04-20 15:56:44 +00:00
" self.model.prob_tv_spread = 0\n",
"\n",
" while self.alive:\n",
" self.model.prob_neighbor_spread = self.model.prob_neighbor_spread * self.model.neighbor_factor\n",
" if self.model.prob_neighbor_spread < 0.01:\n",
" return self.die(\"neighbors can no longer spread the rumour\")\n",
2023-05-03 10:14:49 +00:00
" await self.delay()"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"### Environment (Model)\n",
"\n",
"Let's define a environment model to test our event generator agent.\n",
"This environment will have a single agent (the event generator).\n",
"We will also tell the environment to save the value of `prob_tv_spread` after every step:"
2017-10-18 18:28:42 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 66,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"outputs": [],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"class NewsEnvSimple(NetworkEnvironment):\n",
2023-04-20 15:56:44 +00:00
" \n",
2023-04-24 16:46:09 +00:00
" # Here we set the default parameters for our model\n",
" # We will be able to override them on a per-simulation basis\n",
2023-04-20 15:56:44 +00:00
" prob_tv_spread = 0.1\n",
" prob_neighbor_spread = 0.1\n",
" event_time = 10\n",
" neighbor_factor = 0.9\n",
"\n",
" \n",
2023-05-03 10:14:49 +00:00
" # This function initializes the model. It is run right at the end of the `__init__` function.\n",
2023-04-20 15:56:44 +00:00
" def init(self):\n",
" self.add_model_reporter(\"prob_tv_spread\")\n",
" self.add_agent(EventGenerator)"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-24 16:46:09 +00:00
"Once the environment has been defined, we can quickly run our simulation through the `run` method on NewsEnv:"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 67,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"outputs": [
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "913bbb91650841e6afee444b2c1f4636",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
2017-10-18 18:28:42 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
"NewsEnvSimple: 0%| | 0/1 [00:00<?, ?configuration/s]"
2017-10-18 18:28:42 +00:00
]
},
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "display_data"
2017-10-18 18:28:42 +00:00
},
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "3febc88a480b4e80aa35dfff331f54f6",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
2017-10-18 18:28:42 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/1 [00:00<?, ?it/s]"
2017-10-18 18:28:42 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
2020-10-19 11:14:48 +00:00
{
"data": {
2023-04-20 15:56:44 +00:00
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>step</th>\n",
" <th>agent_count</th>\n",
" <th>prob_tv_spread</th>\n",
" </tr>\n",
" <tr>\n",
" <th>time</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>0.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0.1</td>\n",
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>10.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0.1</td>\n",
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>11.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>2</td>\n",
" <td>1</td>\n",
" <td>0.5</td>\n",
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>12.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>3</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>13.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>4</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>14.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>5</td>\n",
" <td>1</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-04-20 15:56:44 +00:00
" step agent_count prob_tv_spread\n",
"time \n",
2023-05-03 10:14:49 +00:00
"0.0 0 1 0.1\n",
"10.0 1 1 0.1\n",
"11.0 2 1 0.5\n",
"12.0 3 1 0.0\n",
"13.0 4 1 0.0\n",
"14.0 5 1 0.0"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 67,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2023-04-24 16:46:09 +00:00
"it = NewsEnvSimple.run(iterations=1, max_time=14)\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"it[0].model_df()"
2017-10-18 18:28:42 +00:00
]
},
{
2023-05-03 10:14:49 +00:00
"attachments": {},
2017-10-18 18:28:42 +00:00
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-05-03 10:14:49 +00:00
"As we can see, the event occurred right after `t=10`, so by `t=11` the value of `prob_tv_spread` was already set to `0.5`.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"You may notice nothing happened between `t=0` and `t=1`.\n",
"That is because there aren't any other agents in the simulation, and our event generator explicitly waited until `t=10`."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"### Network agents"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-07-03T14:03:07.171127Z",
"start_time": "2017-07-03T16:03:07.165779+02:00"
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"In our disinformation scenario, we will model our agents as a FSM with two states: ``neutral`` (default) and ``infected``.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"Here's the code:"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 68,
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-11-03T10:58:16.051690Z",
"start_time": "2017-11-03T11:58:16.006044+01:00"
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"outputs": [],
"source": [
2023-04-24 16:46:09 +00:00
"class NewsSpread(Agent):\n",
2023-04-20 15:56:44 +00:00
" has_tv = False\n",
" infected_by_friends = False\n",
" \n",
2023-05-03 10:14:49 +00:00
" # The state decorator is used to define the states of the agent\n",
2023-04-24 16:46:09 +00:00
" @state(default=True)\n",
2023-04-20 15:56:44 +00:00
" def neutral(self):\n",
2023-05-03 10:14:49 +00:00
" # The agent might have been infected by their infected friends since the last time they were checked\n",
2023-04-20 15:56:44 +00:00
" if self.infected_by_friends:\n",
2023-05-03 10:14:49 +00:00
" # Automatically transition to the infected state\n",
2023-04-20 15:56:44 +00:00
" return self.infected\n",
2023-05-03 10:14:49 +00:00
" # If the agent has a TV, they might be infected by the evenn\n",
2023-04-20 15:56:44 +00:00
" if self.has_tv:\n",
" if self.prob(self.model.prob_tv_spread):\n",
" return self.infected\n",
" \n",
2023-04-24 16:46:09 +00:00
" @state\n",
2023-04-20 15:56:44 +00:00
" def infected(self):\n",
" for neighbor in self.iter_neighbors(state_id=self.neutral.id):\n",
" if self.prob(self.model.prob_neighbor_spread):\n",
2023-05-03 10:14:49 +00:00
" neighbor.infected_by_friends = True\n",
" return self.delay(7) # Wait for 7 days before trying to infect their friends again"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-24 16:46:09 +00:00
"We can check that our states are well defined:"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 69,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"outputs": [
{
"data": {
"text/plain": [
"['dead', 'neutral', 'infected']"
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 69,
2023-04-20 15:56:44 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"NewsSpread.states()"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"### Environment (Model)"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"cell_style": "split",
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"Let's modify our simple simulation.\n",
"We will add a network of agents of type NewsSpread.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"Only one agent (0) will have a TV (in blue)."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 70,
2017-10-18 18:28:42 +00:00
"metadata": {
"cell_style": "split",
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2020-10-19 11:14:48 +00:00
"outputs": [
{
2023-04-20 15:56:44 +00:00
"data": {
2023-05-03 10:14:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAGFCAYAAABg2vAPAAAAOXRFWHRTb2Z0d2FyZQ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ex+m9n0PjlhgiTVqZMPp/PFzuos7OTuro6Tpw4QW1t7WjkkiSJjhcOsuqOY2z/4FqynCXH2AGPLbzfMvllNj81ldlfrB/FpPFU6ve3cwYkSbHUes+LNF4/hR0fLAQYtAh89P0dHyyk8foptN7zYugZk8IyIEmKnQ0tz7HyyevoobpoCbhQjrH0UM3KJ69jQ8tz4QRMGMuAJClWWu95kfXP3tD3KnPBu53AYuCivvdqgP/az1WC89Y/ewOPf8s7BMVYBiRJsdHxwkHWPrkIGGg626eB/ws0A98k+NL/T8A/DHB8nvueWETHCwfLnjVJLAOSpNhYdccxcmT56zsCAN8HDgD/Cvgj8CPgIMHCuL8Z4IoZcmRZdcexMOImhmVAkhQLbf+0l+0fXDvIHIFH+35u+sjvJgE3At3AH/o9K8dYtn9wLW/+c3u5oiaOZUCSFAubvnuYLGcHOaIdqAJmXvD7m/p+/vOAZ2Y5y6PrDo0sYIJZBiRJsbCl7fIiKwdOAhP6+f1VfT/fHvDMHGPZ+uZlI0iXbJYBSVLkuo508Xau2CZB5+h/49zCZjqnBj27/ewsuo92DyNd8lkGJEmRa3/xCPmiX0kXAbl+ft/Z93P8oGfnGcPe5w8PI13yWQYkSZHr7R5srkDBBIKhggvt6fs5p0yfkz6WAUlS5MbVlLLL4BzgDHDhRMDtfT9vLdPnpI9lQJIUuYbrZ5DhfJGjVl/wE4IhgucI7hosHvTsDOdpuH7
2023-04-20 15:56:44 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
"<Figure size 640x480 with 1 Axes>"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
2020-10-19 11:14:48 +00:00
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"def generate_simple():\n",
" G = nx.Graph()\n",
" G.add_edge(0, 1)\n",
" G.add_edge(0, 2)\n",
" G.add_edge(2, 3)\n",
" G.add_node(4)\n",
" return G\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"G = generate_simple()\n",
"pos = nx.spring_layout(G)\n",
"nx.draw_networkx(G, pos, node_color='red')\n",
"nx.draw_networkx(G, pos, nodelist=[0], node_color='blue')"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 71,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-03-23 13:49:09 +00:00
"outputs": [],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"class NewsEnvNetwork(Environment):\n",
2023-04-20 15:56:44 +00:00
" \n",
" prob_tv_spread = 0\n",
" prob_neighbor_spread = 0.1\n",
" event_time = 10\n",
" neighbor_factor = 0.9\n",
2018-05-04 08:01:49 +00:00
"\n",
2023-04-20 15:56:44 +00:00
" \n",
" def init(self):\n",
" self.add_agent(EventGenerator)\n",
" self.G = generate_simple()\n",
" self.populate_network(NewsSpread)\n",
" self.agent(node_id=0).has_tv = True\n",
" self.add_model_reporter('prob_tv_spread')\n",
" self.add_model_reporter('prob_neighbor_spread')"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 72,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2020-10-19 11:14:48 +00:00
"outputs": [
{
2023-04-20 15:56:44 +00:00
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "450bd9491a774e34bbb8d1454744e83f",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
"NewsEnvNetwork: 0%| | 0/1 [00:00<?, ?configuration/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "b9f8255c3d63430191894f44575e49a1",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/1 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
2020-10-19 11:14:48 +00:00
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
2023-04-20 15:56:44 +00:00
" .dataframe thead th {\n",
2020-10-19 11:14:48 +00:00
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
2023-04-20 15:56:44 +00:00
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>step</th>\n",
" <th>agent_count</th>\n",
2020-10-19 11:14:48 +00:00
" <th>prob_tv_spread</th>\n",
2023-04-20 15:56:44 +00:00
" <th>prob_neighbor_spread</th>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-04-20 15:56:44 +00:00
" <th>time</th>\n",
2020-10-19 11:14:48 +00:00
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>0.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>0</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>1.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>1</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>2.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>2</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>3.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>3</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>4.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>4</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>5.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>5</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>6.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>6</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>7.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>7</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>8.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>8</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>9.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>9</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>10.0</th>\n",
2020-10-19 11:14:48 +00:00
" <td>10</td>\n",
2023-04-20 15:56:44 +00:00
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.100000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>11.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>11</td>\n",
" <td>6</td>\n",
2020-10-19 11:14:48 +00:00
" <td>0.5</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.200000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>12.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>12</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.180000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>13.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>13</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.162000</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>14.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>14</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.145800</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>15.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>15</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.131220</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>16.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>16</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.118098</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>17.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>17</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.106288</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>18.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>18</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.095659</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>19.0</th>\n",
2023-04-20 15:56:44 +00:00
" <td>19</td>\n",
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.086093</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>20.0</th>\n",
2020-10-19 11:14:48 +00:00
" <td>20</td>\n",
2023-04-20 15:56:44 +00:00
" <td>6</td>\n",
" <td>0.0</td>\n",
" <td>0.077484</td>\n",
2020-10-19 11:14:48 +00:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
2023-04-20 15:56:44 +00:00
" step agent_count prob_tv_spread prob_neighbor_spread\n",
"time \n",
2023-05-03 10:14:49 +00:00
"0.0 0 6 0.0 0.100000\n",
"1.0 1 6 0.0 0.100000\n",
"2.0 2 6 0.0 0.100000\n",
"3.0 3 6 0.0 0.100000\n",
"4.0 4 6 0.0 0.100000\n",
"5.0 5 6 0.0 0.100000\n",
"6.0 6 6 0.0 0.100000\n",
"7.0 7 6 0.0 0.100000\n",
"8.0 8 6 0.0 0.100000\n",
"9.0 9 6 0.0 0.100000\n",
"10.0 10 6 0.0 0.100000\n",
"11.0 11 6 0.5 0.200000\n",
"12.0 12 6 0.0 0.180000\n",
"13.0 13 6 0.0 0.162000\n",
"14.0 14 6 0.0 0.145800\n",
"15.0 15 6 0.0 0.131220\n",
"16.0 16 6 0.0 0.118098\n",
"17.0 17 6 0.0 0.106288\n",
"18.0 18 6 0.0 0.095659\n",
"19.0 19 6 0.0 0.086093\n",
"20.0 20 6 0.0 0.077484"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 72,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"it = NewsEnvNetwork.run(max_time=20)\n",
2023-04-20 15:56:44 +00:00
"it[0].model_df()"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"In this case, notice that the inclusion of other agents (which run every step) means that the simulation did not skip to `t=10`.\n",
"\n",
"Now, let's look at the state of our agents in every step:"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 73,
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
2023-05-03 10:14:49 +00:00
{
"name": "stderr",
"output_type": "stream",
"text": [
"No agent dataframe provided and no agent reporters found. Skipping agent plot.\n"
]
},
2023-04-20 15:56:44 +00:00
{
"data": {
2023-05-03 10:14:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGwCAYAAAB7MGXBAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/av/WaAAAACXBIWXMAAA9hAAAPYQGoP6dpAABTfUlEQVR4nO3deVxU5eI/8M/MADMgm4qCKIoLKq4oKGKZVuRSN9PqG3m9uWRWKjcLvZV11dR+F8u1xatlqZV2NW9pXS1NSawUM0Fv5lYaiqagdmWTZWDm+f1xnIFRlhmY4ZwzfN6v13nlzJzlORxpPj6rRgghQERERCQTrdwFICIiosaNYYSIiIhkxTBCREREsmIYISIiIlkxjBAREZGsGEaIiIhIVgwjREREJCsPuQtgD7PZjIsXL8LPzw8ajUbu4hAREZEdhBAoKChAaGgotNrq6z9UEUYuXryIsLAwuYtBREREdXD+/Hm0adOm2s9VEUb8/PwASDfj7+8vc2mIiIjIHvn5+QgLC7N+j1dHFWHE0jTj7+/PMEJERKQytXWxYAdWIiIikhXDCBEREcmKYYSIiIhkpYo+I0REDc1sNsNoNMpdDCJF8/T0hE6nq/d5GEaIiG5iNBqRmZkJs9ksd1GIFC8wMBAhISH1mgeMYYSIqBIhBC5dugSdToewsLAaJ2oiasyEECgqKsLly5cBAK1atarzuRhGiIgqKS8vR1FREUJDQ+Hj4yN3cYgUzdvbGwBw+fJltGzZss5NNoz8RESVmEwmAICXl5fMJSFSB0toLysrq/M5GEaIiKrAdbCI7OOM3xWGESIiIpJVncLIihUrEB4eDoPBgNjYWBw8eLDafdetWweNRmOzGQyGOheYiIiI3IvDYWTTpk1ISkrC3LlzkZGRgd69e2PYsGHW3rRV8ff3x6VLl6zbuXPn6lVoIiJqGOHh4Vi+fLnc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Lly5Z97927RomT56MyMhI3HvvvcjPz8f+/fvRrVs3590FEVElzgwjanLzF+OBAwcQERFR7eJlkZGR2Ldvn817+/btQ+fOnW2OOXDgwC3njYyMtKtMnp6e1pqZysaOHYtNmzYhLS0Nv/32Gx599FG7zgdIzT/jx4/H+vXrsXz5crz77ru3lM+ivLwc6enpNZa3W7du0Ov1yMrKQqdOnWw2S3/Fffv2YeDAgZg6dSr69OmDTp064cyZM9ZzBAQEoFWrVjbPwHJtql2d4r6lx3ZVUlNTbV4vW7YMy5Ytq8tliIjqpLGGkaysLCQlJeGpp55CRkYG3nrrrSpHx1jMmDED/fr1w4IFC5CQkIC0tDS8/fbb+Oc//2mz3759+/D6669j1KhR2LVrFzZv3ozt27fbVabw8HCkpKTgtttug16vR9OmTQEADz74IKZMmYIpU6bgzjvvRGhoqF3nmzNnDqKjo9G9e3eUlpZi27ZttwSNFStWICIiApGRkVi2bBmuXbuGxx9/vNpz+vn5YebMmXjuuedgNptx++23Iy8vD/v27YO/vz/Gjx+PiIgIfPjhh9i5cyfat2+Pjz76CD/++CPat29vPc/06dOxcOFCREREoGvXrli6dClyc3Ptuq/Gzj3qHomIKsmvFEDyG1EYGTduHIqLi9G/f3/odDpMnz7dOoS3Kn379sUnn3yCOXPmYMGCBWjVqhXmz59v03kVkELLoUOHMG/ePPj7+2Pp0qUYNsy+fjRLlixBUlISVq9ejdatW+Ps2bMApABw//3345NPPqlx0sybeXl5YdasWTh79iy8vb0xaNAgbNy40WafhQsXYuHChThy5Ag6deqEL774AkFBQTWed8GCBWjRogWSk5Px22+/ITAwEH379sVLL70EAHjqqadw+PBhJCQkQKP
2023-04-20 15:56:44 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
"<Figure size 640x480 with 1 Axes>"
2023-04-20 15:56:44 +00:00
]
},
2023-05-03 10:14:49 +00:00
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "display_data"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"analysis.plot(it[0])"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
2023-04-20 15:56:44 +00:00
"metadata": {
"deletable": false,
"editable": false,
"hideCode": false,
"hidePrompt": false,
"run_control": {
"frozen": true
}
},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"## Running in more scenarios\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"In real life, you probably want to run several simulations, varying some of the parameters so that you can compare and answer your research questions.\n",
2017-10-18 18:28:42 +00:00
"\n",
2023-04-20 15:56:44 +00:00
"For instance:\n",
" \n",
"* Does the outcome depend on the structure of our network? We will use different generation algorithms to compare them (Barabasi-Albert and Erdos-Renyi)\n",
"* How does neighbor spreading probability affect my simulation? We will try probability values in the range of [0, 0.4], in intervals of 0.1."
2017-10-18 18:28:42 +00:00
]
},
{
2020-10-19 11:14:48 +00:00
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 74,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"outputs": [],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"class NewsEnvComplete(Environment):\n",
2023-05-03 10:14:49 +00:00
" prob_tv = 0.1\n",
2023-04-20 15:56:44 +00:00
" prob_tv_spread = 0\n",
2023-05-03 10:14:49 +00:00
" prob_neighbor_spread = 0.1\n",
2023-04-20 15:56:44 +00:00
" event_time = 10\n",
" neighbor_factor = 0.5\n",
" generator = \"erdos_renyi_graph\"\n",
" n = 100\n",
"\n",
" def init(self):\n",
" self.add_agent(EventGenerator)\n",
2023-05-03 10:14:49 +00:00
" opts = {\"n\": self.n}\n",
" if self.generator == \"erdos_renyi_graph\":\n",
" opts[\"p\"] = 0.05\n",
" elif self.generator == \"barabasi_albert_graph\":\n",
" opts[\"m\"] = 2\n",
" self.create_network(generator=self.generator, **opts)\n",
2023-04-20 15:56:44 +00:00
"\n",
" self.populate_network([NewsSpread,\n",
" NewsSpread.w(has_tv=True)],\n",
" [1-self.prob_tv, self.prob_tv])\n",
" self.add_model_reporter('prob_tv_spread')\n",
" self.add_model_reporter('prob_neighbor_spread')\n",
2023-05-03 10:14:49 +00:00
" self.add_agent_reporter('state_id', lambda a: getattr(a, \"state_id\", None))"
2017-10-18 18:28:42 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
2020-10-19 11:14:48 +00:00
"metadata": {},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-24 16:46:09 +00:00
"This time, we set `dump=True` because we want to store our results to a database, so that we can later analyze them.\n",
"\n",
"But since we do not care about existing results in the database, we will also set`overwrite=True`."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 75,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2020-10-19 11:14:48 +00:00
"outputs": [
2023-04-20 15:56:44 +00:00
{
"name": "stderr",
"output_type": "stream",
"text": [
2023-05-03 10:14:49 +00:00
"[INFO ][12:09:51] Output directory: /mnt/data/home/j/git/lab.gsi/soil/soil/docs/tutorial/soil_output\n"
2023-04-20 15:56:44 +00:00
]
},
2020-10-19 11:14:48 +00:00
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "7218eee842324b00b113e087ae593226",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
"newspread: 0%| | 0/10 [00:00<?, ?configuration/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = erdos_renyi_graph\n",
"prob_neighbor_spread = 0\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "dacc83fb5de94c38b448eda1cf08ae66",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = erdos_renyi_graph\n",
"prob_neighbor_spread = 0.25\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "14ce9a11c3f4415a9408a4fea5152ae5",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = erdos_renyi_graph\n",
"prob_neighbor_spread = 0.5\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "bc095b24b3a7477d9fb5320e98fc342d",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = erdos_renyi_graph\n",
"prob_neighbor_spread = 0.75\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "c9802329d9ce43d996fd6939e6605d78",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = erdos_renyi_graph\n",
"prob_neighbor_spread = 1.0\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "8398c6414f404f60a77439d1c3dd8c35",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = barabasi_albert_graph\n",
"prob_neighbor_spread = 0\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "c4291f99929144a4aff08f921dee4598",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = barabasi_albert_graph\n",
"prob_neighbor_spread = 0.25\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "312773d015ff4b47aec40ea03a67c64d",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2020-10-19 11:14:48 +00:00
]
},
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = barabasi_albert_graph\n",
"prob_neighbor_spread = 0.5\n"
]
},
2020-10-19 11:14:48 +00:00
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "d505285f26b14435be77ba772f75bb1a",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2020-10-19 11:14:48 +00:00
]
},
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = barabasi_albert_graph\n",
"prob_neighbor_spread = 0.75\n"
]
2020-10-19 11:14:48 +00:00
},
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "11956a545d4145e7ba5a13a67b1c4e64",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"n = 100\n",
"generator = barabasi_albert_graph\n",
"prob_neighbor_spread = 1.0\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2023-05-03 10:14:49 +00:00
"model_id": "e52934e005fc45d2b94c18737447bc03",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2023-05-03 10:14:49 +00:00
" 0%| | 0/5 [00:00<?, ?it/s]"
2020-10-19 11:14:48 +00:00
]
},
2023-03-23 13:49:09 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"output_type": "display_data"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"N = 100\n",
"probabilities = [0, 0.25, 0.5, 0.75, 1.0]\n",
"generators = [\"erdos_renyi_graph\", \"barabasi_albert_graph\"]\n",
"\n",
"\n",
2023-04-24 16:46:09 +00:00
"it = NewsEnvComplete.run(name=f\"newspread\",\n",
" iterations=5, max_time=30, dump=True, overwrite=True,\n",
" matrix=dict(n=[N], generator=generators, prob_neighbor_spread=probabilities))"
2023-04-20 15:56:44 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 76,
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [],
"source": [
2023-04-24 16:46:09 +00:00
"DEFAULT_ITERATIONS = 5\n",
"assert len(it) == len(probabilities) * len(generators) * DEFAULT_ITERATIONS"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-07-03T11:05:18.043194Z",
"start_time": "2017-07-03T13:05:18.034699+02:00"
},
"cell_style": "center",
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"The results are conveniently stored in sqlite (history of agent and environment state) and the configuration is saved in a YAML file.\n",
"\n",
"You can also export the results to GEXF format (dynamic network) and CSV using .`run(dump=['gexf', 'csv'])` or the command line flags `--graph --csv`."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 77,
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-11-01T14:05:56.404540Z",
"start_time": "2017-11-01T15:05:56.122876+01:00"
},
"cell_style": "split",
"hideCode": false,
"hidePrompt": false
2018-05-04 08:01:49 +00:00
},
2020-10-19 11:14:48 +00:00
"outputs": [
{
2023-04-20 15:56:44 +00:00
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[01;34msoil_output\u001b[00m\n",
"└── \u001b[01;34mnewspread\u001b[00m\n",
2023-05-03 10:14:49 +00:00
" ├── newspread_1683108591.8199563.dumped.yml\n",
2023-04-20 15:56:44 +00:00
" └── newspread.sqlite\n",
"\n",
2023-05-03 10:14:49 +00:00
"1 directory, 2 files\n",
2023-04-20 15:56:44 +00:00
"21M\tsoil_output/newspread\n"
]
2020-10-19 11:14:48 +00:00
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"!tree soil_output\n",
"!du -xh soil_output/*"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-07-02T10:40:14.384177Z",
"start_time": "2017-07-02T12:40:14.381885+02:00"
},
"hideCode": false,
"hidePrompt": false
},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"### Analysing the results"
2017-10-18 18:28:42 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
"hidePrompt": false
},
"source": [
"#### Loading data"
]
},
{
"cell_type": "markdown",
"metadata": {
"hideCode": false,
"hidePrompt": false
2018-05-04 08:01:49 +00:00
},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"Once the simulations are over, we can use soil to analyse the results.\n",
"\n",
"There are two main ways: directly using the iterations returned by the `run` method, or loading up data from the results database.\n",
"This is particularly useful to store data between sessions, and to accumulate results over multiple runs.\n",
"\n",
"The mainThe main method to load data from the database is `read_sql`, which can be used in two ways:\n",
"\n",
"* `analysis.read_sql(<sqlite_file>)` to load all the results from a sqlite database . e.g. `read_sql('my_simulation/file.db.sqlite')`\n",
"* `analysis.read_sql(name=<simulation name>)` will look for the default path for a simulation named `<simulation name>`"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-04-20 15:56:44 +00:00
"The result in both cases is a named tuple with four dataframes:\n",
"\n",
"* `configuration`, which contains configuration parameters per simulation\n",
"* `parameters`, which shows the parameters used **in every iteration** of every simulation\n",
"* `env`, with the data collected from the model in each iteration (as specified in `model_reporters`)\n",
"* `agents`, like `env`, but for `agent_reporters`"
2017-10-18 18:28:42 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-07-03T14:44:30.978223Z",
"start_time": "2017-07-03T16:44:30.971952+02:00"
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
"source": [
2023-04-20 15:56:44 +00:00
"Let's see it in action by loading the stored results into a pandas dataframe:"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 78,
2017-10-18 18:28:42 +00:00
"metadata": {
"ExecuteTime": {
2023-04-20 15:56:44 +00:00
"end_time": "2017-10-19T15:57:44.101253Z",
"start_time": "2017-10-19T17:57:44.039710+02:00"
},
"hideCode": false,
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2023-04-20 15:56:44 +00:00
"outputs": [],
"source": [
2023-04-24 16:46:09 +00:00
"res = analysis.read_sql(name=\"newspread\", include_agents=True)"
2023-04-20 15:56:44 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting data\n",
"\n",
"Once we have loaded the results from the file, we can use them just like any other dataframe.\n",
"\n",
"Here is an example of plotting the ratio of infected users in each of our simulations:"
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 79,
2023-04-20 15:56:44 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-05-03 10:14:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAHHCAYAAABtF1i4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/av/WaAAAACX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I+o+9/z/fr1k9RqtXT58mV53/Xr1yU7Ozupc+fO8r7C343AwECTn/HkyZMlpVIppaWlFXs+ofKJbhoBgFdeeYWcnBx++ukn7ty5w08//VRiF8369etxcHCgR48e3Lp1S374+fmh1WrZt2+fHHvvN/o7d+5w69YtnnvuObKzs/njjz9MytVqtbz66qvytlqtpkOHDly5cqVc1+Dv74+fn5+87eXlRd++fdm5c2eR5vTQ0FCT7e3btwMwZcoUk/2F3yrv72KoXbu2yTd8e3t7QkJCOH36NImJiQBoNBosLIy/Ynq9npSUFLRaLY0bN+bUqVNF8g8JCcHOzk7efvnll3F3d5dzqwyvvPIKVlZWrF27Vt63c+dObt26ZfKzMMf27dvp0KGDyYBorVbL6NGjiY+P5/z58ybxw4YNK1fLT0W/706fPk1cXByTJk0qdmzF/e5/zzz33HNlvjd3797NnTt3CA8Px8rKqthznDhxguTkZN544w2TmD59+tCkSZMi770HzaU4169f59y5c4SEhJhMX+7SpQu+vr5ml3e/4lqN7v3ZZGVlcevWLQICApAkidOnT5t9Dr1ez65du+jXrx/169eX97u7uzNkyBAOHTpUpOt
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
"<Figure size 640x480 with 1 Axes>"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"output_type": "display_data"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"for (g, group) in res.env.dropna().groupby(\"params_id\"):\n",
" params = res.parameters.query(f'params_id == \"{g}\"').iloc[0]\n",
" title = f\"{params.generator.rstrip('_graph')} {params.prob_neighbor_spread}\"\n",
" prob = group.groupby(by=[\"step\"]).prob_neighbor_spread.mean()\n",
" line = \"-\"\n",
" if \"barabasi\" in params.generator:\n",
" line = \"--\"\n",
" prob.rename(title).fillna(0).plot(linestyle=line)\n",
"plt.title(\"Mean probability for each configuration\")\n",
"plt.legend();"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 80,
2017-10-18 18:28:42 +00:00
"metadata": {
2023-04-20 15:56:44 +00:00
"hideCode": false,
2023-04-24 16:46:09 +00:00
"hidePrompt": false
2017-10-18 18:28:42 +00:00
},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-05-03 10:14:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAHHCAYAAABtF1i4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/av/WaAAAACXBIWXMAAA9hAAAPYQGoP6dpAADI4ElEQVR4nOzdd3gUVdvA4d+W7Kb3BiEQOoRO6BZaMKAiKKLiq0hVFFBAVHhVUEADKk1FsQKCFUTk/QBpUqQLCFJClRBKCi092TrfH5ENSzokbMpzX9deZmfOzHlmMZlnzzlzjkpRFAUhhBBCCAdROzoAIYQQQlRtkowIIYQQwqEkGRFCCCGEQ0kyIoQQQgiHkmRECCGEEA4lyYgQQgghHEqSESGEEEI4lCQjQgghhHAoSUaEEEII4VCSjAjhYG+99RYqlcohdf/555906tQJNzc3VCoVBw4cyLfc5s2bUalUbN68+ZbqSUxM5NFHH8XPzw+VSsWcOXNuOeY77XavXQhRNElGhLjJwoULUalUtpdWqyUkJIRBgwZx4cKFWzpnZmYmb731Vrm6oZlMJvr378/Vq1eZPXs2ixcvplatWmVS19ixY1m7di0TJ05k8eLF9OzZs9TrePfdd1mxYkWpn1cIUfa0jg5AiPJqypQp1K5dm+zsbHbt2sXChQvZtm0bhw8fxtnZuUTnyszM5O233wagS5cudvveeOMNJkyYUFphF9vp06c5e/YsX3zxBcOGDSu07L333ktWVhY6ne6W6vr999/p06cP48ePv6Xji+Pdd9/l0UcfpW/fvmVWhxCibEgyIkQBevXqRZs2bQAYNmwY/v7+zJgxg5UrV/LYY4+VWj1arRat9s7/KiYlJQHg7e1dZFm1Wl3iBOzmuopTj7h9VqsVo9F4W/9eQtxp0k0jRDHdc889QE6LwnVGo5FJkyYRERGBl5cXbm5u3HPPPWzatMlWJjY2loCAAADefvttW/fPW2+9BeQ/ZsRsNjN16lTq1q2LXq8nLCyM//73vxgMhmLF+vvvv3PPPffg5uaGt7c3ffr0ISYmxrZ/0KBBdO7cGYD+/fujUqnytNjcKL9xE126dKFp06YcPXqUrl274urqSkhICO+9956tzPUuL0VRmDdvnu3ar0tOTmbMmDGEhoai1+upV68eM2bMwGq12tVvtVqZO3cuzZo1w9nZmYCAAHr27MnevXsBUKlUZGRksGjRIlsdgwYNsh1/4cIFhgwZQlBQEHq9niZNmvD111/nuc7z58/Tt29f3NzcCAwMZOzYscX+zAcNGkRYWFie7fn9+65fv567774bb29v3N3dadiwIf/973/tyhgMBiZPnky9evXQ6/WEhoby6quv5olHpVIxatQovv32W5o0aYJer+e3334D4IcffiAiIgIPDw88PT1p1qwZc+fOLdb1CHEnScuIEMUUGxsLgI+Pj21bamoqX375JQMGDGD48OGkpaXx1VdfERUVxZ49e2jZsiUBAQF8+umnPP/88zz88MM88sgjADRv3rzAuoYNG8aiRYt49NFHefnll9m9ezfR0dHExMTwyy+/FBrnhg0b6NWrF3Xq1OGtt94iKyuLjz76iLvuuov9+/cTFhbGc889R0hICO+++y4vvvgibdu2JSgoqMSfybVr1+jZsyePPPIIjz32GMuWLeO1116jWbNm9OrVi3vvvZfFixfz9NNP06NHDwYOHGg7NjMzk86dO3PhwgWee+45atasyY4dO5g4cSLx8fF2g1yHDh3KwoUL6dWrF8OGDcNsNvPHH3+wa9cu2rRpw+LFixk2bBjt2rXj2WefBaBu3bpAzuDZDh062G7aAQEBrFmzhqFDh5KamsqYMWMAyMrKonv37sTFxfHiiy9SvXp1Fi9ezO+//17iz6UwR44c4cEHH6R58+ZMmTIFvV7PqVOn2L59u62M1WrloYceYtu2bTz77LM0btyYQ4cOMXv2bE6cOJFnbMzvv//OTz/9xKhRo/D39ycsLIz169czYMAAunfvzowZMwCIiYlh+/btvPTSS6V6TULcNkUIYWfBggUKoGzYsEG5dOmScu7cOWXZsmVKQECAotfrlXPnztnKms1mxWAw2B1/7do1JSgoSBkyZIht26VLlxRAmTx5cp76Jk+erNz4q3jgwAEFUIYNG2ZXbvz48Qqg/P7774XG37JlSyUwMFC5cuWKbdvBgwcVtVqtDBw40LZt06ZNCqAsXbq08A/khrKbNm2ybevcubMCKN98841tm8FgUIKDg5V+/frZHQ8oI0eOtNs2depUxc3NTTlx4oTd9gkTJigajUaJi4tTFEVRfv/9dwVQXnzxxTxxWa1W289ubm7KM888k6fM0KFDlWrVqimXL1+22/7EE08oXl5eSmZmpqIoijJnzhwFUH766SdbmYyMDKVevXp5rj0/zzzzjFKrVq0822/+9509e7YCKJcuXSrwXIsXL1bUarXyxx9/2G2fP3++Aijbt2+3bQMUtVqtHDlyxK7sSy+9pHh6eipms7nQuIUoD6SbRogCREZGEhAQQGhoKI8++ihubm6sXLmSGjVq2MpoNBrboE6r1crVq1cxm820adOG/fv331K9q1evBmDcuHF2219++WUAVq1aVeCx8fHxHDhwgEGDBuHr62vb3rx5c3r06GE7d2lxd3fnqaeesr3X6XS0a9eOf/75p8hjly5dyj333IOPjw+XL1+2vSIjI7FYLGzduhWAn3/+GZVKxeTJk/Oco6hHohVF4eeff6Z3794oimJXT1RUFCkpKbZ/p9WrV1OtWjUeffRR2/Gurq62lpbScn3szK+//pqnO+q6pUuX0rhxYxo1amQXc7du3QDsugEBOnfuTHh4eJ56MjIyWL9+fanGL0RZkGREiALMmzeP9evXs2zZMu6//34uX76MXq/PU27RokU0b94cZ2dn/Pz8CAgIYNWqVaSkpNxSvWfPnkWtVlOvXj277cHBwXh7e3P27NlCjwVo2LBhnn2NGzfm8uXLZGRk3FJc+alRo0aehMDHx4dr164VeezJkyf57bffCAgIsHtFRkYCuQNsT58+TfXq1e2Sq+K6dOkSycnJfP7553nqGTx4sF09Z8+epV69enmuJ7/P8nY8/vjj3HXXXQwbNoygoCCeeOIJfvrpJ7vE5OTJkxw5ciRPzA0aNLCL+bratWvnqeeFF16gQYMG9OrVixo1ajBkyBDbWBIhyhsZMyJEAdq1a2d7mqZv377cfffdPPnkkxw/fhx3d3cAlixZwqBBg+jbty+vvPIKgYGBaDQaoqOj7Qa63gpHTYRWEhqNJt/tiqIUeazVaqVHjx68+uqr+e6/fuO9Hddv8E899RTPPPNMvmUKG7tTEgX9e1ksFrv3Li4ubN26lU2bNrFq1Sp+++03fvzxR7p168a6devQaDRYrVaaNWvGrFmz8j1naGhonnPeLDAwkAMHDrB27VrWrFnDmjVrWLBgAQMHDmTRokW3eJVClA1JRoQohusJRteuXfn4449t84IsW7aMOnXqsHz5crub0c1dCiVJLGrVqoXVauXkyZM0btzYtj0xMZHk5ORCJya7vu/48eN59h07dgx/f3/c3NyKHUtZqlu3Lunp6baWkMLKrV27lqtXrxbaOpLfZxwQEICHhwcWi6XIemrVqsXhw4dRFMXuXPl9lvnx8fEhOTk5z/b8WrLUajXdu3ene/fuzJo1i3fffZfXX3+dTZs2ERkZSd26dTl48CDdu3e/raRUp9PRu3dvevfujdVq5YUXXuCzzz7jzTffzNPyJoQjSTeNEMXUpUsX2rVrx5w5c8jOzgZyWwZubAnYvXs3O3futDvW1dUVIN+b1c3uv/9+gDxTpl//lvzAAw8UeGy1atVo2bIlixYtsqvr8OHDrFu3znbu8uCxxx5j586drF27Ns++5ORkzGYzAP369UNRFNukcTe68XN3c3PL8/lqNBr69evHzz//zOHDh/Mcf+nSJdvP999/PxcvXmTZsmW2bZmZmXz++efFup66deuSkpLC33//bdsWHx+f5+mnq1ev5jm2ZcuWALbHdh977DEuXLjAF198kadsVlZ
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-05-03 10:14:49 +00:00
"<Figure size 640x480 with 1 Axes>"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"output_type": "display_data"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"for (g, group) in res.agents.dropna().groupby(\"params_id\"):\n",
" params = res.parameters.query(f'params_id == \"{g}\"').iloc[0]\n",
" title = f\"{params.generator.rstrip('_graph')} {params.prob_neighbor_spread}\"\n",
" counts = group.groupby(by=[\"step\", \"state_id\"]).value_counts().unstack()\n",
" line = \"-\"\n",
" if \"barabasi\" in params.generator:\n",
" line = \"--\"\n",
" (counts.infected/counts.sum(axis=1)).rename(title).fillna(0).plot(linestyle=line)\n",
"plt.legend()\n",
"plt.xlim([9, None]);\n",
"plt.title(\"Ratio of infected users\");"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2023-04-20 15:56:44 +00:00
"## Data format"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "markdown",
2023-04-20 15:56:44 +00:00
"metadata": {},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"### Parameters\n",
"\n",
"The `parameters` dataframe has three keys:\n",
"\n",
"* The identifier of the simulation. This will be shared by all iterations launched in the same run\n",
"* The identifier of the parameters used in the simulation. This will be shared by all iterations that have the exact same set of parameters.\n",
"* The identifier of the iteration. Each row should have a different iteration identifier\n",
"\n",
"There will be a column per each parameter passed to the environment. In this case, that's three: **generator**, **n** and **prob_neighbor_spread**."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 81,
2023-04-24 16:46:09 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-04-20 15:56:44 +00:00
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>key</th>\n",
" <th>generator</th>\n",
" <th>n</th>\n",
" <th>prob_neighbor_spread</th>\n",
" </tr>\n",
" <tr>\n",
" <th>iteration_id</th>\n",
" <th>params_id</th>\n",
" <th>simulation_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"5\" valign=\"top\">0</th>\n",
" <th>39063f8</th>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-04-20 15:56:44 +00:00
" <td>erdos_renyi_graph</td>\n",
" <td>100</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
2023-04-24 16:05:07 +00:00
" <th>8f26adb</th>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-04-20 15:56:44 +00:00
" <td>barabasi_albert_graph</td>\n",
" <td>100</td>\n",
2023-04-24 16:05:07 +00:00
" <td>0.5</td>\n",
2023-04-20 15:56:44 +00:00
" </tr>\n",
" <tr>\n",
2023-04-24 16:05:07 +00:00
" <th>92fdcb9</th>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-04-24 16:05:07 +00:00
" <td>erdos_renyi_graph</td>\n",
2023-04-20 15:56:44 +00:00
" <td>100</td>\n",
2023-04-24 16:05:07 +00:00
" <td>0.25</td>\n",
2023-04-20 15:56:44 +00:00
" </tr>\n",
" <tr>\n",
" <th>cb3dbca</th>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-04-20 15:56:44 +00:00
" <td>erdos_renyi_graph</td>\n",
" <td>100</td>\n",
" <td>0.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>d1fe9c1</th>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-04-20 15:56:44 +00:00
" <td>barabasi_albert_graph</td>\n",
" <td>100</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-04-24 16:05:07 +00:00
"key generator \\\n",
"iteration_id params_id simulation_id \n",
2023-05-03 10:14:49 +00:00
"0 39063f8 newspread_1683108591.8199563 erdos_renyi_graph \n",
" 8f26adb newspread_1683108591.8199563 barabasi_albert_graph \n",
" 92fdcb9 newspread_1683108591.8199563 erdos_renyi_graph \n",
" cb3dbca newspread_1683108591.8199563 erdos_renyi_graph \n",
" d1fe9c1 newspread_1683108591.8199563 barabasi_albert_graph \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-04-24 16:05:07 +00:00
"key n prob_neighbor_spread \n",
"iteration_id params_id simulation_id \n",
2023-05-03 10:14:49 +00:00
"0 39063f8 newspread_1683108591.8199563 100 1.0 \n",
" 8f26adb newspread_1683108591.8199563 100 0.5 \n",
" 92fdcb9 newspread_1683108591.8199563 100 0.25 \n",
" cb3dbca newspread_1683108591.8199563 100 0.5 \n",
" d1fe9c1 newspread_1683108591.8199563 100 1.0 "
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 81,
2023-03-23 13:49:09 +00:00
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "execute_result"
2020-10-19 11:14:48 +00:00
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"res.parameters.head()"
2017-10-18 18:28:42 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
2023-03-23 13:49:09 +00:00
"metadata": {},
"source": [
2023-04-20 15:56:44 +00:00
"### Configuration\n",
"\n",
"This dataset is indexed by the identifier of the simulation, and there will be a column per each attribute of the simulation.\n",
"For instance, there is one for the number of processes used, another one for the path where the results were stored, etc."
2023-03-23 13:49:09 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 82,
2023-03-23 13:49:09 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-03-23 13:49:09 +00:00
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
2023-04-20 15:56:44 +00:00
" .dataframe thead th {\n",
2023-03-23 13:49:09 +00:00
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
2023-04-20 15:56:44 +00:00
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>index</th>\n",
" <th>version</th>\n",
" <th>source_file</th>\n",
" <th>name</th>\n",
" <th>description</th>\n",
" <th>group</th>\n",
" <th>backup</th>\n",
" <th>overwrite</th>\n",
" <th>dry_run</th>\n",
" <th>dump</th>\n",
2023-03-23 13:49:09 +00:00
" <th>...</th>\n",
2023-04-20 15:56:44 +00:00
" <th>num_processes</th>\n",
" <th>exporters</th>\n",
" <th>model_reporters</th>\n",
" <th>agent_reporters</th>\n",
" <th>tables</th>\n",
" <th>outdir</th>\n",
" <th>exporter_params</th>\n",
" <th>level</th>\n",
" <th>skip_test</th>\n",
" <th>debug</th>\n",
2023-03-23 13:49:09 +00:00
" </tr>\n",
" <tr>\n",
2023-04-20 15:56:44 +00:00
" <th>simulation_id</th>\n",
2023-03-23 13:49:09 +00:00
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th>newspread_1683108591.8199563</th>\n",
2023-03-23 13:49:09 +00:00
" <td>0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>2</td>\n",
" <td>None</td>\n",
" <td>newspread</td>\n",
" <td></td>\n",
" <td>None</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>...</td>\n",
" <td>1</td>\n",
2023-05-03 10:14:49 +00:00
" <td>[\"<class 'soil.exporters.default'>\"]</td>\n",
2023-04-20 15:56:44 +00:00
" <td>{}</td>\n",
" <td>{}</td>\n",
" <td>{}</td>\n",
2023-04-24 16:46:09 +00:00
" <td>/mnt/data/home/j/git/lab.gsi/soil/soil/docs/tu...</td>\n",
2023-04-20 15:56:44 +00:00
" <td>{}</td>\n",
" <td>20</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
2023-03-23 13:49:09 +00:00
" </tr>\n",
" </tbody>\n",
"</table>\n",
2023-05-03 10:14:49 +00:00
"<p>1 rows × 28 columns</p>\n",
2023-03-23 13:49:09 +00:00
"</div>"
],
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-04-24 16:05:07 +00:00
" index version source_file name \\\n",
"simulation_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 0 2 None newspread \n",
2023-04-24 16:05:07 +00:00
"\n",
" description group backup overwrite dry_run dump \\\n",
2023-04-20 15:56:44 +00:00
"simulation_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 None False True False True \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" ... num_processes \\\n",
"simulation_id ... \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 ... 1 \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-05-03 10:14:49 +00:00
" exporters \\\n",
"simulation_id \n",
"newspread_1683108591.8199563 [\"<class 'soil.exporters.default'>\"] \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" model_reporters agent_reporters tables \\\n",
"simulation_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 {} {} {} \n",
2023-03-23 13:49:09 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" outdir \\\n",
"simulation_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 /mnt/data/home/j/git/lab.gsi/soil/soil/docs/tu... \n",
2023-03-23 13:49:09 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" exporter_params level skip_test debug \n",
"simulation_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 {} 20 False False \n",
2023-03-23 13:49:09 +00:00
"\n",
2023-05-03 10:14:49 +00:00
"[1 rows x 28 columns]"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 82,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
2023-03-23 13:49:09 +00:00
}
],
"source": [
2023-04-20 15:56:44 +00:00
"res.config.head()"
2023-03-23 13:49:09 +00:00
]
},
{
2023-04-20 15:56:44 +00:00
"cell_type": "markdown",
"metadata": {},
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"### Model reporters\n",
"\n",
"The `env` dataframe includes the data collected from the model.\n",
"The keys in this case are the same as `parameters`, and an additional one: **step**."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 83,
2023-04-20 15:56:44 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-04-20 15:56:44 +00:00
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>agent_count</th>\n",
" <th>time</th>\n",
" <th>prob_tv_spread</th>\n",
" <th>prob_neighbor_spread</th>\n",
" </tr>\n",
" <tr>\n",
" <th>simulation_id</th>\n",
" <th>params_id</th>\n",
" <th>iteration_id</th>\n",
" <th>step</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th rowspan=\"5\" valign=\"top\">newspread_1683108591.8199563</th>\n",
2023-04-24 16:05:07 +00:00
" <th rowspan=\"5\" valign=\"top\">ff1d24a</th>\n",
2023-04-20 15:56:44 +00:00
" <th rowspan=\"5\" valign=\"top\">0</th>\n",
" <th>0</th>\n",
" <td>101</td>\n",
2023-05-03 10:14:49 +00:00
" <td>0.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>101</td>\n",
2023-05-03 10:14:49 +00:00
" <td>1.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>101</td>\n",
2023-05-03 10:14:49 +00:00
" <td>2.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>101</td>\n",
2023-05-03 10:14:49 +00:00
" <td>3.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>101</td>\n",
2023-05-03 10:14:49 +00:00
" <td>4.0</td>\n",
2023-04-20 15:56:44 +00:00
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-04-24 16:05:07 +00:00
" agent_count time \\\n",
"simulation_id params_id iteration_id step \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 ff1d24a 0 0 101 0.0 \n",
" 1 101 1.0 \n",
" 2 101 2.0 \n",
" 3 101 3.0 \n",
" 4 101 4.0 \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" prob_tv_spread \\\n",
"simulation_id params_id iteration_id step \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 ff1d24a 0 0 0.0 \n",
2023-04-24 16:05:07 +00:00
" 1 0.0 \n",
" 2 0.0 \n",
" 3 0.0 \n",
" 4 0.0 \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" prob_neighbor_spread \n",
"simulation_id params_id iteration_id step \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 ff1d24a 0 0 0.0 \n",
2023-04-24 16:05:07 +00:00
" 1 0.0 \n",
" 2 0.0 \n",
" 3 0.0 \n",
" 4 0.0 "
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 83,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"res.env.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Agent reporters\n",
"\n",
"This dataframe reflects the data collected for all the agents in the simulation, in every step where data collection was invoked.\n",
"\n",
"The key in this dataframe is similar to the one in the `parameters` dataframe, but there will be two more keys: the `step` and the `agent_id`.\n",
"There will be a column per each agent reporter added to the model. In our case, there is only one: `state_id`."
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2023-05-03 10:14:49 +00:00
"execution_count": 84,
2023-04-20 15:56:44 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2023-04-20 15:56:44 +00:00
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th>state_id</th>\n",
" </tr>\n",
" <tr>\n",
" <th>simulation_id</th>\n",
" <th>params_id</th>\n",
" <th>iteration_id</th>\n",
" <th>step</th>\n",
" <th>agent_id</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
2023-05-03 10:14:49 +00:00
" <th rowspan=\"5\" valign=\"top\">newspread_1683108591.8199563</th>\n",
2023-04-24 16:05:07 +00:00
" <th rowspan=\"5\" valign=\"top\">ff1d24a</th>\n",
2023-04-20 15:56:44 +00:00
" <th rowspan=\"5\" valign=\"top\">0</th>\n",
" <th rowspan=\"5\" valign=\"top\">0</th>\n",
" <th>0</th>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>neutral</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>neutral</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>neutral</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>neutral</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
2020-10-19 11:14:48 +00:00
"text/plain": [
2023-04-24 16:05:07 +00:00
" state_id\n",
"simulation_id params_id iteration_id step agent_id \n",
2023-05-03 10:14:49 +00:00
"newspread_1683108591.8199563 ff1d24a 0 0 0 None\n",
2023-04-24 16:05:07 +00:00
" 1 neutral\n",
" 2 neutral\n",
" 3 neutral\n",
" 4 neutral"
2020-10-19 11:14:48 +00:00
]
},
2023-05-03 10:14:49 +00:00
"execution_count": 84,
2023-03-23 13:49:09 +00:00
"metadata": {},
2023-04-20 15:56:44 +00:00
"output_type": "execute_result"
2020-10-19 11:14:48 +00:00
}
],
2017-10-18 18:28:42 +00:00
"source": [
2023-04-20 15:56:44 +00:00
"res.agents.head()"
2017-10-18 18:28:42 +00:00
]
}
],
"metadata": {
2023-04-20 15:56:44 +00:00
"hide_code_all_hidden": false,
2017-10-18 18:28:42 +00:00
"kernelspec": {
2023-04-20 15:56:44 +00:00
"display_name": "Python 3 (ipykernel)",
2017-10-18 18:28:42 +00:00
"language": "python",
2023-04-24 16:05:07 +00:00
"name": "python3"
2017-10-18 18:28:42 +00:00
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2023-03-23 13:49:09 +00:00
"version": "3.8.10"
2017-10-18 18:28:42 +00:00
},
"toc": {
"colors": {
"hover_highlight": "#DAA520",
"navigate_num": "#000000",
"navigate_text": "#333333",
"running_highlight": "#FF0000",
"selected_highlight": "#FFD700",
"sidebar_border": "#EEEEEE",
"wrapper_background": "#FFFFFF"
},
"moveMenuLeft": true,
"nav_menu": {
"height": "31px",
"width": "252px"
},
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 4,
"toc_cell": false,
"toc_position": {
"height": "867px",
"left": "0px",
"right": "1670px",
"top": "106px",
"width": "250px"
},
"toc_section_display": "block",
2018-05-04 08:01:49 +00:00
"toc_window_display": false,
2017-10-18 18:28:42 +00:00
"widenNotebook": false
2023-04-14 17:41:24 +00:00
},
"vscode": {
"interpreter": {
"hash": "3581132406f7320837865a422f37590c78ed7dabfbcb5bc7771b9d116b13a5cf"
}
2017-10-18 18:28:42 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}