forked from raidancampbell/sequelspeare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data.py
More file actions
68 lines (62 loc) · 2.92 KB
/
Copy pathplot_data.py
File metadata and controls
68 lines (62 loc) · 2.92 KB
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
import matplotlib.pyplot as plt
import numpy as np
import csv
import glob
import statistics
class Plotter:
def __init__(self, should_plot=True):
self.analyze(should_plot)
@staticmethod
def moving_average(a, n=3):
ret = np.cumsum(a, dtype=float)
ret[n:] = ret[n:] - ret[:-n]
return ret[n - 1:] / n
@staticmethod
def analyze(should_plot, visibly_plot=False):
filenames = glob.glob("training_metadata/training_*.csv")
total_time = 0.
with open('training_metadata/metadata_sum.csv', 'w') as summary_csv:
summary_writer = csv.writer(summary_csv)
for filenum, filename in enumerate(filenames):
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
errors = []
trial_time = 0
for i, row in enumerate(reader):
if not i:
continue # first row contains the header string
errors.append(float(row[0]))
total_time += float(row[1])
trial_time += float(row[1])
if not should_plot:
continue
if errors:
summary_writer.writerow([filename[27:-4], statistics.mean(errors[-2500:]), trial_time])
for i, substr_ in enumerate(filename[:-4].split('_')):
if not i:
continue
if 'x' in substr_:
width = substr_.split('x')[0]
depth = substr_.split('x')[1]
if 'l' in substr_:
learning_rate = substr_[:-1]
if 'd' in substr_:
decay_rate = substr_[:-1]
if 'e' in substr_:
epochs = substr_[:-1]
if visibly_plot:
plt.figure(filenum+1)
plt.plot(Plotter.moving_average(errors, n=2500))
title = width + ' by ' + depth + ' network. \n''\
learning rate: ' + learning_rate + ' decay rate: ' + decay_rate + ' epochs: ' + epochs
plt.title(title)
plt.savefig(filename[:-4] + '.png')
print('[' + str(filenum) + '/' + str(len(filenames)) + '] Finished analyzing file: ' + filename)
# if we're not viewing the interactive figures, clear the figure to free up memory
if not visibly_plot:
plt.clf()
if visibly_plot:
plt.show()
print('total training time: ' + str(total_time) + ' seconds')
if __name__ == '__main__':
Plotter()