# Path: ndlib/viz/bokeh/DiffusionPrevalence.py
# class DiffusionPrevalence(DiffusionPlot):
# 
#     def __init__(self, model, trends):
#         """
#         :param model: The model object
#         :param iterations: The computed simulation iterations
#         """
#         super(self.__class__, self).__init__(model, trends)
#         self.ylabel = "#Delta Nodes"
#         self.title = "Prevalence"
#         self.normalized = False
# 
#     def iteration_series(self, percentile=100):
# 
#         series = {k: [] for k in self.srev.keys()}
# 
#         presences = {k: [] for k in self.srev.keys()}
#         for t in self.trends:
# 
#             for st in t:
#                 for k in t[st]['status_delta']:
#                     presences[k].append(np.array(t[st]['status_delta'][k]))
# 
#         for st in presences:
#             tp = np.percentile(np.array(presences[st]), percentile, axis=0)
#             bp = np.percentile(np.array(presences[st]), 100 - percentile, axis=0)
#             av = np.average(np.array(presences[st]), axis=0)
#             series[st] = (tp, av, bp)
# 
#         return series
# 
# Path: ndlib/viz/bokeh/MultiPlot.py
# class MultiPlot(object):
# 
#     def __init__(self):
#         self.plots = []
# 
#     def add_plot(self, plot):
#         """
#         :param plot: The bokeh plot to add to the grid
#         """
#         self.plots.append(plot)
# 
#     def plot(self, ncols=2):
#         """
#         :param ncols: Number of grid columns
#         :return: a bokeh figure image
#         """
#         grid = gridplot(self.plots, ncols=ncols)
#         return grid
# 
# Path: ndlib/viz/bokeh/DiffusionTrend.py
# class DiffusionTrend(DiffusionPlot):
# 
#     def __init__(self, model, trends):
#         """
#         :param model: The model object
#         :param iterations: The computed simulation iterations
#         """
#         super(self.__class__, self).__init__(model, trends)
#         self.ylabel = "#Nodes"
#         self.title = "Diffusion Trend"
# 
#     def iteration_series(self, percentile=100):
#         series = {k: [] for k in self.srev.keys()}
# 
#         presences = {k: [] for k in self.srev.keys()}
#         for t in self.trends:
# 
#             for st in t:
#                 for k in t[st]['node_count']:
#                     presences[k].append(np.array(t[st]['node_count'][k]))
# 
#         for st in presences:
#             tp = np.percentile(np.array(presences[st]), percentile, axis=0)
#             bp = np.percentile(np.array(presences[st]), 100 - percentile, axis=0)
#             av = np.average(np.array(presences[st]), axis=0)
#             series[st] = (tp, av, bp)
# 
#         return series


import unittest
import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.epidemics as epd
from bokeh.models.layouts import Column
from bokeh.plotting.figure import Figure
from ndlib.viz.bokeh.DiffusionPrevalence import DiffusionPrevalence
from ndlib.viz.bokeh.MultiPlot import MultiPlot
from ndlib.viz.bokeh.DiffusionTrend import DiffusionTrend
        p = viz.plot()
        self.assertIsInstance(p, Figure)

    def test_visualize_prevalence(self):
        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("fraction_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)
        viz = DiffusionPrevalence(model, trends)
        p = viz.plot()
        self.assertIsInstance(p, Figure)

    def test_multi(self):

        vm = MultiPlot()

        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("fraction_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)

# Path: ndlib/viz/bokeh/DiffusionPrevalence.py
# class DiffusionPrevalence(DiffusionPlot):
# 
#     def __init__(self, model, trends):
#         """
#         :param model: The model object
#         :param iterations: The computed simulation iterations
#         """
#         super(self.__class__, self).__init__(model, trends)
#         self.ylabel = "#Delta Nodes"
#         self.title = "Prevalence"
#         self.normalized = False
# 
#     def iteration_series(self, percentile=100):
# 
#         series = {k: [] for k in self.srev.keys()}
# 
#         presences = {k: [] for k in self.srev.keys()}
#         for t in self.trends:
# 
#             for st in t:
#                 for k in t[st]['status_delta']:
#                     presences[k].append(np.array(t[st]['status_delta'][k]))
# 
#         for st in presences:
#             tp = np.percentile(np.array(presences[st]), percentile, axis=0)
#             bp = np.percentile(np.array(presences[st]), 100 - percentile, axis=0)
#             av = np.average(np.array(presences[st]), axis=0)
#             series[st] = (tp, av, bp)
# 
#         return series
# 
# Path: ndlib/viz/bokeh/MultiPlot.py
# class MultiPlot(object):
# 
#     def __init__(self):
#         self.plots = []
# 
#     def add_plot(self, plot):
#         """
#         :param plot: The bokeh plot to add to the grid
#         """
#         self.plots.append(plot)
# 
#     def plot(self, ncols=2):
#         """
#         :param ncols: Number of grid columns
#         :return: a bokeh figure image
#         """
#         grid = gridplot(self.plots, ncols=ncols)
#         return grid
# 
# Path: ndlib/viz/bokeh/DiffusionTrend.py
# class DiffusionTrend(DiffusionPlot):
# 
#     def __init__(self, model, trends):
#         """
#         :param model: The model object
#         :param iterations: The computed simulation iterations
#         """
#         super(self.__class__, self).__init__(model, trends)
#         self.ylabel = "#Nodes"
#         self.title = "Diffusion Trend"
# 
#     def iteration_series(self, percentile=100):
#         series = {k: [] for k in self.srev.keys()}
# 
#         presences = {k: [] for k in self.srev.keys()}
#         for t in self.trends:
# 
#             for st in t:
#                 for k in t[st]['node_count']:
#                     presences[k].append(np.array(t[st]['node_count'][k]))
# 
#         for st in presences:
#             tp = np.percentile(np.array(presences[st]), percentile, axis=0)
#             bp = np.percentile(np.array(presences[st]), 100 - percentile, axis=0)
#             av = np.average(np.array(presences[st]), axis=0)
#             series[st] = (tp, av, bp)
# 
#         return series


# Path: ndlib/test/test_viz.py
import unittest
import networkx as nx
import ndlib.models.ModelConfig as mc
import ndlib.models.epidemics as epd
from bokeh.models.layouts import Column
from bokeh.plotting.figure import Figure
from ndlib.viz.bokeh.DiffusionPrevalence import DiffusionPrevalence
from ndlib.viz.bokeh.MultiPlot import MultiPlot
from ndlib.viz.bokeh.DiffusionTrend import DiffusionTrend

        p = viz.plot()
        self.assertIsInstance(p, Figure)

    def test_visualize_prevalence(self):
        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("fraction_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)
        viz = DiffusionPrevalence(model, trends)
        p = viz.plot()
        self.assertIsInstance(p, Figure)

    def test_multi(self):

        vm = MultiPlot()

        g = nx.erdos_renyi_graph(1000, 0.1)
        model = epd.SIRModel(g)
        config = mc.Configuration()
        config.add_model_parameter('beta', 0.001)
        config.add_model_parameter('gamma', 0.01)
        config.add_model_parameter("fraction_infected", 0.05)
        model.set_initial_status(config)
        iterations = model.iteration_bunch(200)
        trends = model.build_trends(iterations)

        viz = DiffusionTrend(model, trends)