-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_plot.py
491 lines (356 loc) · 17.5 KB
/
experiment_plot.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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
import matplotlib.pyplot as plt
import matplotlib.figure as fig
from collections import defaultdict
from math import log2
def savefig(filename):
plt.savefig("plot/" + filename + ".svg", dpi=600, format="svg")
plt.clf()
def plot_insertion_size():
with open("data/bst_unbalanced_space_inserts.csv") as f:
data = [tuple(map(int, line.strip().split(","))) for line in f.readlines()[1:]]
eph_size_sum = defaultdict(lambda: [])
per_size_sum = defaultdict(lambda: [])
for _, n, eph, per in data:
eph_size_sum[n].append(eph)
per_size_sum[n].append(per)
def points(size_sum):
return sorted((n, v / n) for n, values in size_sum.items() for v in values)
def avg_points(size_sum):
return sorted((n, sum(values) / len(values) / n) for n, values in size_sum.items())
plt.plot(*zip(*points(eph_size_sum)), ".", label="Ephemeral size for fixed seed", color="Black")
plt.plot(*zip(*avg_points(eph_size_sum)), "o:", label="Average Ephemeral size", color="Blue")
plt.plot(*zip(*avg_points(per_size_sum)), "o:", label="Persistent size", color="Orange")
# plt.title("Space Experiment\nUnbalanced BST with only Insertion Updates")
plt.xlabel("Number of Updates")
plt.ylabel("Space usage (bytes) / Updates")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("space_compare_inserts")
def plot_insertion_deletion_size():
with open("data/bst_unbalanced_space_insert_and_delete.csv") as f:
data = [tuple(map(int, line.strip().split(","))) for line in f.readlines()[1:]]
data = [(seed, 2 * n, eph, per) for seed, n, eph, per in data]
eph_size_sum = defaultdict(lambda: [])
per_size_sum = defaultdict(lambda: [])
for _, n, eph, per in data:
eph_size_sum[n].append(eph)
per_size_sum[n].append(per)
def points(size_sum):
return sorted((n, v / n) for n, values in size_sum.items() for v in values)
def avg_points(size_sum):
return sorted((n, sum(values) / len(values) / n) for n, values in size_sum.items())
plt.plot(*zip(*points(eph_size_sum)), ".", label="Ephemeral size for fixed seed", color="Black")
plt.plot(*zip(*avg_points(eph_size_sum)), "o:", label="Average Ephemeral size", color="Blue")
plt.plot(*zip(*points(per_size_sum)), ".", label="Persistent size for fixed seed", color="Grey")
plt.plot(*zip(*avg_points(per_size_sum)), "o:", label="Average Persistent size", color="Orange")
# plt.title("Space Experiment\nUnbalanced BST with Insertion and Deletion Updates")
plt.xlabel("Number of Updates")
plt.ylabel("Space usage (bytes) / Updates")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("space_compare_inserts_and_delete")
def plot_insertion_deletion_worst_case_size_with_node_splits():
with open("data/bst_unbalanced_space_insert_and_delete_worst_case_splits_only_persistent.csv") as f:
data = [tuple(map(int, line.strip().split(","))) for line in f.readlines()[1:]]
data = [(3 * n, size, splits) for n, size, splits in data]
size_pr_size = [(n, size / n) for n, size, _ in data]
splits_pr_size = [(n, splits / n) for n, _, splits in data]
# plt.suptitle("Space Experiment\nUnbalanced BST with Worst case Insertion and Deletion Updates")
plt.subplot(2, 1, 1)
plt.plot(*zip(*size_pr_size), "o:")
plt.title("Space")
plt.xlabel("Number of Updates")
plt.ylabel("Space usage (bytes) / Updates")
plt.xscale("log")
plt.subplot(2, 1, 2)
plt.plot(*zip(*splits_pr_size), "o:")
plt.title("Splits")
plt.xlabel("Number of Updates")
plt.ylabel("Splits / Updates")
plt.xscale("log")
plt.subplots_adjust(hspace=0.6)
# plt.show()
savefig("space_worst_case")
def plot_insertion_deletion_worst_case_range_size_with_node_splits():
with open("data/bst_unbalanced_space_insert_and_delete_worst_case_splits_range_only_persistent.csv") as f:
data = [tuple(map(int, line.strip().split(","))) for line in f.readlines()[3:]]
data = [(3 * n, size, splits) for n, size, splits in data]
size_pr_size = [(n, size / n) for n, size, _ in data]
splits_pr_size = [(n, splits / n) for n, _, splits in data]
# plt.suptitle("Space Experiment\nUnbalanced BST with Worst case Insertion and Deletion Updates")
plt.subplot(2, 1, 1)
plt.plot(*zip(*size_pr_size), ".")
plt.title("Space")
plt.xlabel("Number of Updates")
plt.ylabel("Space usage (bytes) / Updates")
# plt.xscale("log")
plt.subplot(2, 1, 2)
plt.plot(*zip(*splits_pr_size), ".")
plt.title("Splits")
plt.xlabel("Number of Updates")
plt.ylabel("Splits / Updates")
# plt.xscale("log")
plt.subplots_adjust(hspace=0.6)
# plt.show()
savefig("space_worst_case_range")
def plot_insertion_deletion_worst_case_range_size_node_splits():
with open("data/bst_unbalanced_space_insert_and_delete_worst_case_splits_range_only_persistent.csv") as f:
data = [tuple(map(int, line.strip().split(","))) for line in f.readlines()[3:]]
# data = [(3 * n, size, splits) for n, size, splits in data]
split_diff = [(n, s2 - s1) for (_, _, s1), (n, _, s2) in zip(data, data[1:])]
plt.plot(*zip(*split_diff), ".")
# plt.title("Space Experiment\nUnbalanced BST with Worst case Insertion and Deletion Updates")
plt.xlabel("Number of Updates")
plt.ylabel("Difference in Splits from Previous Size")
# plt.show()
savefig("space_worst_case_range_diff")
def plot_update_runtime(path, title, savepath):
with open(path) as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(seed), int(n), float(eph), float(per)) for seed, n, eph, per in data]
batch_times = defaultdict(lambda: [])
for seed, n, eph, per in data:
batch_times[(seed, n)].append((eph, per))
avg_batch_times = [
(seed, n, *[sum(times) / len(times) for times in zip(*values)])
for (seed, n), values in batch_times.items()
]
batch_increase = defaultdict(lambda: [])
for _, n, eph_avg, per_avg in avg_batch_times:
batch_increase[n].append(per_avg / eph_avg)
# batch_increase[n].append((per_avg - eph_avg) / eph_avg)
sorted_batch_increase = sorted(batch_increase.items())
increase = [(n, t) for n, times in sorted_batch_increase for t in times]
avg_increase = [(n, sum(times) / len(times)) for n, times in sorted_batch_increase]
plt.plot(*zip(*increase), ".", color="black", label="Ratio from Average Time over fixed seed")
plt.plot(*zip(*avg_increase), "o:", color="red", label="Ratio from Average Ratio of seeds")
# plt.title(title)
plt.xlabel("Number of Updates")
plt.ylabel("Persistent Runtime / Ephemeral Runtime")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig(savepath)
def plot_RB_update_insertion_time():
with open("data/bst_RB_update_insert_range.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(n), float(eph), float(per)) for n, eph, per in data]
batch_times = defaultdict(lambda: [])
for n, eph, per in data:
batch_times[n].append((eph, per))
avg_batch_times = [
(n, *[sum(times) / len(times) for times in zip(*values)])
for n, values in batch_times.items()
]
# all_batch_increase = [
# (n, p / t)
# for n, values in batch_times.items()
# for (eph_times, per_times) in [zip(*values)]
# for t in eph_times
# for p in per_times
# ]
# all_batch_increase = []
# for n, values in batch_times.items():
# eph, per = zip(*values)
# for t, p in zip(sorted(eph), sorted(per)):
# all_batch_increase.append((n, p / t))
batch_increase = sorted([(n, per_avg / eph_avg) for n, eph_avg, per_avg in avg_batch_times])
# plt.plot(*zip(*all_batch_increase), ".", color="black", label="Ratio from all times")
plt.plot(*zip(*batch_increase), "o:", color="red", label="Ratio from Average Ratio of times")
# plt.title("Update Time Increase Experiment\nRed-Black BST with Increasing Insertion Updates")
plt.xlabel("Number of Updates")
plt.ylabel("Persistent Runtime / Ephemeral Runtime")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("update_RB_insert")
def plot_build_runtime():
with open("data/bst_unbalanced_dag_build_time_insert_and_delete.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(seed), 2 * int(n), float(time)) for seed, n, time in data]
data = [(seed, n, time / n) for seed, n, time in data]
batch_times = defaultdict(lambda: [])
for seed, n, time in data:
batch_times[(seed, n)].append(time)
avg_batch_times = [
(seed, n, sum(times) / len(times))
for (seed, n), times in batch_times.items()
]
avg_times = defaultdict(lambda: [])
for _, n, time_avg in avg_batch_times:
avg_times[n].append(time_avg)
sorted_avg_times = sorted(avg_times.items())
times = [(n, t) for n, times in sorted_avg_times for t in times]
avg = [(n, sum(times) / len(times)) for n, times in sorted_avg_times]
plt.plot(*zip(*times), ".", color="black", label="Average Time for fixed seed")
plt.plot(*zip(*avg), "o:", color="red", label="Average Time over seeds")
# plt.title("DAG Build Time Experiment\nUnbalanced BST with random Insertion and Deletion Updates")
plt.xlabel("Number of Updates")
plt.ylabel("Runtime / Updates")
plt.xscale("log")
# plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("build_insert_delete")
def plot_worst_case_build_runtime():
with open("data/bst_unbalanced_dag_build_time_worst_case_insert_delete_leaf.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(3 * int(n), float(time), int(splits)) for n, time, splits in data]
data = [(n, time / n, splits) for n, time, splits in data]
batch_times = defaultdict(lambda: [])
for n, time, _ in data:
batch_times[n].append(time)
sorted_batch_times = sorted(batch_times.items())
times = [(n, t) for n, times in sorted_batch_times for t in times]
avg = [(n, sum(times) / len(times)) for n, times in sorted_batch_times]
plt.plot(*zip(*times), ".", color="black", label="Times")
plt.plot(*zip(*avg), "o:", color="red", label="Average Time")
# plt.title("DAG Build Time Experiment\nUnbalanced BST path with repeated Insertion and Deletion of leaf")
plt.xlabel("Number of Updates")
plt.ylabel("Runtime / Updates")
plt.xscale("log")
# plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("build_worst_case")
def plot_query_insertion_only_sum():
with open("data/bst_unbalanced_query_sum_of_all_elements_random_insert_only.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(seed), int(version), float(eph), float(per)) for seed, version, eph, per in data]
batch_times = defaultdict(lambda: [])
for seed, version, eph, per in data:
batch_times[(seed, version)].append((eph, per))
avg_batch_times = [
(seed, version, *[sum(times) / len(times) for times in zip(*values)])
for (seed, version), values in batch_times.items()
]
batch_increase = defaultdict(lambda: [])
for _, n, eph_avg, per_avg in avg_batch_times:
batch_increase[n].append(per_avg / eph_avg)
sorted_batch_increase = sorted(batch_increase.items())
increase = [(v, t) for v, times in sorted_batch_increase for t in times]
avg_increase = [(v, sum(times) / len(times)) for v, times in sorted_batch_increase]
plt.plot(*zip(*increase), ".", color="black", label="Ratio from Average Time over fixed seed")
plt.plot(*zip(*avg_increase), "o:", color="red", label="Ratio from Average Ratio of seeds")
# plt.title("Query Time Experiment\nUnbalanced BST with 200000 random Insertions\nQuery sum of elements")
plt.xlabel("Version Queried")
plt.ylabel("Persistent Runtime / Ephemeral Runtime")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("query_insert_sum")
def plot_query_worst_case_insert_delete_contains_leaf():
# with open("data/bst_unbalanced_query_wort_case_insert_delete_contains_leaf.csv") as f:
with open("data/bst_unbalanced_query_wort_case_insert_delete_contains_leaf_LARGER.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(time), float(eph), float(per)) for time, eph, per in data]
eph_times = defaultdict(lambda: [])
per_times = defaultdict(lambda: [])
for time, eph, per in data:
eph_times[time].append(eph)
per_times[time].append(per)
def points(times):
return sorted((n, v) for n, values in times.items() for v in values)
def avg_points(times):
return sorted((n, sum(values) / len(values)) for n, values in times.items())
plt.plot(*zip(*points(eph_times)), ".", label="Ephemeral time", color="Black")
plt.plot(*zip(*avg_points(eph_times)), "o:", label="Average Ephemeral time", color="Blue")
plt.plot(*zip(*points(per_times)), ".", label="Persistent time", color="Grey")
plt.plot(*zip(*avg_points(per_times)), "o:", label="Average Persistent time", color="Orange")
# plt.title("Query Time Experiment\nUnbalanced BST path with repeated Insertion and Deletion of leaf\nQuery containing of leaf")
plt.xlabel("Version Queried")
plt.ylabel("Runtime (s)")
plt.xscale("log")
# plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("query_contains_leaf")
def plot_query_relative_worst_case_insert_delete_contains_leaf():
with open("data/bst_unbalanced_query_wort_case_insert_delete_contains_leaf.csv") as f:
data_small = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data_small = [(int(time), float(eph), float(per)) for time, eph, per in data_small]
with open("data/bst_unbalanced_query_wort_case_insert_delete_contains_leaf_LARGER.csv") as f:
data_large = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data_large = [(int(time), float(eph), float(per)) for time, eph, per in data_large]
def process(data):
batch_times = defaultdict(lambda: [])
for time, eph, per in data:
batch_times[time].append((eph, per))
avg_batch_times = [
(time, *[sum(times) / len(times) for times in zip(*values)])
for time, values in batch_times.items()
]
return [(time, per / eph) for time, eph, per in avg_batch_times]
plt.plot(*zip(*process(data_small)), "o:", label="Path length 1000")
plt.plot(*zip(*process(data_large)), "o:", label="Path length 3000")
# plt.title("Query Time Experiment\nUnbalanced BST path with repeated Insertion and Deletion of leaf\nQuery containing of leaf")
plt.xlabel("Version Queried")
plt.ylabel("Persistent Runtime / Ephemeral Runtime")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("query_contains_leaf_relative")
def plot_sanity_test_runtime():
with open("data/sanity_time_test_bst_query_all.csv") as f:
data = [tuple(line.strip().split(",")) for line in f.readlines()[1:]]
data = [(int(seed), int(n), float(time)) for seed, n, time in data]
data = [(seed, n, time / (n * log2(n) ** 4)) for seed, n, time in data]
batch_times = defaultdict(lambda: [])
for seed, n, time in data:
batch_times[(seed, n)].append(time)
avg_batch_times = [
(seed, n, sum(times) / len(times))
for (seed, n), times in batch_times.items()
]
avg_times = defaultdict(lambda: [])
for _, n, time_avg in avg_batch_times:
avg_times[n].append(time_avg)
sorted_avg_times = sorted(avg_times.items())
times = [(n, t) for n, times in sorted_avg_times for t in times]
avg = [(n, sum(times) / len(times)) for n, times in sorted_avg_times]
plt.plot(*zip(*times), ".", color="black", label="Average Time for fixed seed")
plt.plot(*zip(*avg), "o:", color="red", label="Average Time over seeds")
# plt.title("Sanity Time Experiment\nPerfect BST Query all nodes in random order")
plt.xlabel("Number of Queries (q)")
plt.ylabel("Runtime / (q lg$^4$ q)")
plt.xscale("log")
plt.ylim(ymin=0)
plt.legend()
# plt.show()
savefig("time_sanity")
if __name__ == "__main__":
### SIZE
plot_insertion_size()
plot_insertion_deletion_size()
plot_insertion_deletion_worst_case_size_with_node_splits()
plot_insertion_deletion_worst_case_range_size_with_node_splits()
plot_insertion_deletion_worst_case_range_size_node_splits()
### UPDATE
plot_update_runtime(
"data/bst_unbalanced_update_insert_total_time_FULL.csv",
"Update Time Increase Experiment\nUnbalanced BST with only random Insertion Updates",
"update_relative_inserts"
)
plot_update_runtime(
"data/bst_unbalanced_update_insert_and_delete_total_time.csv",
"Update Time Increase Experiment\nUnbalanced BST with Insertion and Deletion Updates",
"update_relative_insert_and_delete"
)
plot_RB_update_insertion_time()
### DAG BUILDING
plot_build_runtime()
plot_worst_case_build_runtime()
### QUERY
plot_query_insertion_only_sum()
plot_query_worst_case_insert_delete_contains_leaf()
plot_query_relative_worst_case_insert_delete_contains_leaf()
# SANITY TIME
plot_sanity_test_runtime()