Updated readthedocs

models
Tasio Mendez 7 years ago
parent f1bb636ca8
commit 23fc9671c3

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -13,11 +13,13 @@ Soil is an Agent-based Social Simulator in Python for modelling and simulation o
:caption: Learn more about soil:
installation
usage
models
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

@ -0,0 +1,112 @@
Developing new models
---------------------
This document describes how to develop a new analysis model.
What is a model?
================
A model defines the behaviour of the agents with a view to assessing their effects on the system as a whole.
In practice, a model consists of at least two parts:
* Python module: the actual code that describes the behaviour.
* Setting up the variables in the Simulation Settings JSON file.
This separation allows us to run the simulation with different agents.
Models Code
===========
All the models are imported to the main file. The initialization look like this:
.. code:: python
import settings
networkStatus = {} # Dict that will contain the status of every agent in the network
sentimentCorrelationNodeArray = []
for x in range(0, settings.number_of_nodes):
sentimentCorrelationNodeArray.append({'id': x})
# Initialize agent states. Let's assume everyone is normal.
init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)]
# add keys as as necessary, but "id" must always refer to that state category
A new model have to inherit the BaseBehaviour class which is in the same module.
There are two basics methods:
* __init__
* step: used to define the behaviour over time.
Variable Initialization
=======================
The different parameters of the model have to be initialize in the Simulation Settings JSON file which will be
passed as a parameter to the simulation.
.. code:: json
{
"agent": ["SISaModel","ControlModelM2"],
"neutral_discontent_spon_prob": 0.04,
"neutral_discontent_infected_prob": 0.04,
"neutral_content_spon_prob": 0.18,
"neutral_content_infected_prob": 0.02,
"discontent_neutral": 0.13,
"discontent_content": 0.07,
"variance_d_c": 0.02,
"content_discontent": 0.009,
"variance_c_d": 0.003,
"content_neutral": 0.088,
"standard_variance": 0.055,
"prob_neutral_making_denier": 0.035,
"prob_infect": 0.075,
"prob_cured_healing_infected": 0.035,
"prob_cured_vaccinate_neutral": 0.035,
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
}
In this file you will also define the models you are going to simulate. You can simulate as many models as you want.
The simulation returns one result for each model. For the usage, see :doc:`usage`.
Example Model
=============
In this section, we will implement a Sentiment Correlation Model.
The class would look like this:
.. code:: python
from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray
class SentimentCorrelationModel(BaseBehaviour):
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
self.outside_effects_prob = environment.environment_params['outside_effects_prob']
self.anger_prob = environment.environment_params['anger_prob']
self.joy_prob = environment.environment_params['joy_prob']
self.sadness_prob = environment.environment_params['sadness_prob']
self.disgust_prob = environment.environment_params['disgust_prob']
self.time_awareness = []
for i in range(4): # In this model we have 4 sentiments
self.time_awareness.append(0) # 0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
def step(self, now):
self.behaviour() # Method which define the behaviour
super().step(now)
The variables will be modified by the user, so you have to include them in the Simulation Settings JSON file.

@ -0,0 +1,98 @@
Usage
-----
First of all, you need to install the package. See :doc:`installation` for installation instructions.
Simulation Settings
===================
Once installed, before running a simulation, you need to configure it.
* In the settings.py file you will find the configuration of the network.
.. code:: python
# Network settings
network_type = 1
number_of_nodes = 1000
max_time = 50
num_trials = 1
timeout = 2
* In the Simulation Settings JSON file, you will find the configuration of the models.
Network Types
=============
There are three types of network implemented, but you could add more.
.. code:: python
if settings.network_type == 0:
G = nx.complete_graph(settings.number_of_nodes)
if settings.network_type == 1:
G = nx.barabasi_albert_graph(settings.number_of_nodes, 10)
if settings.network_type == 2:
G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None)
# More types of networks can be added here
Models Settings
===============
After having configured the simulation, the next step is setting up the variables of the models.
For this, you will need to modify the Simulation Settings JSON file.
.. code:: json
{
"agent": ["SISaModel","ControlModelM2"],
"neutral_discontent_spon_prob": 0.04,
"neutral_discontent_infected_prob": 0.04,
"neutral_content_spon_prob": 0.18,
"neutral_content_infected_prob": 0.02,
"discontent_neutral": 0.13,
"discontent_content": 0.07,
"variance_d_c": 0.02,
"content_discontent": 0.009,
"variance_c_d": 0.003,
"content_neutral": 0.088,
"standard_variance": 0.055,
"prob_neutral_making_denier": 0.035,
"prob_infect": 0.075,
"prob_cured_healing_infected": 0.035,
"prob_cured_vaccinate_neutral": 0.035,
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
}
In this file you will define the different models you are going to simulate. You can simulate as many models
as you want.
After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed
in the documentation of each model.
Parameter validation will fail if a required parameter without a default has not been provided.
Running the Simulation
======================
After setting all the configuration, you will be able to run the simulation. All you need to do is execute:
.. code:: bash
python soil.py
The simulation will return a dynamic graph .gexf file which could be visualized with
`Gephi <https://gephi.org/users/download/>`__.
It will also return one .png picture for each model simulated.

@ -0,0 +1,96 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&lt;no title&gt; &#8212; Soil 0.1 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Models" href="models.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="models.html" title="previous chapter">Models</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/demo.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2017, GSI.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.5.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
|
<a href="_sources/demo.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

@ -49,16 +49,22 @@
<p class="caption"><span class="caption-text">Learn more about soil:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="usage.html">Usage</a><ul>
<li class="toctree-l2"><a class="reference internal" href="usage.html#simulation-settings">Simulation Settings</a></li>
<li class="toctree-l2"><a class="reference internal" href="usage.html#network-types">Network Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="usage.html#models-settings">Models Settings</a></li>
<li class="toctree-l2"><a class="reference internal" href="usage.html#running-the-simulation">Running the Simulation</a></li>
</ul>
</div>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
</li>
<li class="toctree-l1"><a class="reference internal" href="models.html">Developing new models</a><ul>
<li class="toctree-l2"><a class="reference internal" href="models.html#what-is-a-model">What is a model?</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html#models-code">Models Code</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html#variable-initialization">Variable Initialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="models.html#example-model">Example Model</a></li>
</ul>
</li>
</ul>
</div>
</div>
@ -66,13 +72,7 @@
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="#">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Welcome to Soil&#8217;s documentation!</a></li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>
<div class="relations">
<div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="#">Documentation overview</a><ul>

@ -0,0 +1,210 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Developing new models &#8212; Soil 0.1 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Usage" href="usage.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="developing-new-models">
<h1>Developing new models<a class="headerlink" href="#developing-new-models" title="Permalink to this headline"></a></h1>
<p>This document describes how to develop a new analysis model.</p>
<div class="section" id="what-is-a-model">
<h2>What is a model?<a class="headerlink" href="#what-is-a-model" title="Permalink to this headline"></a></h2>
<p>A model defines the behaviour of the agents with a view to assessing their effects on the system as a whole.
In practice, a model consists of at least two parts:</p>
<ul class="simple">
<li>Python module: the actual code that describes the behaviour.</li>
<li>Setting up the variables in the Simulation Settings JSON file.</li>
</ul>
<p>This separation allows us to run the simulation with different agents.</p>
</div>
<div class="section" id="models-code">
<h2>Models Code<a class="headerlink" href="#models-code" title="Permalink to this headline"></a></h2>
<p>All the models are imported to the main file. The initialization look like this:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">settings</span>
<span class="n">networkStatus</span> <span class="o">=</span> <span class="p">{}</span> <span class="c1"># Dict that will contain the status of every agent in the network</span>
<span class="n">sentimentCorrelationNodeArray</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">):</span>
<span class="n">sentimentCorrelationNodeArray</span><span class="o">.</span><span class="n">append</span><span class="p">({</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="n">x</span><span class="p">})</span>
<span class="c1"># Initialize agent states. Let&#39;s assume everyone is normal.</span>
<span class="n">init_states</span> <span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="p">}</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">)]</span>
<span class="c1"># add keys as as necessary, but &quot;id&quot; must always refer to that state category</span>
</pre></div>
</div>
<p>A new model have to inherit the BaseBehaviour class which is in the same module.
There are two basics methods:</p>
<ul class="simple">
<li>__init__</li>
<li>step: used to define the behaviour over time.</li>
</ul>
</div>
<div class="section" id="variable-initialization">
<h2>Variable Initialization<a class="headerlink" href="#variable-initialization" title="Permalink to this headline"></a></h2>
<p>The different parameters of the model have to be initialize in the Simulation Settings JSON file which will be
passed as a parameter to the simulation.</p>
<div class="code json highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">&quot;agent&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;SISaModel&quot;</span><span class="p">,</span><span class="s2">&quot;ControlModelM2&quot;</span><span class="p">],</span>
<span class="s2">&quot;neutral_discontent_spon_prob&quot;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
<span class="s2">&quot;neutral_discontent_infected_prob&quot;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
<span class="s2">&quot;neutral_content_spon_prob&quot;</span><span class="p">:</span> <span class="mf">0.18</span><span class="p">,</span>
<span class="s2">&quot;neutral_content_infected_prob&quot;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
<span class="s2">&quot;discontent_neutral&quot;</span><span class="p">:</span> <span class="mf">0.13</span><span class="p">,</span>
<span class="s2">&quot;discontent_content&quot;</span><span class="p">:</span> <span class="mf">0.07</span><span class="p">,</span>
<span class="s2">&quot;variance_d_c&quot;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
<span class="s2">&quot;content_discontent&quot;</span><span class="p">:</span> <span class="mf">0.009</span><span class="p">,</span>
<span class="s2">&quot;variance_c_d&quot;</span><span class="p">:</span> <span class="mf">0.003</span><span class="p">,</span>
<span class="s2">&quot;content_neutral&quot;</span><span class="p">:</span> <span class="mf">0.088</span><span class="p">,</span>
<span class="s2">&quot;standard_variance&quot;</span><span class="p">:</span> <span class="mf">0.055</span><span class="p">,</span>
<span class="s2">&quot;prob_neutral_making_denier&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_infect&quot;</span><span class="p">:</span> <span class="mf">0.075</span><span class="p">,</span>
<span class="s2">&quot;prob_cured_healing_infected&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_cured_vaccinate_neutral&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_vaccinated_healing_infected&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_vaccinated_vaccinate_neutral&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_generate_anti_rumor&quot;</span><span class="p">:</span> <span class="mf">0.035</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In this file you will also define the models you are going to simulate. You can simulate as many models as you want.
The simulation returns one result for each model. For the usage, see <a class="reference internal" href="usage.html"><span class="doc">Usage</span></a>.</p>
</div>
<div class="section" id="example-model">
<h2>Example Model<a class="headerlink" href="#example-model" title="Permalink to this headline"></a></h2>
<p>In this section, we will implement a Sentiment Correlation Model.</p>
<p>The class would look like this:</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">..BaseBehaviour</span> <span class="k">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">..</span> <span class="k">import</span> <span class="n">sentimentCorrelationNodeArray</span>
<span class="k">class</span> <span class="nc">SentimentCorrelationModel</span><span class="p">(</span><span class="n">BaseBehaviour</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">environment</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">agent_id</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">state</span><span class="o">=</span><span class="p">()):</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">environment</span><span class="o">=</span><span class="n">environment</span><span class="p">,</span> <span class="n">agent_id</span><span class="o">=</span><span class="n">agent_id</span><span class="p">,</span> <span class="n">state</span><span class="o">=</span><span class="n">state</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">outside_effects_prob</span> <span class="o">=</span> <span class="n">environment</span><span class="o">.</span><span class="n">environment_params</span><span class="p">[</span><span class="s1">&#39;outside_effects_prob&#39;</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">anger_prob</span> <span class="o">=</span> <span class="n">environment</span><span class="o">.</span><span class="n">environment_params</span><span class="p">[</span><span class="s1">&#39;anger_prob&#39;</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">joy_prob</span> <span class="o">=</span> <span class="n">environment</span><span class="o">.</span><span class="n">environment_params</span><span class="p">[</span><span class="s1">&#39;joy_prob&#39;</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sadness_prob</span> <span class="o">=</span> <span class="n">environment</span><span class="o">.</span><span class="n">environment_params</span><span class="p">[</span><span class="s1">&#39;sadness_prob&#39;</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">disgust_prob</span> <span class="o">=</span> <span class="n">environment</span><span class="o">.</span><span class="n">environment_params</span><span class="p">[</span><span class="s1">&#39;disgust_prob&#39;</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">time_awareness</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span> <span class="c1"># In this model we have 4 sentiments</span>
<span class="bp">self</span><span class="o">.</span><span class="n">time_awareness</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c1"># 0-&gt; Anger, 1-&gt; joy, 2-&gt;sadness, 3 -&gt; disgust</span>
<span class="n">sentimentCorrelationNodeArray</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">][</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">now</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">def</span> <span class="nf">step</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">now</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">behaviour</span><span class="p">()</span> <span class="c1"># Method which define the behaviour</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">step</span><span class="p">(</span><span class="n">now</span><span class="p">)</span>
</pre></div>
</div>
<p>The variables will be modified by the user, so you have to include them in the Simulation Settings JSON file.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Developing new models</a><ul>
<li><a class="reference internal" href="#what-is-a-model">What is a model?</a></li>
<li><a class="reference internal" href="#models-code">Models Code</a></li>
<li><a class="reference internal" href="#variable-initialization">Variable Initialization</a></li>
<li><a class="reference internal" href="#example-model">Example Model</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="usage.html" title="previous chapter">Usage</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/models.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2017, GSI.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.5.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
|
<a href="_sources/models.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

@ -2,5 +2,5 @@
# Project: Soil
# Version: 0.1
# The remainder of this file is compressed using zlib.
xÚmŽ±Â0 D÷|…™<E280A6>ŠÄĘ0 !u`6±•FrbD\ ţž–´
•Řě»wöÎ1ż ťď,Đ!,ęa°$pžG×0R?C?ÄŤĹkb0…^Łě <4C>8ZÔĽÂĹPä»mo4}}Ö—”ţ´{Ľ»Ő¨™‹Ň(Ľô,ŚO?lU«p_ý+v…ţZÝ
xÚm<EFBFBD>Á
Â0 †ï}Šxò4Á«g/aˆçº†®<E280A0>6öSßÞuÙØ^JúåûÓÆbpÁàb2'ÒO$¨Ž`'zh“'¸”R-šá¦H+ã<>Ô°GH 5;ÚGœì1$<24>‡ÝŽI<13>·íŒ…Ï<E280A6>-Dy6Hq{$î\°ð=µJæÏFÝ·š¾²É„Ónõ«i· a"×Ò¿i*Çá\iâÝK©~my+

@ -1 +1 @@
Search.setIndex({docnames:["index","installation"],envversion:51,filenames:["index.rst","installation.rst"],objects:{},objnames:{},objtypes:{},terms:{The:1,about:0,agent:0,base:0,can:1,clone:1,cluster:1,content:[],dit:1,git:1,gitlab:1,gsi:1,http:1,index:0,instal:0,lab:1,latest:1,learn:0,model:0,modul:0,more:0,network:0,page:0,python:0,search:0,simul:0,social:0,soil:1,through:1,upm:1,version:1},titles:["Welcome to Soil&#8217;s documentation!","Installation"],titleterms:{document:0,indic:0,instal:1,soil:0,tabl:0,welcom:0}})
Search.setIndex({docnames:["index","usage"],envversion:51,filenames:["index.rst","usage.rst"],objects:{},objnames:{},objtypes:{},terms:{"class":[],"default":1,"import":[],"new":0,"return":1,"super":[],For:1,The:1,There:1,__init__:[],abl:1,about:0,actual:[],add:1,added:1,after:1,agent:[0,1],agent_id:[],all:1,allow:[],also:1,alwai:[],analysi:[],anger:[],anger_prob:[],append:[],assess:[],assum:[],barabasi_albert_graph:1,base:0,basebehaviour:[],basic:[],been:1,befor:1,behaviour:[],can:1,categori:[],clone:[],cluster:[],code:0,complete_graph:1,configur:1,consist:[],contain:[],content:[],content_discont:1,content_neutr:1,controlmodelm2:1,correl:[],could:1,def:[],defin:1,describ:[],develop:0,dict:[],differ:1,discontent_cont:1,discontent_neutr:1,disgust:[],disgust_prob:[],dit:[],doc:[],document:1,dynam:1,each:1,effect:[],env:[],environ:[],environment_param:[],everi:[],everyon:[],exampl:0,execut:1,fail:1,file:1,fill:[],find:1,first:1,from:[],gephi:1,gexf:1,git:[],gitlab:[],going:1,graph:1,gsi:[],has:1,have:1,here:1,how:[],http:[],implement:1,includ:[],index:[],inherit:[],init_st:[],initi:[0,1],instal:[0,1],instruct:1,joi:[],joy_prob:[],json:1,kei:[],lab:[],latest:[],learn:0,least:[],let:[],like:[],look:[],main:[],mani:1,margulis_gabber_galil_graph:1,max_tim:1,method:[],model:0,modifi:1,modul:[],more:[0,1],must:[],necessari:[],need:1,network:0,network_typ:1,networkstatu:[],neutral_content_infected_prob:1,neutral_content_spon_prob:1,neutral_discontent_infected_prob:1,neutral_discontent_spon_prob:1,next:1,none:1,normal:[],now:[],num_trial:1,number_of_nod:1,onc:1,one:1,outside_effects_prob:[],over:[],packag:1,page:[],paramet:1,part:[],pass:[],pictur:1,plugin:[],png:1,practic:[],prob_cured_healing_infect:1,prob_cured_vaccinate_neutr:1,prob_generate_anti_rumor:1,prob_infect:1,prob_neutral_making_deni:1,prob_vaccinated_healing_infect:1,prob_vaccinated_vaccinate_neutr:1,provid:1,python:[0,1],rang:[],refer:[],requir:1,result:[],run:0,sad:[],sadness_prob:[],same:[],search:[],section:[],see:1,self:[],sentiment:[],sentimentcorrelationmodel:[],sentimentcorrelationnodearrai:[],separ:[],set:0,simul:0,sisamodel:1,social:0,soil:1,standard_vari:1,state:[],statu:[],step:1,system:[],them:[],thi:1,three:1,through:[],time:[],time_awar:[],timeout:1,two:[],type:0,upm:[],usag:0,used:[],user:[],valid:1,variabl:[0,1],variance_c_d:1,variance_d_c:1,version:[],view:[],visual:1,want:1,what:0,which:1,whole:[],without:1,would:[],you:1},titles:["Welcome to Soil&#8217;s documentation!","Usage"],titleterms:{"new":[],code:[],develop:[],document:0,exampl:[],indic:[],initi:[],instal:[],model:1,network:1,run:1,set:1,simul:1,soil:0,tabl:[],type:1,usag:1,variabl:[],welcom:0,what:[]}})

@ -0,0 +1,196 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Usage &#8212; Soil 0.1 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Developing new models" href="models.html" />
<link rel="prev" title="Installation" href="installation.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body role="document">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="usage">
<h1>Usage<a class="headerlink" href="#usage" title="Permalink to this headline"></a></h1>
<p>First of all, you need to install the package. See <a class="reference internal" href="installation.html"><span class="doc">Installation</span></a> for installation instructions.</p>
<div class="section" id="simulation-settings">
<h2>Simulation Settings<a class="headerlink" href="#simulation-settings" title="Permalink to this headline"></a></h2>
<p>Once installed, before running a simulation, you need to configure it.</p>
<ul>
<li><p class="first">In the settings.py file you will find the configuration of the network.</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="c1"># Network settings</span>
<span class="n">network_type</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">number_of_nodes</span> <span class="o">=</span> <span class="mi">1000</span>
<span class="n">max_time</span> <span class="o">=</span> <span class="mi">50</span>
<span class="n">num_trials</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">timeout</span> <span class="o">=</span> <span class="mi">2</span>
</pre></div>
</div>
</li>
<li><p class="first">In the Simulation Settings JSON file, you will find the configuration of the models.</p>
</li>
</ul>
</div>
<div class="section" id="network-types">
<h2>Network Types<a class="headerlink" href="#network-types" title="Permalink to this headline"></a></h2>
<p>There are three types of network implemented, but you could add more.</p>
<div class="code python highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">network_type</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">complete_graph</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">)</span>
<span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">network_type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">barabasi_albert_graph</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">network_type</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">G</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">margulis_gabber_galil_graph</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">number_of_nodes</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="c1"># More types of networks can be added here</span>
</pre></div>
</div>
</div>
<div class="section" id="models-settings">
<h2>Models Settings<a class="headerlink" href="#models-settings" title="Permalink to this headline"></a></h2>
<p>After having configured the simulation, the next step is setting up the variables of the models.
For this, you will need to modify the Simulation Settings JSON file.</p>
<div class="code json highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="s2">&quot;agent&quot;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&quot;SISaModel&quot;</span><span class="p">,</span><span class="s2">&quot;ControlModelM2&quot;</span><span class="p">],</span>
<span class="s2">&quot;neutral_discontent_spon_prob&quot;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
<span class="s2">&quot;neutral_discontent_infected_prob&quot;</span><span class="p">:</span> <span class="mf">0.04</span><span class="p">,</span>
<span class="s2">&quot;neutral_content_spon_prob&quot;</span><span class="p">:</span> <span class="mf">0.18</span><span class="p">,</span>
<span class="s2">&quot;neutral_content_infected_prob&quot;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
<span class="s2">&quot;discontent_neutral&quot;</span><span class="p">:</span> <span class="mf">0.13</span><span class="p">,</span>
<span class="s2">&quot;discontent_content&quot;</span><span class="p">:</span> <span class="mf">0.07</span><span class="p">,</span>
<span class="s2">&quot;variance_d_c&quot;</span><span class="p">:</span> <span class="mf">0.02</span><span class="p">,</span>
<span class="s2">&quot;content_discontent&quot;</span><span class="p">:</span> <span class="mf">0.009</span><span class="p">,</span>
<span class="s2">&quot;variance_c_d&quot;</span><span class="p">:</span> <span class="mf">0.003</span><span class="p">,</span>
<span class="s2">&quot;content_neutral&quot;</span><span class="p">:</span> <span class="mf">0.088</span><span class="p">,</span>
<span class="s2">&quot;standard_variance&quot;</span><span class="p">:</span> <span class="mf">0.055</span><span class="p">,</span>
<span class="s2">&quot;prob_neutral_making_denier&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_infect&quot;</span><span class="p">:</span> <span class="mf">0.075</span><span class="p">,</span>
<span class="s2">&quot;prob_cured_healing_infected&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_cured_vaccinate_neutral&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_vaccinated_healing_infected&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_vaccinated_vaccinate_neutral&quot;</span><span class="p">:</span> <span class="mf">0.035</span><span class="p">,</span>
<span class="s2">&quot;prob_generate_anti_rumor&quot;</span><span class="p">:</span> <span class="mf">0.035</span>
<span class="p">}</span>
</pre></div>
</div>
<p>In this file you will define the different models you are going to simulate. You can simulate as many models
as you want.</p>
<p>After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed
in the documentation of each model.</p>
<p>Parameter validation will fail if a required parameter without a default has not been provided.</p>
</div>
<div class="section" id="running-the-simulation">
<h2>Running the Simulation<a class="headerlink" href="#running-the-simulation" title="Permalink to this headline"></a></h2>
<p>After setting all the configuration, you will be able to run the simulation. All you need to do is execute:</p>
<div class="code bash highlight-default"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">soil</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>The simulation will return a dynamic graph .gexf file which could be visualized with
<a class="reference external" href="https://gephi.org/users/download/">Gephi</a>.</p>
<p>It will also return one .png picture for each model simulated.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Usage</a><ul>
<li><a class="reference internal" href="#simulation-settings">Simulation Settings</a></li>
<li><a class="reference internal" href="#network-types">Network Types</a></li>
<li><a class="reference internal" href="#models-settings">Models Settings</a></li>
<li><a class="reference internal" href="#running-the-simulation">Running the Simulation</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
<li>Previous: <a href="installation.html" title="previous chapter">Installation</a></li>
<li>Next: <a href="models.html" title="next chapter">Developing new models</a></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/usage.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2017, GSI.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.5.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
|
<a href="_sources/usage.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>

@ -13,11 +13,13 @@ Soil is an Agent-based Social Simulator in Python for modelling and simulation o
:caption: Learn more about soil:
installation
usage
models
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

@ -0,0 +1,112 @@
Developing new models
---------------------
This document describes how to develop a new analysis model.
What is a model?
================
A model defines the behaviour of the agents with a view to assessing their effects on the system as a whole.
In practice, a model consists of at least two parts:
* Python module: the actual code that describes the behaviour.
* Setting up the variables in the Simulation Settings JSON file.
This separation allows us to run the simulation with different agents.
Models Code
===========
All the models are imported to the main file. The initialization look like this:
.. code:: python
import settings
networkStatus = {} # Dict that will contain the status of every agent in the network
sentimentCorrelationNodeArray = []
for x in range(0, settings.number_of_nodes):
sentimentCorrelationNodeArray.append({'id': x})
# Initialize agent states. Let's assume everyone is normal.
init_states = [{'id': 0, } for _ in range(settings.number_of_nodes)]
# add keys as as necessary, but "id" must always refer to that state category
A new model have to inherit the BaseBehaviour class which is in the same module.
There are two basics methods:
* __init__
* step: used to define the behaviour over time.
Variable Initialization
=======================
The different parameters of the model have to be initialize in the Simulation Settings JSON file which will be
passed as a parameter to the simulation.
.. code:: json
{
"agent": ["SISaModel","ControlModelM2"],
"neutral_discontent_spon_prob": 0.04,
"neutral_discontent_infected_prob": 0.04,
"neutral_content_spon_prob": 0.18,
"neutral_content_infected_prob": 0.02,
"discontent_neutral": 0.13,
"discontent_content": 0.07,
"variance_d_c": 0.02,
"content_discontent": 0.009,
"variance_c_d": 0.003,
"content_neutral": 0.088,
"standard_variance": 0.055,
"prob_neutral_making_denier": 0.035,
"prob_infect": 0.075,
"prob_cured_healing_infected": 0.035,
"prob_cured_vaccinate_neutral": 0.035,
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
}
In this file you will also define the models you are going to simulate. You can simulate as many models as you want.
The simulation returns one result for each model. For the usage, see :doc:`usage`.
Example Model
=============
In this section, we will implement a Sentiment Correlation Model.
The class would look like this:
.. code:: python
from ..BaseBehaviour import *
from .. import sentimentCorrelationNodeArray
class SentimentCorrelationModel(BaseBehaviour):
def __init__(self, environment=None, agent_id=0, state=()):
super().__init__(environment=environment, agent_id=agent_id, state=state)
self.outside_effects_prob = environment.environment_params['outside_effects_prob']
self.anger_prob = environment.environment_params['anger_prob']
self.joy_prob = environment.environment_params['joy_prob']
self.sadness_prob = environment.environment_params['sadness_prob']
self.disgust_prob = environment.environment_params['disgust_prob']
self.time_awareness = []
for i in range(4): # In this model we have 4 sentiments
self.time_awareness.append(0) # 0-> Anger, 1-> joy, 2->sadness, 3 -> disgust
sentimentCorrelationNodeArray[self.id][self.env.now] = 0
def step(self, now):
self.behaviour() # Method which define the behaviour
super().step(now)
The variables will be modified by the user, so you have to include them in the Simulation Settings JSON file.

@ -0,0 +1,98 @@
Usage
-----
First of all, you need to install the package. See :doc:`installation` for installation instructions.
Simulation Settings
===================
Once installed, before running a simulation, you need to configure it.
* In the settings.py file you will find the configuration of the network.
.. code:: python
# Network settings
network_type = 1
number_of_nodes = 1000
max_time = 50
num_trials = 1
timeout = 2
* In the Simulation Settings JSON file, you will find the configuration of the models.
Network Types
=============
There are three types of network implemented, but you could add more.
.. code:: python
if settings.network_type == 0:
G = nx.complete_graph(settings.number_of_nodes)
if settings.network_type == 1:
G = nx.barabasi_albert_graph(settings.number_of_nodes, 10)
if settings.network_type == 2:
G = nx.margulis_gabber_galil_graph(settings.number_of_nodes, None)
# More types of networks can be added here
Models Settings
===============
After having configured the simulation, the next step is setting up the variables of the models.
For this, you will need to modify the Simulation Settings JSON file.
.. code:: json
{
"agent": ["SISaModel","ControlModelM2"],
"neutral_discontent_spon_prob": 0.04,
"neutral_discontent_infected_prob": 0.04,
"neutral_content_spon_prob": 0.18,
"neutral_content_infected_prob": 0.02,
"discontent_neutral": 0.13,
"discontent_content": 0.07,
"variance_d_c": 0.02,
"content_discontent": 0.009,
"variance_c_d": 0.003,
"content_neutral": 0.088,
"standard_variance": 0.055,
"prob_neutral_making_denier": 0.035,
"prob_infect": 0.075,
"prob_cured_healing_infected": 0.035,
"prob_cured_vaccinate_neutral": 0.035,
"prob_vaccinated_healing_infected": 0.035,
"prob_vaccinated_vaccinate_neutral": 0.035,
"prob_generate_anti_rumor": 0.035
}
In this file you will define the different models you are going to simulate. You can simulate as many models
as you want.
After setting up the models, you have to initialize the parameters of each one. You will find the parameters needed
in the documentation of each model.
Parameter validation will fail if a required parameter without a default has not been provided.
Running the Simulation
======================
After setting all the configuration, you will be able to run the simulation. All you need to do is execute:
.. code:: bash
python soil.py
The simulation will return a dynamic graph .gexf file which could be visualized with
`Gephi <https://gephi.org/users/download/>`__.
It will also return one .png picture for each model simulated.

@ -1,5 +1,4 @@
# General configuration
import json
# Network settings
@ -9,12 +8,11 @@ max_time = 50
num_trials = 1
timeout = 2
with open('simulation_settings.json', 'r') as f:
environment_params = json.load(f)
'''
'''
environment_params = {
# Zombie model
'bite_prob': 0.01, # 0-1

@ -1,5 +1,4 @@
{
"agent": ["BaseBehaviour","SISaModel","ControlModelM2"],

@ -8,6 +8,7 @@ import models
import math
import json
#################
# Visualization #
#################
@ -25,7 +26,6 @@ def visualization(graph_name):
attributes[attribute] = emotionStatusAux
G.add_node(x, attributes)
print("Done!")
with open('data.txt', 'w') as outfile:
@ -33,9 +33,11 @@ def visualization(graph_name):
nx.write_gexf(G, graph_name+".gexf", version="1.2draft")
###########
# Results #
###########
def results(model_name):
x_values = []
infected_values = []
@ -106,14 +108,12 @@ if settings.network_type == 2:
agents = settings.environment_params['agent']
print("Using Agent(s): {agents}".format(agents=agents))
if len(agents) > 1:
for agent in agents:
sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.max_time,
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
print(str(agent))
results(str(agent))
@ -121,13 +121,7 @@ if len(agents) > 1:
else:
agent = agents[0]
sim = NetworkSimulation(topology=G, states=init_states, agent_type=locals()[agent], max_time=settings.max_time,
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
num_trials=settings.num_trials, logging_interval=1.0, **settings.environment_params)
sim.run_simulation()
results(str(agent))
visualization(str(agent))

Loading…
Cancel
Save