def test_multi(self): vm = MultiPlot() g = nx.erdos_renyi_graph(1000, 0.1) model = sir.SIRModel(g) config = mc.Configuration() config.add_model_parameter('beta', 0.001) config.add_model_parameter('gamma', 0.01) config.add_model_parameter("percentage_infected", 0.05) model.set_initial_status(config) iterations = model.iteration_bunch(200) trends = model.build_trends(iterations) viz = DiffusionTrend(model, trends) p = viz.plot() vm.add_plot(p) g = nx.erdos_renyi_graph(1000, 0.1) model = sir.SIRModel(g) config = mc.Configuration() config.add_model_parameter('beta', 0.001) config.add_model_parameter('gamma', 0.01) config.add_model_parameter("percentage_infected", 0.05) model.set_initial_status(config) iterations = model.iteration_bunch(200) trends = model.build_trends(iterations) viz = DiffusionPrevalence(model, trends) p1 = viz.plot() vm.add_plot(p1) m = vm.plot() self.assertIsInstance(m, Column)
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("percentage_infected", 0.05) model.set_initial_status(config) iterations = model.iteration_bunch(200) trends = model.build_trends(iterations) viz = DiffusionTrend(model, trends) p = viz.plot() vm.add_plot(p) 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("percentage_infected", 0.05) model.set_initial_status(config) iterations = model.iteration_bunch(200) trends = model.build_trends(iterations) viz = DiffusionPrevalence(model, trends) p1 = viz.plot() vm.add_plot(p1) m = vm.plot() self.assertIsInstance(m, Column)
def draw_epidemic_plot(model, trends): viz = DiffusionTrend(model, trends) p = viz.plot(width=650, height=500) viz2 = DiffusionPrevalence(model, trends) p2 = viz2.plot(width=650, height=500) vm = MultiPlot() vm.add_plot(p) vm.add_plot(p2) m = vm.plot() show(m)
def plot_trends(self,iterations): if self.config["UI"].getboolean("verbose"): print("Qu: Plotting trends ... ") trends = self._active_model.build_trends(iterations) viz = DiffusionTrend(self._active_model, trends) p = viz.plot(width=400, height=400) viz2 = DiffusionPrevalence(self._active_model, trends) p2 = viz2.plot(width=400, height=400) vm = MultiPlot() vm.add_plot(p) vm.add_plot(p2) m = vm.plot() show(m)
def plot_diffusion(model, iterations): output_notebook() # show bokeh in notebook trends = model.build_trends(iterations) viz = DiffusionTrend(model, trends) p = viz.plot(width=400, height=400) viz2 = DiffusionPrevalence(model, trends) p2 = viz2.plot(width=400, height=400) vm = MultiPlot() vm.add_plot(p) vm.add_plot(p2) m = vm.plot() show(m)
# Simulation execution iterations = model.iteration_bunch(200) trends = model.build_trends(iterations) from bokeh.io import output_notebook, show from ndlib.viz.bokeh.DiffusionTrend import DiffusionTrend viz1 = DiffusionTrend(model, trends) p = viz1.plot(width=400, height=400) # show(p) print(viz1) from ndlib.viz.bokeh.DiffusionPrevalence import DiffusionPrevalence viz2 = DiffusionPrevalence(model, trends) p2 = viz2.plot(width=400, height=400) from ndlib.viz.bokeh.MultiPlot import MultiPlot vm1 = MultiPlot() vm1.add_plot(p) vm1.add_plot(p2) m = None m = vm1.plot() show(m) #%% # pip install ndlib import networkx as nx import ndlib.models.epidemics.SIRModel as sir # Network Definition g = nx.erdos_renyi_graph(1000, 0.1) # Model Selection model = sir.SIRModel(g) import ndlib.models.ModelConfig as mc # Model Configuration
show(p) # In[7]: viz2 = DiffusionPrevalence(model, trends) p2 = viz2.plot(width=400, height=400) show(p2) # In[8]: vm = MultiPlot() vm.add_plot(p) vm.add_plot(p2) m = vm.plot() show(m) # ### Kertesz Threshold model # # The Kertesz Threshold model was introduced in 2015 by `Ruan` et al. [1] and it is an extension of the Watts threshold model [2]. # # We set the initial infected as well blocked node sets equals to the 10% of the overall population, assign a threshold of 0.25 to all the nodes and impose an probability of spontaneous adoptions of 40%. # # - [1] Z. Ruan, G. In ̃iguez, M. Karsai, and J. Kertész, “Kinetics of social contagion,” Phys. Rev. Lett., vol. 115, p. 218702, Nov 2015. # - [2] D.J. Watts, “A simple model of global cascades on random networks,” Proceedings of the National Academy of Sciences, vol. 99, no. 9, pp. 5766–5771, 2002. # In[18]:
import networkx as nx import ndlib.models.ModelConfig as mc import ndlib.models.epidemics as ep from bokeh.io import show from ndlib.viz.bokeh.DiffusionTrend import DiffusionTrend from ndlib.viz.bokeh.MultiPlot import MultiPlot # Network topology g = nx.erdos_renyi_graph(1000, 0.1) # Model selection model = ep.SIModel(g) # Model Configuration cfg = mc.Configuration() cfg.add_model_parameter('beta', 0.01) cfg.add_model_parameter("percentage_infected", 0.05) model.set_initial_status(cfg) # Simulation execution iterations = model.iteration_bunch(10) trends = model.build_trends(iterations) viz1 = DiffusionTrend(model, trends) p = viz1.plot(width=400, height=400) vm1 = MultiPlot() vm1.add_plot(p) m = vm1.plot() show(m)