forked from jakobrj/GPU_PROCLUS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_real.py
95 lines (74 loc) · 2.59 KB
/
run_real.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
from python.GPU_PROCLUS import *
import os
import time
import numpy as np
import matplotlib.pyplot as plt
def run(method, X):
print(X.size())
k = 10
l = 5
a = min(100, X.shape[0] // k)
b = 10
min_deviation = 0.7
termination_rounds = 5
rounds = 20
total = 0.
for _ in range(rounds):
print("round:", _)
t0 = time.time()
method(X, k, l, a, b, min_deviation, termination_rounds)
t1 = time.time()
total += t1 - t0
avg = total / rounds
return avg
def runs(method):
r = [run(method, load_data()) for load_data in
(load_glass, load_vowel, load_pendigits, load_skyserver_1x1, load_skyserver_2x2, load_skyserver_5x5)]
print(r)
return r
if not os.path.exists('plots/'):
os.makedirs('plots/')
X = load_vowel()
k = 5
l = 5
a = 40
b = 10
min_deviation = 0.7
termination_rounds = 5
# do one run just to get the GPU started and get more correct measurements
GPU_PROCLUS(X, k, l, a, b, min_deviation, termination_rounds)
labels = ["glass", "vowel", "pendigits", "sky 1x1", "sky 2x2", "sky 5x5"]
ra = np.arange(len(labels))
fig, ax = plt.subplots(figsize=(8, 5))
width = 1. / 7.
PROCLUS_times = runs(PROCLUS)
rects1 = ax.bar(ra - 5 * width / 2, PROCLUS_times, width=width, label="PROCLUS")
FAST_star_PROCLUS_times = runs(FAST_star_PROCLUS)
rects2 = ax.bar(ra - 3 * width / 2, FAST_star_PROCLUS_times, width=width, label="FAST*-PROCLUS")
FAST_PROCLUS_times = runs(FAST_PROCLUS)
rects3 = ax.bar(ra - width / 2, FAST_PROCLUS_times, width=width, label="FAST-PROCLUS")
run(GPU_PROCLUS, load_glass())
GPU_PROCLUS_times = runs(GPU_PROCLUS)
rects4 = ax.bar(ra + width / 2, GPU_PROCLUS_times, width=width, label="GPU-PROCLUS")
GPU_FAST_star_PROCLUS_times = runs(GPU_FAST_star_PROCLUS)
rects5 = ax.bar(ra + 3 * width / 2, GPU_FAST_star_PROCLUS_times, width=width, label="GPU-FAST*-PROCLUS")
GPU_FAST_PROCLUS_times = runs(GPU_FAST_PROCLUS)
rects6 = ax.bar(ra + 5 * width / 2, GPU_FAST_PROCLUS_times, width=width, label="GPU-FAST-PROCLUS")
ax.set_xticks(ra)
ax.set_xticklabels(labels)
def autolabel(rects):
"""Attach a text label above each bar in *rects*, displaying its height."""
for rect in rects:
height = round(rect.get_height(), 3)
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, rect.get_height()),
xytext=(0, 1),
textcoords="offset points",
ha='center', va='bottom')
plt.ylabel('time in seconds')
ax.legend()
plt.rc('font', size=11)
plt.yscale("log")
fig.tight_layout()
plt.savefig("plots/real.pdf")
plt.show()