Skip to content

Commit

Permalink
bugfix + docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed Jul 27, 2017
1 parent e1a76c0 commit 5bc2c0b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NDlib is a Python software package that allows to describe, simulate, and study

=========== ============= =================== ================== ========== ===============
**Release** **Date** **Python Versions** **Main Author** **GitHub** **pypl**
2.0.1 May 31, 2017 2.7.x/3.x `Giulio Rossetti`_ `Source`_ `Distribution`_
2.1.0 July 27, 2017 2.7.x/3.x `Giulio Rossetti`_ `Source`_ `Distribution`_
=========== ============= =================== ================== ========== ===============


Expand Down
2 changes: 1 addition & 1 deletion docs/reference/viz/mpl/DiffusionPrevalence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Below is shown an example of Diffusion Prevalence description and visualization
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.01)
cfg.add_model_parameter("percentage_infected", 16 0.05)
cfg.add_model_parameter("percentage_infected", 0.01)
model.set_initial_status(cfg)
# Simulation execution
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/viz/mpl/DiffusionTrend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Below is shown an example of Diffusion Trend description and visualization for t
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.01)
cfg.add_model_parameter("percentage_infected", 16 0.05)
cfg.add_model_parameter("percentage_infected", 0.01)
model.set_initial_status(cfg)
# Simulation execution
Expand Down
20 changes: 10 additions & 10 deletions docs/reference/viz/mpl/PrevalenceComparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Below is shown an example of Diffusion Prevalence description and visualization
import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.epidemics.SIRModel as sir
import ndlib.models.epidemics.SIRModel as sir
import ndlib.models.epidemics.SIModel as si
from ndlib.viz.mpl.PrevalenceComparison import DiffusionPrevalenceComparison
Expand All @@ -31,22 +32,21 @@ Below is shown an example of Diffusion Prevalence description and visualization
# Model Configuration
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.01)
cfg.add_model_parameter("percentage_infected", 16 0.05)
cfg.add_model_parameter('gamma', 0.02)
cfg.add_model_parameter("percentage_infected", 0.01)
model.set_initial_status(cfg)
# Simulation execution
iterations = model.iteration_bunch(200)
trends = model.build_trends(iterations)
# 2° Model selection
model1 = sir.SIRModel(g)
model1 = si.SIModel(g)
# 2° Model Configuration
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.004)
cfg.add_model_parameter('gamma', 0.02)
cfg.add_model_parameter("percentage_infected", 0.05)
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter("percentage_infected", 0.01)
model1.set_initial_status(cfg)
# 2° Simulation execution
Expand All @@ -59,9 +59,9 @@ Below is shown an example of Diffusion Prevalence description and visualization
.. figure:: diff_prevalence.png
.. figure:: prevalence_comparison.png
:scale: 80 %
:align: center
:alt: SIR Diffusion Prevalence Example
:alt: SIR-SI Diffusion Prevalence Comparison Example

SIR Diffusion Prevalence Example.
SIR-SI Diffusion Prevalence Comparison Example.
12 changes: 6 additions & 6 deletions docs/reference/viz/mpl/TrendComparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Below is shown an example of Diffusion Trend description and visualization for t
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.01)
cfg.add_model_parameter("percentage_infected", 0.05)
cfg.add_model_parameter("percentage_infected", 0.01)
model.set_initial_status(cfg)
# Simulation execution
Expand All @@ -43,9 +43,9 @@ Below is shown an example of Diffusion Trend description and visualization for t
# 2° Model Configuration
cfg = mc.Configuration()
cfg.add_model_parameter('beta', 0.004)
cfg.add_model_parameter('beta', 0.001)
cfg.add_model_parameter('gamma', 0.02)
cfg.add_model_parameter("percentage_infected", 0.05)
cfg.add_model_parameter("percentage_infected", 0.01)
model1.set_initial_status(cfg)
# 2° Simulation execution
Expand All @@ -59,9 +59,9 @@ Below is shown an example of Diffusion Trend description and visualization for t
.. figure:: diff_trend.png
.. figure:: trend_comparison.png
:scale: 80 %
:align: center
:alt: SIR Diffusion Trend Example
:alt: SIR-SI Diffusion Trend Comparison Example

SIR Diffusion Trend Example.
SIR-SI Diffusion Trend Comparison Example.
Binary file modified docs/reference/viz/mpl/diff_prevalence.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/viz/mpl/diff_trend.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reference/viz/mpl/prevalence_comparison.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/reference/viz/mpl/trend_comparison.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions ndlib/viz/mpl/ComparisonViz.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InitializationException(Exception):
class ComparisonPlot(object):
__metaclass__ = abc.ABCMeta

def __init__(self, models, trends, statuses=("Infected")):
def __init__(self, models, trends, statuses=["Infected"]):
self.models = models
self.trends = trends
if len(models) != len(trends):
Expand All @@ -37,7 +37,10 @@ def __init__(self, models, trends, statuses=("Infected")):
self.srev["%s_%s" % (model.name, i)] = srev
i += 1

cls = set(statuses) & set(available_classes.keys())
if type(statuses) == list:
cls = set(statuses) & set(available_classes.keys())
else:
cls = set([statuses]) & set(available_classes.keys())
if len(cls) > 0:
self.classes = cls
else:
Expand Down Expand Up @@ -77,12 +80,12 @@ def plot(self, filename, percentile=90):
mx = len(l[st][0])
if self.normalized:
plt.plot(range(0, mx), l[st][1]/self.nnodes, lw=2,
label="%s - %s" % (self.mnames[i].split("_")[0], st), alpha=0.9, color=cols[h+j])
label="%s - %s" % (k.split("_")[0], st), alpha=0.9, color=cols[h+j])
plt.fill_between(range(0, mx), l[st][0]/self.nnodes,
l[st][2]/self.nnodes, alpha=0.2, color=cols[h+j])
else:
plt.plot(range(0, mx), l[st][1], lw=2,
label="%s - %s" % (self.mnames[i].split("_")[0], st), alpha=0.9, color=cols[h + j])
label="%s - %s" % (k.split("_")[0], st), alpha=0.9, color=cols[h + j])
plt.fill_between(range(0, mx), l[st][0],
l[st][2], alpha=0.2, color=cols[h + j])
j += 1
Expand Down

0 comments on commit 5bc2c0b

Please sign in to comment.