def process_degree_distribution(N, Pk, color, Psi, DPsi, symbol, label, count): report_times = scipy.linspace(0, 30, 3000) sums = 0 * report_times for cnt in range(count): G = generate_network(Pk, N) t, S, I, R = EoN.fast_SIR(G, tau, gamma, rho=rho) plt.plot(t, I * 1. / N, '-', color=color, alpha=0.1, linewidth=1) subsampled_I = EoN.subsample(report_times, t, I) sums += subsampled_I * 1. / N ave = sums / count plt.plot(report_times, ave, color='k') #Do EBCM N = G.order( ) #N is arbitrary, but included because our implementation of EBCM assumes N is given. t, S, I, R = EoN.EBCM_uniform_introduction(N, Psi, DPsi, tau, gamma, rho, tmin=0, tmax=10, tcount=41) plt.plot(t, I / N, symbol, color=color, markeredgecolor='k', label=label) for cnt in range(3): #do 3 highlighted simulations G = generate_network(Pk, N) t, S, I, R = EoN.fast_SIR(G, tau, gamma, rho=rho) plt.plot(t, I * 1. / N, '-', color='k', linewidth=0.1)
def SIR_process(G, degree_prob, tau, gamma, tmax=10): N = G.order() plt.figure(2) plt.clf() plt.figure(3) plt.clf() plt.figure(5) plt.clf() for index, starting_node in enumerate([x * N / 100. for x in range(100)]): plt.figure(2) t, S, I, R = EoN.fast_SIR(G, tau, gamma, initial_infecteds=[starting_node]) subt = scipy.linspace(0, t[-1], 101) subI, subR = EoN.subsample(subt, t, I, R) plt.plot(subt, subI) if R[-1] > 500: plt.figure(3) shift = EoN.get_time_shift(t, R, threshold) plt.plot(subt - shift, subI) plt.figure(5) plt.plot(subt - shift, subR) #t, S, I, R = EoN.EBCM(degree_prob, tau, gamma, rho) rho = 1. / N def psi(x): return sum(degree_prob[k] * x**k for k in degree_prob) def psiPrime(x): return sum(k * degree_prob[k] * x**(k - 1) for k in degree_prob) t, S, I, R = EoN.EBCM_uniform_introduction(N, psi, psiPrime, tau, gamma, rho, tmax=tmax) shift = EoN.get_time_shift(t, R, threshold) plt.figure(2) #plt.savefig('sw_SIR_epi_N{}_p{}_k{}_tau{}.pdf'.format(N,p,k,tau)) plt.figure(3) plt.plot(t - shift, I, '--') plt.xlabel('$t$', fontsize=18) plt.ylabel('$I$', fontsize=18) #plt.set_xtick_labels(fontsize = 15) xmax = get_xmax(t - shift, I) plt.axis(xmax=xmax) plt.savefig('sw_SIR_epi_N{}_p{}_k{}_tau{}_shifted.pdf'.format( N, p, k, tau)) plt.figure(5) plt.plot(t - shift, R, '--')