def sim_and_plot(G, tau, gamma, rho, tmax, tcount, ax): t, S, I, R= EoN.fast_SIR(G, tau, gamma, rho = rho, tmax = tmax) report_times = scipy.linspace(0, tmax, tcount) I = EoN.subsample(report_times, t, I) ax.plot(report_times, I/N, color='grey', linewidth=5, alpha=0.3) t, S, I, R = EoN.SIR_heterogeneous_meanfield_from_graph(G, tau, gamma, rho=rho, tmax=tmax, tcount=tcount) ax.plot(t, I/N, '--') t, S, I, R = EoN.SIR_compact_pairwise_from_graph(G, tau, gamma, rho=rho, tmax=tmax, tcount=tcount) ax.plot(t, I/N) t, S, I, R = EoN.SIR_homogeneous_pairwise_from_graph(G, tau, gamma, rho=rho, tmax=tmax, tcount=tcount) ax.plot(t, I/N, '-.')
# In[7]: #we expect a homogeneous model to perform poorly because the degree #distribution is very heterogeneous t, S, I, R = EoN.SIR_homogeneous_pairwise_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. t, S, I, R = EoN.SIR_heterogeneous_meanfield_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.EBCM_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. t, S, I, R = EoN.EBCM_pref_mix_from_graph(G, tau, gamma, rho=rho, tmax=tmax) plt.plot(t, I, label='Pref mix EBCM', linewidth=5, dashes=[4, 2, 1, 2, 1, 2]) plt.xlabel('$t$') plt.ylabel('Number infected') plt.legend() # plt.savefig('SIR_BA_model_vs_sim.png') # The preferential mixing version of the EBCM approach provides the best approximation to the (gray) simulated epidemics.