Last active
September 29, 2021 09:45
-
-
Save MJacobs1985/93e9c856056d8fe376827cc3986429ae to your computer and use it in GitHub Desktop.
Network Graphs for Epidemiology
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import ndlib.models.ModelConfig as mc | |
import ndlib.models.epidemics as ep | |
from ndlib.viz.mpl.DiffusionTrend import DiffusionTrend | |
# Network topology | |
g = nx.erdos_renyi_graph(1000, 0.1) # 1000 nodes with 10% probability of edge creation | |
# Model selection | |
model = ep.SEIRModel(g) | |
model2 = ep.SEIRctModel(g) | |
model3 = ep.SEISModel(g) | |
# Model Configuration | |
cfg = mc.Configuration() | |
cfg.add_model_parameter('beta', 0.01) # Infection probability S -> I | |
cfg.add_model_parameter('lambda', 0.9) # Recovery probability I -> S | |
cfg.add_model_parameter('gamma', 0.005) # Removal probability I -> R | |
cfg.add_model_parameter('alpha', 0.05) # Latent Period E -> I | |
cfg.add_model_parameter("fraction_infected", 0.05) # 50 infected nodes at start in the network | |
model.set_initial_status(cfg) | |
model2.set_initial_status(cfg) | |
model3.set_initial_status(cfg) | |
# Simulation execution | |
iterations = model.iteration_bunch(500) | |
trends = model.build_trends(iterations) | |
trends2 = model2.build_trends(iterations) | |
trends3 = model3.build_trends(iterations) | |
# Show simulation | |
viz = DiffusionTrend(model, trends) | |
viz.plot("diffusion") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment