-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.py
67 lines (52 loc) · 1.93 KB
/
runner.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
# coding=utf-8
from numpy import std
from matplotlib import pyplot as plt
from data_provider import DataProvider
from prediction import PredictionNetwork
__author__ = 'Michał Ciołczyk'
def avg(ys):
sum = 0
for y in ys:
sum += y
return sum / len(ys)
if __name__ == '__main__':
epochs = [50, 100, 200]
learning_rates = [0.01, 0.1, 0.2]
momentums = [0.5, 0.75, 0.99]
hidden_layer_size = 30
repeats = 10
normalize = True
denormalize = True
dp = DataProvider('data2.csv', 100, normalize)
test_data = dp.provide_test_data()
for e in epochs:
for lr in learning_rates:
for m in momentums:
print 'Epochs:', e, 'Learning rate:', lr, 'Momentum:', m
networks = []
for i in xrange(0, repeats):
pn = PredictionNetwork(dp, hidden_layer_size)
pn.learn(lr, m, e, False)
networks.append(pn.network)
days = range(1, len(test_data) + 1)
real_vals = []
stddevs = []
avgs = []
for (x, y) in test_data:
yc = y[0]
ys = map(lambda n: n.activate(x)[0], networks)
err = map(lambda yp: abs(yp - yc), ys)
if denormalize:
yc = dp.max * yc + dp.min
ys = map(lambda a: dp.max * a + dp.min, ys)
err = map(lambda a: dp.max * a, err)
stddev = std(err)
avgval = avg(ys)
real_vals.append(yc)
stddevs.append(stddev)
avgs.append(avgval)
plt.figure()
plt.plot(days, real_vals)
plt.errorbar(days, avgs, stddevs)
plt.savefig('error_plots/' + str(e) + '_' + str(lr) + '_' + str(m) + '.png')
plt.close()