plot ( t, I, '-.', label = 'Homogeneous pairwise', linewidth = 5 ) t, S, I = EoN. SIS_homogeneous_pairwise_from_graph ( G, tau, gamma, rho = rho, tmax = tmax ) plt. #we expect a homogeneous model to perform poorly because the degree #distribution is very heterogeneous t, S, I = EoN. #There are versions of these functions that allow you to specify the #initial conditions rather than starting from a graph. Read in the degree distribution of G #and use rho to initialize the various model equations. plot ( t, I, color = 'k', alpha = 0.3 ) #Now compare with ODE predictions. plot ( t, I, color = 'k', alpha = 0.3, label = 'Simulation' ) plt. fast_SIS ( G, tau, gamma, rho = rho, tmax = tmax ) if counter = 0 : plt. barabasi_albert_graph ( N, 5 ) #create a barabasi-albert graph for counter in range ( iterations ): t, S, I = EoN. Simulation is much slower so need smaller network N = 10 ** 4 G = nx. The preferential mixing version of the EBCM approach provides the best approximation plot ( t, I, label = 'Pref mix EBCM', linewidth = 5, dashes = ) plt. EBCM_pref_mix_from_graph ( G, tau, gamma, rho = rho, tmax = tmax ) plt. plot ( t, I, '-', label = 'EBCM approximation', linewidth = 5 ) #the preferential mixing model captures degree correlations. EBCM_from_graph ( G, tau, gamma, rho = rho, tmax = tmax ) plt. plot ( t, I, ':', label = 'Heterogeneous meanfield', linewidth = 5 ) #The EBCM model does not account for degree correlations or clustering t, S, I, R = EoN. SIR_heterogeneous_meanfield_from_graph ( G, tau, gamma, rho = rho, tmax = tmax ) plt. plot ( t, I, '-.', label = 'Homogeneous pairwise', linewidth = 5 ) #meanfield models will generally overestimate SIR growth because they #treat partnerships as constantly changing. SIR_homogeneous_pairwise_from_graph ( G, tau, gamma, rho = rho, tmax = tmax ) plt.
#we expect a homogeneous model to perform poorly because the degree #distribution is very heterogeneous t, S, I, R = EoN. fast_SIR ( G, tau, gamma, rho = rho, tmax = tmax ) if counter = 0 : plt.
barabasi_albert_graph ( N, 5 ) #create a barabasi-albert graph tmax = 20 iterations = 5 #run 5 simulations tau = 0.1 #transmission rate gamma = 1.0 #recovery rate rho = 0.005 #random fraction initially infected for counter in range ( iterations ): #run simulations t, S, I, R = EoN. Import networkx as nx import matplotlib.pyplot as plt import EoN N = 10 ** 5 G = nx.