-
Notifications
You must be signed in to change notification settings - Fork 3
/
bs_draw.py
64 lines (50 loc) · 1.41 KB
/
bs_draw.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
'''
Рисует графики с зависимостью ускорения от b и/или h
'''
import json
import matplotlib.pyplot as plt
import numpy as np
import time
from numpy import loadtxt
from simple_grad_descend import SGD
V = 20
##############################################
dataset_name = './data/default_data.csv'
labels_name = './data/default_labels.csv'
X = loadtxt(dataset_name, delimiter=',')
y = loadtxt(labels_name, delimiter=',')
start_sgd, stop_sgd = 0, 0
start_sgd += time.time()
SGD(X, y)
stop_sgd += time.time()
k = stop_sgd - start_sgd
##############################################
logs = json.load(open('logs.json'))
t = logs['algorithm_time']
v = logs['version']
ta = sorted([t[i] / k for i in range(len(v)) if v[i] == V])
h1b1 = []
h1b2 = []
h2b1 = []
h2b2 = []
i = 0
while i < len(ta):
h1b1.append(ta[i])
i += 1
h1b2.append(ta[i])
i += 1
h2b1.append(ta[i])
i += 1
h2b2.append(ta[i])
i += 1
x = np.arange(1, 21, 2)
plt.figure(figsize=(12, 8))
plt.plot(x, h1b1, label='b = 4')
plt.plot(x, h1b2, label='b = 16')
plt.plot(x, h2b1, label='b = 32')
plt.plot(x, h2b2, label='b = 256')
plt.xlabel('Количество работников', fontsize=15)
plt.ylabel('Ускорение по сравнению с SGD', fontsize=15)
plt.title("Зависимость ускорения от mini-batch size", fontsize=15)
plt.legend()
plt.savefig('./img/test_bs_h')