-
Notifications
You must be signed in to change notification settings - Fork 0
/
convergence_experiment.py
66 lines (52 loc) · 1.74 KB
/
convergence_experiment.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
import numpy as np
import Zhang
import networkx as nx
import pandas
import matplotlib.pyplot as plt
import time
from core.constants import *
# Experiment showing long term behaviour of simulation
# and the percent vaccination levels reached.
# And trying to get a some sense for did it converge.
graph_properties = dict(size=1000,
average_degree=6,
random_mixing=0.15)
network = nx.generators.watts_strogatz_graph(graph_properties["size"], graph_properties["average_degree"], graph_properties["random_mixing"])
sim_properties = dict(network=network,
infect_rate=0.18,
recover_rate=0.25,
immunity_loss=0.0,
select_strength=10,
vaccine_cost=0.5,
policy=Policy.PARTIAL,
delta=0.3)
seasons = 3000
window = 200
windows = 2
# Do simulation and time it.
start = time.time()
sim = Zhang.ZhangSimulation(**sim_properties)
print(sim)
data = sim.run(seasons)
print(f"took {time.time()-start:.2f} seconds")
df = pandas.DataFrame(data)
df["total_vaccinated"] /= 1000
df["total_vaccinated"].plot()
def window_average(window, df):
s = sum(df["total_vaccinated"].iloc[:window])
values = [s]
for offset in range(seasons-window-1):
s = s + df["total_vaccinated"].iloc[window+offset] - df["total_vaccinated"].iloc[offset]
values.append(s)
final = np.array(values)
return final / window
temp = window_average(window, df)
plt.plot(temp)
plt.show()
# Calculate window differences
window_difference = []
for i in range(seasons-window-window):
delta = temp[i+window]-temp[i]
window_difference.append(delta)
plt.plot(window_difference)
plt.show()