-
Notifications
You must be signed in to change notification settings - Fork 1
/
sis_network.py
66 lines (50 loc) · 1.25 KB
/
sis_network.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
# Example for the group
import matplotlib.pyplot as plt
import sys
script_location = '/home/anderson/Documents/UW_AM_Research' + \
'/Code/GEMFPython'
sys.path.append(script_location)
from GEMFPy import *
# Will
# Genrate graph
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
# Mehrshad
# color by path length from node near center
p=nx.single_source_shortest_path_length(G,ncenter)
# Population
N = G.number_of_nodes()
# Rui
# Parameters and model
beta = 1.2; delta = 2;
Para = Para_SIS(delta,beta)
# initial conditions
x0 = np.zeros(N)
x0 = Initial_Cond_Gen(N, Para[1][0], 2, x0)
#sameed
# Sim variables
Net = NetCmbn([MyNet(G)])
StopCond = ['RunTime', 10]
# Simulation
t, f = MonteCarlo(Net, Para, StopCond, 1, 3, .1, 20, N, x_init = np.zeros(N))
# Dania
# plotting
fig = plt.figure()
ax0 =fig.add_subplot(211)
ax0 = nx.draw_networkx(G, pos, node_size =200)
ax1 = fig.add_subplot(212)
ax1.plot(t,f[0,:],'r',label='Susceptible')
ax1.plot(t,f[1,:],'b',label='Infected')
# Stephanie
ax1.set_xlabel('Time (day)')
ax1.set_ylabel('Fraction of Population')
plt.show(block=True)