-
Notifications
You must be signed in to change notification settings - Fork 0
/
SAIS_Single.py
99 lines (73 loc) · 2.43 KB
/
SAIS_Single.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from GEMFPy import *
from time import time
G=nx.random_geometric_graph(100,0.151)
pos=nx.get_node_attributes(G,'pos')
# find node near center (0.5,0.5)
dmin=1
ncenter=0
for n in pos:
x,y=pos[n]
d=(x-0.5)**2+(y-0.5)**2
if d<dmin:
ncenter=n
dmin=d
# color by path length from node near center
p=nx.single_source_shortest_path_length(G,ncenter)
plt.figure(figsize=(8,8))
nx.draw_networkx(G, pos, node_size =200)
# plt.savefig('random_geometric_graph.png')
plt.show()
# G = nx.erdos_renyi_graph(10,.3)
N = G.number_of_nodes()
beta = 2
delta = 1
beta_a = 0.4
kappa = 0.2
Para = Para_SAIS_Single(delta,beta, beta_a, kappa)
x0 = np.zeros(N)
x0 = Initial_Cond_Gen(N, Para[1][0], 2, x0)
Net = NetCmbn([MyNet(G)])
StopCond = ['RunTime', 10]
t, f = MonteCarlo(Net, Para, StopCond, 1, 3, .1, 20, N, x_init = np.zeros(N) )
fig2 = plt.figure(figsize=(10,5))
# for i in range(M):
# plt.plot(T, StateCount[0,:]/N,'r',label='Susceptible')
plt.plot(t,f[0,:],'r',label='Susceptible')
plt.plot(t,f[1,:],'b',label='Infected')
plt.plot(t,f[2,:],'g',label='Alerted')
# plt.plot(t,f[3,:],'g',label='Recovered')
# plt.savefig("SAIS.png")
plt.xlabel('Time (day)')
plt.ylabel('Fraction of Population')
plt.title('SAIS')
plt.legend(loc='upper center', shadow=True)
plt.show()
# plt.savefig("SAIS_MonteCarlo.png")
# *************
ts, n_index, i_index, j_index = GEMF_SIM(Para, Net, x0, StopCond,N)
M = Para[0]
T, StateCount = Post_Population(x0, M, N, ts, i_index, j_index)
fig = plt.figure(figsize=(10,5))
# for i in range(M):
# plt.plot(T, StateCount[0,:]/N,'r',label='Susceptible')
plt.plot(T, StateCount[0,:]/N,'r',label='Susceptible')
plt.plot(T, StateCount[1,:]/N,'k',label='Infected')
plt.plot(T, StateCount[2,:]/N,'y',label='Alerted')
plt.xlabel('Time (day)')
plt.ylabel('Fraction of Population')
plt.title('SAIS')
plt.legend(loc='upper center', shadow=True)
plt.show()
# plt.savefig("SAIS.png")
# *************
fig = plt.figure(figsize = (10, 10))
comp = ['S', 'I', 'A']
colors = ['olivedrab', 'tomato', 'blue']
col = dict(zip(comp, colors))
model = [x0, n_index, i_index, j_index]
anim = animate_discrete_property_over_graph(G, model, len(ts)-1, fig, n_index,i_index, j_index, comp, 'state',
col, pos = pos, Node_radius = .01)
plt.show()
##ALERT-----before saving: Just be careul when you save the movie, cause it takes too much time, i.e., each event is a frame.
# anim.save('myTest11111.mp4')
# *************