-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample3D.py
More file actions
66 lines (52 loc) · 1.73 KB
/
example3D.py
File metadata and controls
66 lines (52 loc) · 1.73 KB
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
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from epidemic import SI, SIR, SIS
from network import bi_planted_partition
def main():
n_networks = 100
ps = np.linspace(0, 1, 25, endpoint=False)
rs = np.linspace(0, 1, 25, endpoint=False)
results_p = []; results_r = []; results_s = []; results_l = []
for r in rs:
for p in ps:
print (r, p)
samples_l = []
samples_s = []
for i in range(n_networks):
#print('-- NEW EPI --')
g = bi_planted_partition(1000, 8, 0)
epi = SIS(g, p=p, r=r)
#epi = SI(g, p=p)
epi.infect_random_node()
epi.simulate()
samples_l.append(epi.length)
samples_s.append(epi.size)
results_r.append(r)
results_p.append(p)
results_s.append(np.average(samples_s))
results_l.append(np.average(samples_l))
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = results_r, results_p
Z = results_l
ax.scatter(X, Y, Z)
ax.set_xlabel('Recovery Probability')
ax.set_ylabel('Transmission Probability')
ax.set_zlabel('Epidemic Length')
plt.show()
# TODO: Figure out the right way to save these plots
plt.clf()
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = results_r, results_p
Z = results_s
ax.scatter(X, Y, Z)
ax.set_xlabel('Recovery Probability')
ax.set_ylabel('Transmission Probability')
ax.set_zlabel('Epidemic Size')
plt.show()
# TODO: Figure out the right way to save these plots
plt.clf()
if __name__ == "__main__":
main()