import networkx as nx
import matplotlib.pyplot as plt
import EoN
ER网络上的仿真
N = 10**4
M = 4*N
ER = nx.gnm_random_graph(N, M)
SIS仿真
tau = 0.5 # transmission rate
gamma = 0.2 # recovery rate per node
t, S, I = EoN.fast_SIS(ER, tau=tau, gamma=gamma, tmax = 10)
plt.plot(t, S, color = 'r', label='S')
plt.plot(t, I, color = 'b', label='I')
plt.legend(loc=0)
plt.xlabel("$T$")
plt.ylabel("individuals")
SIR仿真
tau = 0.5 # transmission rate
gamma = 1.0 # recovery rate
rho = 0.05 # random fraction initially infected
t, S, I, R = EoN.fast_SIR(ER, tau, gamma, rho=rho, tmax = 20)
plt.plot(t, S, color = 'r', label='S')
plt.plot(t, I, color = 'b', label='I')
plt.plot(t, R, color = 'g', label='R')
plt.legend(loc=0)
plt.xlabel("$T$")
plt.ylabel("individuals")
BA网络上的仿真
N=10**4
BA=nx.barabasi_albert_graph(N, 4)
SIS仿真
tmax = 10
tau = 0.5 # transmission rate
gamma = 0.05 # recovery rate per node
t, S, I = EoN.fast_SIS(BA, tau=tau, gamma=gamma, tmax = tmax)
plt.plot(t, S, color = 'r', label='S')
plt.plot(t, I, color = 'b', label='I')
plt.legend(loc=0)
plt.xlabel("$T$")
plt.ylabel("individuals")
SIR仿真
tmax = 10
tau = 0.5 # transmission rate
gamma = 1.0 # recovery rate
rho = 0.05 # random fraction initially infected
t, S, I, R = EoN.fast_SIR(BA, tau, gamma, rho=rho, tmax = tmax)
plt.plot(t, S, color = 'r', label='S')
plt.plot(t, I, color = 'b', label='I')
plt.plot(t, R, color = 'g', label='R')
plt.legend(loc=0)
plt.xlabel("$T$")
plt.ylabel("individuals")