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,
2024-04-11 15:46:45 +00:00
"hidePrompt": false,
"jupyter": {
"outputs_hidden": true
}
2017-10-18 18:28:42 +00:00
},
"source": [
"This notebook is an introduction to the soil agent-based social network simulation framework.\n",
2024-04-11 15:46:45 +00:00
"Soil is built on top of [Mesa](https://mesa.readthedocs.io/), a general simulation library, and it introduces features specifically tailored to social simulations.\n",
2023-04-24 16:46:09 +00:00
"\n",
2024-04-11 15:46:45 +00:00
"It will focus on a specific use case: studying the propagation of disinformation through TV and social networks.\n",
"In the following sections we will:\n",
2017-10-18 18:28:42 +00:00
"\n",
2024-04-11 15:46:45 +00:00
"* Cover the basics of mesa and Soil (environments, agents, etc.)\n",
2023-04-24 16:46:09 +00:00
"* Simulate a basic scenario with a single agent\n",
"* Add more complexity to our scenario\n",
2024-04-11 15:46:45 +00:00
"* Run simulations using different configurations\n",
"* Analyze the results of each simulation\n",
2023-04-24 16:46:09 +00:00
"\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",
2024-04-11 15:46:45 +00:00
"execution_count": 1,
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",
2024-04-11 15:46:45 +00:00
"import soil\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": [
2024-04-11 15:46:45 +00:00
"Simulations are based on the concept of a **model** (or environment).\n",
"A model represents the world where the simulation will be run.\n",
"It usually contains:\n",
"\n",
" * All the simulation parameters (given in the constructor)\n",
" * A reference to every agent in the simulation\n",
" * A data collector, which will capture any relevant information for agents (agent reporters) or the model itself (model reporters)\n",
" * A scheduler (`soil.time.Scheduler` or `mesa.time.BaseScheduler`), which is responsible of coordinating the activation of agents at each simulation step\n",
" * A grid or space where agents can move (optional)\n",
2017-10-18 18:28:42 +00:00
" \n",
2024-04-11 15:46:45 +00:00
"Soil introduces the `soil.NetworkEnvironment` model class.\n",
"This type of environment contain a network topology (accessible through through `self.G`).\n",
"The topology can be manually provided to the environment, or it can be randomly generated through multiple network parameters.\n",
" \n",
"**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",
2024-04-11 15:46:45 +00:00
"This means you can use events (timeouts, delays) in soil.\n",
"But, for the most part, we will assume your models will be step-based."
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
]
},
2024-04-11 15:46:45 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A simple model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"class SimpleModel(soil.Environment):\n",
" max_steps_neutral = 3"
]
},
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
]
},
{
"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",
2024-04-11 15:46:45 +00:00
"Here is a simple example of an agent:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T14:03:07.171127Z",
"start_time": "2017-07-03T16:03:07.165779+02:00"
},
"hideCode": false,
"hidePrompt": false
},
"outputs": [],
"source": [
2023-04-20 15:56:44 +00:00
"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",
2024-04-11 15:46:45 +00:00
" self.is_infected = True"
]
},
{
"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": [
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
]
},
2024-04-11 15:46:45 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's see how the agent works:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent 0 is alive and infected\n",
"Agent 0 is alive and infected\n",
"Agent 0 is alive and infected\n",
"Agent 0 is alive and not infected\n",
"Agent 0 is dead and not infected\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/j/.cache/pypoetry/virtualenvs/soil-cCX5yKRx-py3.10/lib/python3.10/site-packages/mesa/time.py:82: FutureWarning: The AgentSet is experimental. It may be changed or removed in any and all future releases, including patch releases.\n",
"We would love to hear what you think about this new feature. If you have any thoughts, share them with us here: https://github.com/projectmesa/mesa/discussions/1919\n",
" self._agents: AgentSet = AgentSet(agents, model)\n"
]
}
],
"source": [
"model = SimpleModel()\n",
"num_steps = model.max_steps_neutral+2\n",
"a = ExampleAgent(unique_id=0, model=model)\n",
"for i in range(num_steps):\n",
" ret = a.step()\n",
" print(f\"Agent {a.unique_id} is {'alive' if a.alive else 'dead'} and {'infected' if not a.is_infected else 'not infected'}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent 0 is alive and infected @ 1\n",
"Agent 0 is alive and infected @ 2\n",
"Agent 0 is alive and infected @ 3\n",
"Agent 0 is alive and not infected @ 4\n",
"Agent 0 is dead and not infected @ inf\n"
]
}
],
"source": [
"model = SimpleModel()\n",
"a = model.add_agent(ExampleAgent)\n",
"for i in range(num_steps):\n",
" model.step()\n",
" print(f\"Agent {a.unique_id} is {'alive' if a.alive else 'dead'} and {'infected' if not a.is_infected else 'not infected'} @ {model.now}\")"
]
},
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",
2024-04-11 15:46:45 +00:00
"Our previous example could be expressed like this:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2017-07-03T14:03:07.171127Z",
"start_time": "2017-07-03T16:03:07.165779+02:00"
},
"hideCode": false,
"hidePrompt": false
},
"outputs": [],
"source": [
2023-04-20 15:56:44 +00:00
"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",
2024-04-11 15:46:45 +00:00
" return self.die(\"No need to do anything else\")"
2017-10-18 18:28:42 +00:00
]
},
{
2024-04-11 15:46:45 +00:00
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent 0 is alive and neutral @ 1\n",
"Agent 0 is alive and neutral @ 2\n",
"Agent 0 is alive and neutral @ 3\n",
"Agent 0 is alive and infected @ 4\n",
"Agent 0 is dead and dead @ inf\n"
]
}
],
2017-10-18 18:28:42 +00:00
"source": [
2024-04-11 15:46:45 +00:00
"model = SimpleModel()\n",
"a = model.add_agent(FSMExample)\n",
"for i in range(num_steps):\n",
" ret = model.step()\n",
" print(f\"Agent {a.unique_id} is {'alive' if a.alive else 'dead'} and {a.state_id} @ {model.now}\")"
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",
2024-04-11 15:46:45 +00:00
"By default, every agent will be called in every simulation step, and the time elapsed between two steps is controlled by the `default_interval` attribute in the environment.\n",
2023-04-20 15:56:44 +00:00
"\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
]
},
2024-04-11 15:46:45 +00:00
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"class FSMExampleDelayed(FSMExample):\n",
" \n",
" @state(default=True)\n",
" def neutral(self):\n",
" return self.infected.delay(self.model.max_steps_neutral)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Agent 0 is alive and infected @ 3.0\n",
"Agent 0 is dead and dead @ inf\n",
"Agent 0 is dead and dead @ inf\n",
"Agent 0 is dead and dead @ inf\n",
"Agent 0 is dead and dead @ inf\n"
]
}
],
"source": [
"model = SimpleModel()\n",
"a = model.add_agent(FSMExampleDelayed)\n",
"for i in range(num_steps):\n",
" ret = model.step()\n",
" print(f\"Agent {a.unique_id} is {'alive' if a.alive else 'dead'} and {a.state_id} @ {model.now}\")"
]
},
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",
2024-04-11 15:46:45 +00:00
"execution_count": 10,
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-24 16:46:09 +00:00
"class EventGenerator(BaseAgent):\n",
2024-04-11 15:46:45 +00:00
" def __init__(self, *args, **kwargs):\n",
" super().__init__(*args, **kwargs)\n",
"\n",
" def step(self):\n",
2023-04-20 15:56:44 +00:00
" # Do nothing until the time of the event\n",
2024-04-11 15:46:45 +00:00
" yield self.at(self.model.event_time)\n",
" self.debug(\"TV event happened\")\n",
2023-04-20 15:56:44 +00:00
" self.model.prob_tv_spread = 0.5\n",
2024-04-11 15:46:45 +00:00
" self.model.prob_neighbor_spread = min(self.model.prob_neighbor_spread*2, 1)\n",
" yield 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",
2024-04-11 15:46:45 +00:00
" yield 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",
2024-04-11 15:46:45 +00:00
"execution_count": 11,
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",
2024-04-11 15:46:45 +00:00
" self.add_model_reporter(\"prob_tv_spread\") # save prob_tv_spread at every step\n",
2023-04-20 15:56:44 +00:00
" 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",
2024-04-11 15:46:45 +00:00
"execution_count": 12,
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": {
2024-04-11 15:46:45 +00:00
"model_id": "86199270e7f74321bfc4481c95942d67",
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
},
2024-04-11 15:46:45 +00:00
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n"
]
},
2017-10-18 18:28:42 +00:00
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 12,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
2024-04-11 15:46:45 +00:00
"its = NewsEnvSimple.run(iterations=1, max_time=14)\n",
"its[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
]
},
2024-04-11 15:46:45 +00:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also get more information if we run the simulation with logging set to DEBUG:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "468d9985226a4f0cac12f62e566bce1b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NewsEnvSimple: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/1 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"NewsEnvSimple.run(iterations=1, max_time=14);"
]
},
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",
2024-04-11 15:46:45 +00:00
"execution_count": 24,
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",
2024-04-11 15:46:45 +00:00
" self.info(\"INFECTED\")\n",
2023-04-20 15:56:44 +00:00
" 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",
2024-04-11 15:46:45 +00:00
"execution_count": 15,
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']"
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 15,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 16,
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": {
2024-04-11 15:46:45 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgMAAAGFCAYAAABg2vAPAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAcyklEQVR4nO3df3Cc9Z3Y8ffKa/2w1xLYYCjgUNnKJJY5ajAT0uT4oWJzsUPSy7SZ6UzTcDO2znaLb+Y602SKTRqCHa6dm+kcZmq7Fkkh7XQ60xvKBew7GyJiE7gcPwIEy6VYVsDYIcT4rB82krzW9o9HC8aRdlf2Pvto9/t+zTBitft895P8ozfPs/t9UrlcLockSQpWXdIDSJKkZBkDkiQFzhiQJClwxoAkSYEzBiRJCpwxIElS4IwBSZICly7lRWNjYxw7dow5c+aQSqXinkmSJJVBLpdjcHCQq666irq6yf/7v6QYOHbsGAsWLCjbcJIkqXKOHDnCNddcM+nzJcXAnDlzPlqsubm5PJNJkqRYDQwMsGDBgo/+jk+mpBjIXxpobm42BiRJqjLFLvH7AUJJkgJX0pkBSZIUg6EhOHQIRkagoQHa2iCTqfgYxoAkSZXU0wPbt8OuXXD4MJx78+BUChYuhFWrYN06aG+vyEheJpAkqRL6+uDOO2HJEti2DXp7PxkCED3u7Y2eX7Iken1fX+yjGQOSJMWtqyv6r/zu7uhxNlv49fnnu7uj47q6Yh3PGJAkKU5btkBnJwwPF4+A82Wz0XGdndE6MTEGJEmKS1cXbNpUnrU2bYJHHinPWucxBiRJikNfH2zY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XGAHy8PfGjjz6a9Ci
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",
2024-04-11 15:46:45 +00:00
"execution_count": 17,
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
" 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
" 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",
2024-04-11 15:46:45 +00:00
" self.add_model_reporter('prob_neighbor_spread')\n",
" self.add_agent_reporter('state_id', lambda a: getattr(a, \"state_id\", None))"
2017-10-18 18:28:42 +00:00
]
},
{
"cell_type": "code",
2024-04-11 15:46:45 +00:00
"execution_count": 18,
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
2023-04-20 15:56:44 +00:00
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "26d045b0cd18418ab14507ac59f5a236",
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"
},
2024-04-11 15:46:45 +00:00
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n"
]
},
2023-04-20 15:56:44 +00:00
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
2023-04-20 15:56:44 +00:00
"version_major": 2,
"version_minor": 0
},
"text/plain": [
2024-04-11 15:46:45 +00:00
" 0%| | 0/3 [00:00<?, ?it/s]"
2023-04-20 15:56:44 +00:00
]
},
"metadata": {},
"output_type": "display_data"
2024-04-11 15:46:45 +00:00
}
],
"source": [
"its = NewsEnvNetwork.run(iterations=3, max_time=14)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
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",
2024-04-11 15:46:45 +00:00
" <td>0.1</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",
2024-04-11 15:46:45 +00:00
" <td>0.1</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",
2024-04-11 15:46:45 +00:00
" <td>0.1</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",
2024-04-11 15:46:45 +00:00
" <td>0.1</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",
2024-04-11 15:46:45 +00:00
" <td>0.1</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",
2024-04-11 15:46:45 +00:00
"0.0 0 6 0.0 0.1\n",
"1.0 1 6 0.0 0.1\n",
"2.0 2 6 0.0 0.1\n",
"3.0 3 6 0.0 0.1\n",
"4.0 4 6 0.0 0.1"
2020-10-19 11:14:48 +00:00
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 19,
2020-10-19 11:14:48 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
2017-10-18 18:28:42 +00:00
"source": [
2024-04-11 15:46:45 +00:00
"it = []\n",
"for i in range(3):\n",
" env = NewsEnvNetwork(seed=i+5)\n",
" for i in range(50):\n",
" env.step()\n",
" it.append(env)\n",
"it[0].model_df().head()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "90f0eab223de4c0cb834633fe037ae2f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NewsEnvNetwork: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/3 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"[INFO ][17:23:10] [@10.0]\tNewsSpread(1): INFECTED\n",
"[INFO ][17:23:10] [@11.0]\tNewsSpread(1): INFECTED\n"
]
}
],
"source": [
"import logging\n",
"it = NewsEnvNetwork.run(iterations=3, seed=4, max_time=30, level=logging.INFO)"
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",
2024-04-11 15:46:45 +00:00
"execution_count": 27,
2023-04-20 15:56:44 +00:00
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
2023-05-03 10:14:49 +00:00
{
2024-04-11 15:46:45 +00:00
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjYAAAGwCAYAAAC6ty9tAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAABvXklEQVR4nO3dd3hUZeL28e+kVwIhkNBDh4AQIIARC1IEVFZAX7H8pIi4KihuZBVUQEANq6CoILq6igUFu64oFjQsUqUpvRmqdCkhPZnz/nEyk0LKTMjMJOH+XNe5zJw55Zlxkrl5qsUwDAMRERGRasDL0wUQERERqSgKNiIiIlJtKNiIiIhItaFgIyIiItWGgo2IiIhUGwo2IiIiUm0o2IiIiEi14ePpAjgiJyeHjRs3EhkZiZeXspiIiEhVYLVaOXbsGJ06dcLHxz2Ro0oEm40bN9KtWzdPF0NERETKYe3atXTt2tUt96oSwSYyMhIw35h69ep5uDQiIiLiiCNHjtCtWzf797g7VIlgY2t+qlevHg0bNvRwaURERMQZ7uxGog4rIiIiUm0o2IiIiEi1oWAjIiIi1UaV6GMjIuJuVquVrKwsTxdDpFLz9fXF29vb08UoRMFGRKSIrKwskpOTsVqtni6KSKVXs2ZNoqKisFgsni4KoGAjIlKIYRgcOXIEb29vGjVqpElBRUpgGAZpaWkcP34coNJMx6JgIyJSQE5ODmlpadSvX5+goCBPF0ekUgsMDATg+PHj1K1bt1I0S+mfIiIiBe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E4s9rnv37syfP58lS5Ywb948kpOTueqqq5yq4HB5RI2Pjyc+Pt7++IorrqBt27a8/vrrTJ8+vdhzJk6cSEJCgv3x4cOHXRJumrz3boVfUyQzOZk/BlxPxpYtGFlZWJz4V3F6ljmHSlref8Xz0rNziZn8nUfuvW1aP4L8HP8z/c477zBq1CjWrl3LunXruPfee2ncuDGjR48GYObMmUyePJkpU6YAsH79em699Vaeeuophg4dysqVK3nggQeoXbs2I0aMsF/3+eef5/HHH2fq1Kl89913jBs3jlatWtG3b99Sy/Prr79St25d3n77bfr374+3tzd16tQhLi6OBQsWFPoOWLBgAXfccUeZr3HSpEls27aNb7/9loiICPbs2UN6enqhY/75z38ye/ZsYmJieOGFFxg4cCDJycnUrl3bfsyECROYOXMmzZo1o1atWiQmJvL+++/z2muv0bJlS/73v//xf//3f9SpU4drrrkGq9VKw4YN+fjjj6lduzYrV67k3nvvpV69etx6660AzJo1i/nz5/PWW2/Rtm1bZs2axeeff06vXr3KfF3V3bZt22jQoIH9cUm1NQMGDLD/3KFDB7p3706TJk346KOPGDVqlEP3cirYRERE4O3tzbFjxwrtP3bsmMPtYb6+vnTq1Ik9e/aUeEzRKqqC1VcilZ1fdDTeNWuSe+YMGTt2ENihg8PnpmblAJCWqWAjzmvUqBEvvvgiFouF1q1bs3nzZl588UV7sOnVqxePPPKI/fg777yT3r17M2nSJABatWrFtm3beP755wsFmx49etj7ULZq1YoVK1bw4osvlhls6tSpA+SvJVTwvnPmzLEHm127drF+/Xref//9Ml/jgQMH6NSpE3FxcUB+rVBBY8eO5eabbwZg3rx5LFmyhP/85z88+uij9mOmTZtmL39mZibPPvssP/74o/0f4s2aNeOXX37h9ddf55prrsHX15epU6faz2/atCmrVq3io48+sgeb2bNnM3HiRIYMGQKYfVC/+84zobiyCQ0NpUaNGk6fV7NmTVq1alVqZijKqWDj5+dHly5dWLp0qb0jmNVqZenSpYwdO9aha+Tm5rJ582auv/56Z24tUmVYLBYCO3bk/LJlpG/c6FSwsdfYZOe4qnjipEBfb7ZN6+exezvj8ssvLzRZWnx8PLNmzbLPpmwLAzbbt2/npptuKrSvR48ezJ49m9zcXPv0+AVr3W2PL2ak1G233cb48eNZvXo1l19+OQsWLKBz584ODeu9//77ufnmm9mwYQPXXXcdgwYN4oorrrigfDY+Pj7ExcWxffv2QscUfC/27NlDWlraBUEtKyuLTp062R/PnTuXt956iwMHDpCenk5WVhaxsbEAnD17liNHjtC9e/cL7q3mqPI7f/48e/fu5a677nL4HKebohISEhg+fDhxcXF069aN2bNnk5qaah8lNWzYMBo0aGBvP5s2bRqXX345LVq04MyZMzz//PPs37+fe+65x9lbi1QZgZ06cX7ZMtI2bXKqA3GqLdioxqbSsFgsTjUHVWbBwcGeLgIAUVFR9OrViw8++IDLL7+cDz74gPvvv9+hcwcMGMD+/fv55ptv+OGHH+jduzdjxoxh5syZTpWh4Htx/vx5ABYvXlyouQTym0wWLlzI+PHjmTVrFvHx8YSGhvL888+zZs0ap+4rpRs/fjwDBw6kSZMm/Pnnn0yZMgVvb29uv/12h6/h9G/r0KFDOXHiBJMnT+bo0aPExsayZMkSe4fiAwcOFFoN9/Tp04wePZqjR49Sq1YtunTpwsqVK13WIVikMgjM+1dc+qbfnDov3dYUpT42Ug5Fv2RXr15Ny5YtS1yYsG3btqxYsaLQvhUrVtCqVatC56xevfqC67Zt29ahMvn6+tprjAq68847efTRR7n99tv5448/uO222xy6HphNXMOHD2f48OFcddVV/POf/ywUbFavXs3VV18NmIuarl+/vtRWhZiYGPz9/Tlw4ADXXHNNscesWLGCK664ggceeMC+b+/evfafw8LCqFevHmvWrLng3p07d3b4tV3qDh06xO23386pU6eoU6cOV155JatXr7Y3azqiXP8MsfW8L05SUlKhxy+++CIvvvhieW4jUmUFXtYevLzIOXKE7KNH8XWwD1pqXk2Nra+NiDMOHDhAQkICf//739mwYQOvvPJKsaOcbB555BG6du3K9OnTGTp0KKtWrWL
"text/plain": [
"<Figure size 640x480 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display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g0jNjbW2X42bdo0Lr30Ulq2bMnp06d56qmn2LdvH3fddZentxap9tKy89gaFcflv21Sx/ZKwmKxeNQcVJmFhob6uggAxMTEcPXVV/POO+9w6aWX8s4773Dvvfe6de6AAQPYt28fX375Jd9++y29e/dmzJgxzJw506MyFH4vzp07B8AXX3zh0lwCBU0mCxYsYPz48cyaNYukpCTCw8N56qmnWL16tUf3lZKNHz+egQMH0rRpU3777TemTJmCzWbj1ltvdfsaHv+2Dh06lOPHjzN58mSOHDlCp06dWLRokbND8f79+11Wwz116hSjR4/myJEj1K5dm65du7JixQqvdQgWqcoysnM5GNXU/HnjRgzDqHTTlUvldf6X7KpVq2jVqlWxCxO2a9eO5cuXu+xbvnw5rVu3djln1apVF1y3Xbt2bpXJ39/fWWNU2O23385DDz3Erbfeyq+//sott9zi1vXAbOIaPnw4w4cP54orruDBBx90CTarVq3iyiuvBMxFTdetW1diq0J8fDyBgYHs37+fq666qshjli9fzmWXXcZ9993n3Ld7927nzxERETRo0IDVq1dfcO8uXbq4/dpquoMHD3Lrrbdy8uRJ6tWrx+WXX86qVauczZruKNOfIY6e90VZsmSJy+NnnnmGZ555piy3Ealx0rLy2B3RiByrDX7/nZwDBwjwYJij1Gz79+8nOTmZP//5z6xfv57nn3++yFFODg888ADdunVj+vTpDB06lJUrV/LCCy/w4osvuhy3fPlynnzySQYNGsS3337L+++/zxdffOFWmeLi4li8eDE9e/YkMDCQ2rVrAzBkyBDuvfde7r33Xv7
2023-04-20 15:56:44 +00:00
"text/plain": [
2024-04-11 15:46:45 +00:00
"<Figure size 640x480 with 2 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkMAAAGwCAYAAACq12GxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAABlb0lEQVR4n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k586dvPDCC2XODrN5+OGH6dGjB7NmzSIpKYlNmzaxcOFC/v73vzuU27BhA8888wxDhgxhzZo1vP3223z00UcVqlNsbCypqan07t2boKAgateuDcDtt9/OuHHjGDduHL/5zW9o2LBhha43depUunXrRvv27cnPz+c///nPRUFn0aJFtGrVinbt2vHcc8/xyy+/8Ic//KHca4aHhzNp0iQeeughLBYL1113HWfOnGHDhg3UrFmTkSNH0qpVK1577TU+/fRTmjVrxuuvv862bdto1qyZ/ToTJ05k9uzZtGrVirZt2zJv3jx+/fXXCr0v8a6ro+1X5CqRW2iEobyCYqxW61WxAaJ4zogRI8jLy6Nnz56YzWYmTpxon0Jflq5du/LWW28xdepUZs2aRYMGDZg5c6bD4GkwQtP27duZMWMGNWvWZN68eQwYULFxVHPnziU5OZmXXnqJmJgYDh8+DBgBZPDgwbz11luXXLT3QoGBgUyePJnDhw8TEhLC9ddfz8qVKx3KzJ49m9mzZ7N7925atmzJhx9+SL169S553VmzZhEZGUlKSgo//PADtWr
"text/plain": [
"<Figure size 640x480 with 2 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": [
2024-04-11 15:46:45 +00:00
"from soil import analysis\n",
"for res in it:\n",
" analysis.plot(res)"
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",
2024-04-11 15:46:45 +00:00
"execution_count": 28,
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",
2024-04-11 15:46:45 +00:00
" [1-self.prob_tv, self.prob_tv])\n",
2023-04-20 15:56:44 +00:00
" 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
]
},
2024-04-11 15:46:45 +00:00
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(its.values())[0][3].count_agents(state_id='infected')"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "522fa16a8a52488781e69f025ec51cc1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0\n",
" generator = erdos_renyi_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a46911e00cf04c7d9504c70d3105bfc9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0\n",
" generator = barabasi_albert_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f3202fff4879428b8505f4fd7c7605e1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.25\n",
" generator = erdos_renyi_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6e3bee309cd043b19b4ea90f1ea3e039",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.25\n",
" generator = barabasi_albert_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7369e8dc45d545899c07a0e1de2cec52",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.5\n",
" generator = erdos_renyi_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a1cac9f81c46470fb9b20eab88bfe0da",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.5\n",
" generator = barabasi_albert_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f48b611e76bb4363a14182dd5fea6059",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.75\n",
" generator = erdos_renyi_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5d8fffaacc084c0b9b14de13e0c968fb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 0.75\n",
" generator = barabasi_albert_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d50a638f8b3b45909d9e7b56418abcc5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 1.0\n",
" generator = erdos_renyi_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f494cf391b354761b23c8c772d330422",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"newspread: 0%| | 0/1 [00:00<?, ?configuration/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- Running for parameters: \n",
" N = 100\n",
" prob_neighbor_spread = 1.0\n",
" generator = barabasi_albert_graph\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/5 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Ns = [100]\n",
"probabilities = [0, 0.25, 0.5, 0.75, 1.0]\n",
"generators = [\"erdos_renyi_graph\", \"barabasi_albert_graph\"]\n",
"\n",
"its = {}\n",
"for N in Ns:\n",
" for prob_neighbor_spread in probabilities:\n",
" for generator in generators:\n",
" params = dict(N=N, prob_neighbor_spread=prob_neighbor_spread, generator=generator)\n",
" env = NewsEnvComplete.run(name=f\"newspread\",\n",
" iterations=5,\n",
" max_time=30,\n",
" level=logging.WARNING,\n",
" parameters=params)\n",
" its[(N, prob_neighbor_spread, generator)] = env\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(its)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Storing results and analyzing them"
]
},
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",
2024-04-11 15:46:45 +00:00
"execution_count": 53,
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": [
{
"data": {
2023-04-20 15:56:44 +00:00
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "d5004870a00c48de8fd16e47b91e47ec",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = erdos_renyi_graph\n",
" prob_neighbor_spread = 0\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = erdos_renyi_graph\n",
" prob_neighbor_spread = 0.25\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = erdos_renyi_graph\n",
" prob_neighbor_spread = 0.5\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = erdos_renyi_graph\n",
" prob_neighbor_spread = 0.75\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = erdos_renyi_graph\n",
" prob_neighbor_spread = 1.0\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = barabasi_albert_graph\n",
" prob_neighbor_spread = 0\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = barabasi_albert_graph\n",
" prob_neighbor_spread = 0.25\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = barabasi_albert_graph\n",
" prob_neighbor_spread = 0.5\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": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = barabasi_albert_graph\n",
" prob_neighbor_spread = 0.75\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": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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": [
2024-04-11 15:46:45 +00:00
"- Running for parameters: \n",
" n = 100\n",
" generator = barabasi_albert_graph\n",
" prob_neighbor_spread = 1.0\n"
2023-04-20 15:56:44 +00:00
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
2024-04-11 15:46:45 +00:00
"model_id": "",
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-24 16:46:09 +00:00
"it = NewsEnvComplete.run(name=f\"newspread\",\n",
2024-04-11 15:46:45 +00:00
" iterations=5,\n",
" max_time=30,\n",
" level='WARNING',\n",
" dump=True,\n",
" overwrite=True,\n",
" matrix=dict(n=[N],\n",
" generator=generators,\n",
" prob_neighbor_spread=probabilities))"
2023-04-20 15:56:44 +00:00
]
},
{
"cell_type": "code",
2024-04-11 15:46:45 +00:00
"execution_count": 44,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 45,
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": [
2024-04-11 15:46:45 +00:00
"\u001b[01;34msoil_output\u001b[0m\n",
"└── \u001b[01;34mnewspread\u001b[0m\n",
" ├── \u001b[00mnewspread_1712844336.8642576.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712844450.0526526.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846070.381033.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846089.2092683.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846145.296178.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846219.0644977.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846305.368385.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712846671.6566656.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712849017.0672383.dumped.yml\u001b[0m\n",
" ├── \u001b[00mnewspread_1712849444.2514122.dumped.yml\u001b[0m\n",
" └── \u001b[00mnewspread.sqlite\u001b[0m\n",
2023-04-20 15:56:44 +00:00
"\n",
2024-04-11 15:46:45 +00:00
"1 directory, 11 files\n",
"4,0K\tsoil_output/newspread/.ipynb_checkpoints\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",
2024-04-11 15:46:45 +00:00
"execution_count": 46,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 47,
2023-04-20 15:56:44 +00:00
"metadata": {},
2020-10-19 11:14:48 +00:00
"outputs": [
{
"data": {
2024-04-11 15:46:45 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAHHCAYAAABtF1i4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAAC/rUlEQVR4nOzdd1xT5/7A8U9ISBhhi4II4sCNCxe0dVQsjvJTa+1Vb0VbFxZ3bUW7rFixVXG0Wruuq9bbal23al11XBdeZ22luEBaFVBkyCbJ+f0ROTUyowzH83698tJz8j3P+Z4QyJNnHYUkSRKCIAiCIAjVxKK6ExAEQRAE4ekmKiOCIAiCIFQrURkRBEEQBKFaicqIIAiCIAjVSlRGBEEQBEGoVqIyIgiCIAhCtRKVEUEQBEEQqpWojAiCIAiCUK1EZUQQBEEQhGolKiOCYCZvb29efPHFCitv//79KBQKNmzYUGbs8OHD8fb2NtmnUCiYOXOmvL1y5UoUCgXx8fEVlmNJkpKSePnll3FxcUGhULBo0aJKP2dVGz58OFqttrrTMFtmZiYjR47Ezc0NhULBpEmTiI+PR6FQsHLlyupO76Hc/54XHn+iMvIUK/zQUigUHDp0qMjzkiTh6emJQqGo0A9foeotW7asUj6AJk+ezM6dO5k+fTpr1qyhZ8+eFX4O4cHMmTOHlStXMnbsWNasWcPQoUOrOyWzbN++XVQ4niKq6k5AqH5WVlZ89913PPvssyb7Dxw4wF9//YVGo6mmzIT7ffXVVxgMhlJjhg4dyqBBg0x+bsuWLaNGjRoMHz68QvP55Zdf6Nu3L1OnTq3QcoWH98svv9CpUyc++OADeZ8kSeTk5GBpaVmNmZXP9u3bWbp0abEVkpycHFQq8fH1JBEtIwK9e/dm/fr16HQ6k/3fffcdfn5+uLm5VVNmVSMrK6u6Uyg3S0vLMiuHSqUSKysrFApFpe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ZD++9//yvvu3Lkj1atXT/L29pZfk8Lrrl+/frHvk/tV9PtOp9NJ9erVk+rWrSulpqaaxBoMBvn/w4YNkwCTn5kkSVKbNm0kPz+/UnNOS0uT7OzspI4dO0o5OTnFniM/P1+qWbOm1KJFC5OYn376SQKk999//4Fyuf/3VpKM7z9AWrFihbzP19dXqlOnjnTnzh153/79+yXA5L1W+PPat29fmWUW5hkeHl7kNSnuZxMZGSkpFArp6tWr8r6wsDCppI+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",
2024-04-11 15:46:45 +00:00
"execution_count": 48,
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": {
2024-04-11 15:46:45 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAHHCAYAAABtF1i4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAA9hAAAPYQGoP6dpAADEp0lEQVR4nOzdeXhM59vA8e/MZGayr7KJELvYK3ZtaUVjqaKqrbaUoo2iVCm6UVQogmr76mppdUFb1Z+dWmqvtdZYIy1ZiCyyTmbmvH+EkZEdMcL9ua65mjnnOee5z6Ry7jnPplIURUEIIYQQwkbUtg5ACCGEEA82SUaEEEIIYVOSjAghhBDCpiQZEUIIIYRNSTIihBBCCJuSZEQIIYQQNiXJiBBCCCFsSpIRIYQQQtiUJCNCCCGEsClJRoSwsQkTJqBSqWxS999//03r1q1xcnJCpVJx8ODBAstt3rwZlUrF5s2bb6me+Ph4nnnmGby8vFCpVMyePfuWY77bbvfahRDFk2REiJssWLAAlUplednZ2REQEEC/fv24cOHCLZ0zIyODCRMm3FM3tJycHHr16sWVK1eYNWsW3333HVWqVCmTut58803Wrl3LuHHj+O677+jYseMdr2PKlCksX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09++eUXjhw5ku/4S5cuWX7u3LkzFy9eZNmyZZZtGRkZfPnllyW6nurVq5OSksI///xj2RYbG5tv9NOVK1fyHdu4cWMAy7DdZ599lgsXLvDVV1/lK5uZmVm
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",
2024-04-11 15:46:45 +00:00
"execution_count": 49,
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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
"0 39063f8 newspread_1712849444.2514122 erdos_renyi_graph \n",
" 8f26adb newspread_1712849444.2514122 barabasi_albert_graph \n",
" 92fdcb9 newspread_1712849444.2514122 erdos_renyi_graph \n",
" cb3dbca newspread_1712849444.2514122 erdos_renyi_graph \n",
" d1fe9c1 newspread_1712849444.2514122 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",
2024-04-11 15:46:45 +00:00
"0 39063f8 newspread_1712849444.2514122 100 1.0 \n",
" 8f26adb newspread_1712849444.2514122 100 0.5 \n",
" 92fdcb9 newspread_1712849444.2514122 100 0.25 \n",
" cb3dbca newspread_1712849444.2514122 100 0.5 \n",
" d1fe9c1 newspread_1712849444.2514122 100 1.0 "
2020-10-19 11:14:48 +00:00
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 49,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 50,
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",
2024-04-11 15:46:45 +00:00
" <th>newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
" <td>/media/j/JsTickData/git/gsi-upm/soil/docs/tuto...</td>\n",
2023-04-20 15:56:44 +00:00
" <td>{}</td>\n",
2024-04-11 15:46:45 +00:00
" <td>30</td>\n",
2023-04-20 15:56:44 +00:00
" <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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 ... 1 \n",
2023-04-20 15:56:44 +00:00
"\n",
2023-05-03 10:14:49 +00:00
" exporters \\\n",
"simulation_id \n",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 [\"<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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 {} {} {} \n",
2023-03-23 13:49:09 +00:00
"\n",
2023-04-24 16:05:07 +00:00
" outdir \\\n",
"simulation_id \n",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 /media/j/JsTickData/git/gsi-upm/soil/docs/tuto... \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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 {} 30 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
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 50,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 51,
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",
2024-04-11 15:46:45 +00:00
" <th rowspan=\"5\" valign=\"top\">newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 ff1d24a 0 0 101 0.0 \n",
2023-05-03 10:14:49 +00:00
" 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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 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
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 51,
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",
2024-04-11 15:46:45 +00:00
"execution_count": 52,
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",
2024-04-11 15:46:45 +00:00
" <th rowspan=\"5\" valign=\"top\">newspread_1712849444.2514122</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",
2024-04-11 15:46:45 +00:00
"newspread_1712849444.2514122 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
]
},
2024-04-11 15:46:45 +00:00
"execution_count": 52,
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",
2024-04-11 15:46:45 +00:00
"version": "3.10.12"
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,
2024-04-11 15:46:45 +00:00
"nbformat_minor": 4
2017-10-18 18:28:42 +00:00
}