-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRuntime_Processing.py
372 lines (328 loc) · 14 KB
/
Runtime_Processing.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# Santiago Nunez-Corrales and Eric Jakobsson
# Illinois Informatics and Molecular and Cell Biology
# University of Illinois at Urbana-Champaign
# {nunezco,jake}@illinois.edu
# A simple tunable model for COVID-19 response
import matplotlib.pyplot as plot
import scipy.stats as sps
import seaborn as sns
import pandas as pd
import numpy as np
from covidmodel import CovidModel
import matplotlib.patches as mpatches
import sys
import multiprocessing
import glob
import os
import time
import scipy.stats as stats
plot.rcParams['agg.path.chunksize'] = 10000
features = ["Data_Time","Step_Time"]
def linear_model(x, slope, intercept):
new_list = []
for element in x:
new_list.append(element*slope+intercept)
return new_list
input_directory_list = []
output_filenames_list = []
input_filenames_list = []
#
# for argument in sys.argv[1:]:
# input_directory_list.append(argument)
# agent_count_list = []
agent_count_list = [100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000]
agent_count_list_2 = [100,200,300,400,500,600,700,800,900,1000]
iteration_list = iteration_list = [1,2,3,4]
"""No Backtracking Files"""
No_backtracking_data_storage_file_1 = "outcomes/Debugging/Test_Runtime/Total_Running_Times_0_10_No_backtracking.csv"
No_backtracking_df_1 = pd.read_csv(No_backtracking_data_storage_file_1)
# data_storage_file_2 = "outcomes/Debugging/Test_Runtime/Total_Running_Times_10_21_No_backtracking.csv"
# backtracking_df_2 = pd.read_csv(data_storage_file_2)
# frames = [No_backtracking_df_1, backtracking_df_2]
frames = [No_backtracking_df_1]
no_backtracking_data_storage_df = pd.concat(frames, ignore_index = True)
""""Backtracking Files"""
backtracking_data_storage_file_1 = "outcomes/Debugging/Test_Runtime/Total_Running_Times_0_10_backtracking.csv"
backtracking_df_1 = pd.read_csv(backtracking_data_storage_file_1)
# data_storage_file_2 = "outcomes/Debugging/Test_Runtime/Data_Storage_Times.csv"
# backtracking_df_2 = pd.read_csv(data_storage_file_2)
nb_frames = [backtracking_df_1]
backtracking_data_storage_df = pd.concat(nb_frames)
All_No_Backtracking_Data_Storage_Times = []
All_Backtracking_Data_Storage_Times = []
for iteration in iteration_list:
No_Backtracking_Data_Storage_Times = []
Backtracking_Data_Storage_Times = []
for index in range(len(np.array(no_backtracking_data_storage_df))):
time = no_backtracking_data_storage_df["Iteration"+str(iteration)][index]
No_Backtracking_Data_Storage_Times.append(time)
for index in range(len(np.array(backtracking_data_storage_df))):
time = backtracking_data_storage_df["Iteration"+str(iteration)][index]
Backtracking_Data_Storage_Times.append(time)
All_No_Backtracking_Data_Storage_Times.append(No_Backtracking_Data_Storage_Times)
All_Backtracking_Data_Storage_Times.append(Backtracking_Data_Storage_Times)
for iteration in iteration_list:
#Initialize the plot
namesuf = str(iteration)
plot.figure(figsize=(200.7, 100.27))
plot.ticklabel_format(style='plain', axis='y')
fig, ax = plot.subplots()
ax.plot(agent_count_list_2, All_No_Backtracking_Data_Storage_Times[iteration-1], color="red", label=("No_Backtracking_Storage_Times"), linewidth=2)
ax.plot(agent_count_list_2, All_Backtracking_Data_Storage_Times[iteration-1], color="blue", label=("Backtracking_Storage_Times"), linewidth=2)
slope, intercept, r_value, p_value, std_err =stats.linregress(agent_count_list_2, All_No_Backtracking_Data_Storage_Times[iteration-1])
print("Slope and intercept for No Backtracking respectively is :", slope, ":::", intercept)
model_runtime = linear_model(agent_count_list_2,slope,intercept)
ax.plot(agent_count_list_2, model_runtime, label = "BestRuntimeFit for No Backtracking", color = "orange", linewidth=1)
slope, intercept, r_value, p_value, std_err = stats.linregress(agent_count_list_2, All_Backtracking_Data_Storage_Times[iteration - 1])
print("Slope and intercept for Backtracking respectively is :", slope, ":::", intercept)
model_runtime = linear_model(agent_count_list_2, slope, intercept)
ax.plot(agent_count_list_2, model_runtime, label="BestRuntimeFit for Backtracking", color = "purple", linewidth=1)
legends_list = []
legend1 = mpatches.Patch(color="red")
legends_list.append(legend1)
legend2 = mpatches.Patch(color="blue")
legends_list.append(legend2)
plot.axis('tight')
ax.set_xlabel("Agent_Count")
ax.set_ylabel("Time(s)")
names = ["Total_Running_Times_No_backtracking", "Total_Running_Times_backtracking"]
plot.legend(legends_list, names, bbox_to_anchor=(1.05, 0.8), loc="upper right", borderaxespad=0, fontsize='xx-small')
ax.set_title(f"Total Running Times for {iteration} iterations")
out_file = f"visualizations/Debugging/Test_Runtime/Total_Running_Times_{iteration}.png"
print(out_file)
plot.savefig(out_file, dpi=700)
plot.close()
# """Average_Calculation:"""
#
# backtracking_input_filenames_list = []
#
# for directory in input_directory_list:
# for count in agent_count_list:
# print(f"{directory}/backtracking{str(count)}.csv")
# file_list = glob.glob(f"{directory}/backtracking{str(count)}.csv")
# for file in file_list:
# backtracking_input_filenames_list.append(file)
#
# no_backtracking_input_filenames_list = []
# for directory in input_directory_list:
# for count in agent_count_list:
# print(f"{directory}/backtracking{str(count)}.csv")
# file_list = glob.glob(f"{directory}/No_backtracking{str(count)}.csv")
# for file in file_list:
# no_backtracking_input_filenames_list.append(file)
#
# total_backtracking = [[] for _ in range(3)]
# total_no_backtracking = [[] for _ in range(3)]
# average_backtracking = [[] for _ in range(3)]
# average_no_backtracking = [[] for _ in range(3)]
# print(total_backtracking[0], total_no_backtracking, average_backtracking, average_no_backtracking)
#
# print("Backtracking Files: ")
# for item in backtracking_input_filenames_list:
# print(item)
#
# print("Non backtracking Files: ")
# for item in no_backtracking_input_filenames_list:
# print(item)
#
# """0 -> Data_Time, 1 -> Step_Time, 2 -> Total_Time """
# for iteration in range(3):
# """Calculating Backtracking Totals"""
# backtracking_average_list = []
# backtracking_total_list = []
# for index, in_file in enumerate(backtracking_input_filenames_list):
# df = pd.read_csv(in_file)
# print(iteration, index+1, len(backtracking_input_filenames_list))
# total = 0
# for idx in df["Step"].unique():
# if (iteration == 0):#Data
# values = df[features[0]][df["Step"] == idx]
# avg = values.mean()
# total += avg
# elif (iteration == 1):#Step
# values = df[features[1]][df["Step"] == idx]
# avg = values.mean()
# total += avg
# elif (iteration == 2): #Total
# values = df[features[1]][df["Step"] == idx] + df[features[0]][df["Step"] == idx]
# avg = values.mean()
# total += avg
# total_backtracking[iteration].append(total)
# average = total/len(df[features[0]])
# average_backtracking[iteration].append(average)
#
#
#
# """Calculating Non-Backtracking Totals"""
# no_backtracking_total_list = []
# no_backtracking_average_list = []
# for index, in_file in enumerate(no_backtracking_input_filenames_list):
# df = pd.read_csv(in_file)
# print(iteration, index+1, len(no_backtracking_input_filenames_list))
# total = 0
# for idx in df["Step"].unique():
# if (iteration == 0): # Data
# values = df[features[0]][df["Step"] == idx]
# avg = values.mean()
# total += avg
# elif (iteration == 1): # Step
# values = df[features[1]][df["Step"] == idx]
# avg = values.mean()
# total += avg
# elif (iteration == 2): # Total
# values = df[features[1]][df["Step"] == idx] + df[features[0]][df["Step"] == idx]
# avg = values.mean()
# total += avg
#
# total_no_backtracking[iteration].append(total)
# average = total / len(df[features[0]])
# average_no_backtracking[iteration].append(average)
#
#
#
# for avg in range(2):
# for iteration in range(3):
# #Initialize the plot
# namepref = ""
# namesuf = ""
# plot.figure(figsize=(200.7, 100.27))
# plot.ticklabel_format(style='plain', axis='y')
# fig, ax = plot.subplots()
# if(iteration == 0):
# namepref = "Data_Time"
# if (iteration == 1):
# namepref = "Step_Time"
# if (iteration == 2):
# namepref = "Total_Time"
#
# if avg:
# namesuf = "Average"
# ax.plot(agent_count_list, average_backtracking[iteration], color="red", label=(namepref + " " + "Backtracking Average"), linewidth=1)
# ax.plot(agent_count_list, average_no_backtracking[iteration], color="blue", label=(namepref +" " + "No Backtracking Average"),
# linewidth=1)
# else:
# namesuf = "Total"
# ax.plot(agent_count_list, total_backtracking[iteration], color="red", label=(namepref +" " + "Backtracking Total"), linewidth=1)
# ax.plot(agent_count_list, total_no_backtracking[iteration], color="blue", label=(namepref +" " + "No Backtracking Total"),
# linewidth=1)
#
# legends_list = []
# legend1 = mpatches.Patch(color="red")
# legends_list.append(legend1)
# legend2 = mpatches.Patch(color="blue")
# legends_list.append(legend2)
# plot.axis('tight')
# names = [namepref+ " " + "Backtracking" + " " + namesuf, namepref+ " " + "No Backtracking" + " " + namesuf]
# plot.legend(legends_list, names, bbox_to_anchor=(1.05, 0.8), loc="upper right", borderaxespad=0,
# fontsize='xx-small')
# ax.set_title(namepref+ " "+ namesuf + "s")
# file = no_backtracking_input_filenames_list[0]
# out_file = file.replace("outcomes/", "visualizations/")
# out_file = file.replace("No_backtracking100", "")
# out_file = out_file.replace(".csv", namepref+ "_"+ namesuf + "s" + ".png")
# print(out_file)
# plot.savefig(out_file, dpi=700)
# plot.close()
#
# for directory in input_directory_list:
# file_list = glob.glob(f"{directory}/*.csv")
# for file in file_list:
# input_filenames_list.append(file)
#
# for file in input_filenames_list:
# out_file = file.replace("outcomes/", "visualizations/")
# out_file = out_file.replace(".csv", "-data_time.png")
# output_filenames_list.append(out_file)
#
# print(input_directory_list)
# print(input_filenames_list)
# print(output_filenames_list)
#
# np.seterr(all="ignore")
#features will be a list of features requested on the graph
#
# for index, in_file in enumerate(input_filenames_list):
# plot.figure(figsize = (200.7, 100.27))
# plot.ticklabel_format(style='plain', axis='y')
# df0 = pd.read_csv(in_file)
# df0["Step"] = df0["Step"]/96
#
# df_list = []
# xmin_list = []
# xmax_list = []
# ymin_list = []
# ymax = 1.0
# ymin = 0
# fig, ax = plot.subplots()
# average_lists = []
#
# df_stats_list = []
# legends_list = []
# labels_list = []
# index_list = [range(len(features))]
# for idx,feature in enumerate(features):
# #TODO create a list of dataframes
# df = pd.DataFrame()
# df["Step"] = df0["Step"]
# df[feature] = df0[feature]#*100
# xmin = 0
# xmax = df["Step"].max()
#
# avg = []
# low_ci_95 = []
# high_ci_95 = []
# low_ci_99 = []
# high_ci_99 = []
# print(f"Computing confidence intervals... {feature}")
# for step in df["Step"].unique():
# values = df[feature][df["Step"] == step]
# f_mean = values.mean()
# lci95, hci95 = sps.t.interval(0.95, len(values), loc=f_mean, scale=sps.sem(values))
# lci99, hci99 = sps.t.interval(0.99, len(values), loc=f_mean, scale=sps.sem(values))
# avg.append(f_mean)
# low_ci_95.append(lci95)
# high_ci_95.append(hci95)
# low_ci_99.append(lci99)
# high_ci_99.append(hci99)
#
# df_stats = pd.DataFrame()
# df_stats["Step"] = df["Step"].unique()
# df_stats["mean"] = avg
# df_stats["lci95"] = low_ci_95
# df_stats["hci95"] = high_ci_95
# df_stats["lci99"] = low_ci_99
# df_stats["hci99"] = high_ci_99
# cur_color = ((idx+1)/len(features)), 0.5*((idx+1)/len(features)), 1-((idx+1)/len(features))
# if (feature == "Vaccinated"):
# cur_color = "lime"
# elif (feature == "Generally_Infected"):
# cur_color = "red"
# elif (feature == "Susceptible"):
# cur_color = "blue"
# elif (feature == "Deceased"):
# cur_color = "black"
# elif (feature == "SymptQuarantined"):
# cur_color = "yellow"
# elif (feature == "Recovered"):
# cur_color = "skyblue"
# elif (feature == "Exposed"):
# cur_color = "purple"
# elif (feature == "Fully_Vaccinated"):
# cur_color = "olive"
#
#
# ax.plot(df_stats["Step"], df_stats["mean"], color=cur_color, label = feature, linewidth = 1)
# ax.fill_between(df_stats["Step"], df_stats["lci95"], df_stats["hci95"], color=cur_color, alpha=.1)
# ax.set_xlim([xmin, xmax])
# ax.set_ylim([ymin, ymax])
# ax.set_xlabel("Days")
# ax.set_ylabel("Pop. Fraction")
# legend = mpatches.Patch(color=cur_color)
# legends_list.append(legend)
#
#
# plot.axis('tight')
# plot.legend(legends_list, features, bbox_to_anchor=(1.05, 0.8), loc="upper right", borderaxespad=0, fontsize='xx-small')
# plot.savefig(output_filenames_list[index], dpi=700)
# plot.close()
#