-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdisplay.py
164 lines (142 loc) · 5.09 KB
/
display.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
import argparse
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
parser = argparse.ArgumentParser(description='Display an opt_tools hist.')
parser.add_argument('hist_file', type=str, nargs='+', help="Paths to the history files to be displayed.")
parser.add_argument('--smooth', help="Smoothing for objective function.", type=int, default=3)
parser.add_argument('--logscale', help="Log scale graphs.", action="store_true")
parser.add_argument('--xaxis', help="time|iter", type=str, default="time")
args = parser.parse_args()
hs = [pd.read_pickle(hf) for hf in args.hist_file]
plt.figure()
for h, f in zip(hs, args.hist_file):
fn = os.path.splitext(os.path.split(f)[-1])[0]
plt.subplot(311)
idx = h.t / 3600 if args.xaxis == "time" else h.i
# plt.plot(idx, np.convolve(h.f, np.ones(args.smooth) / args.smooth, 'same'), label=fn, alpha=0.5)
smooth = np.ones(args.smooth) / args.smooth
plt.plot(np.convolve(idx, smooth, 'valid'), np.convolve(h.f, smooth, 'valid'), label=fn, alpha=0.5)
# plt.plot(idx, h.f, label=fn)
plt.subplot(312)
plt.plot(idx, h.learning_rate)
plt.ylabel("Learning rate")
plt.yscale('log')
plt.subplot(313)
plt.plot(idx, h.minibatch_size)
plt.ylabel("Minibatch size")
plt.yscale('log')
plt.subplot(311)
plt.ylabel("LML bound")
plt.legend()
plt.subplot(313)
plt.xlabel("Time (hrs)")
if args.logscale:
plt.xscale('log')
plt.figure()
for h in hs:
if 'lml' in h.columns:
f = h[~(h.lml == 0.0) & ~np.isnan(h.lml)]
plt.plot(f.t / 3600, f.lml, '-')
else:
plt.plot([])
plt.xlabel("Time (hrs)")
plt.ylabel("LML bound")
plt.figure()
for i, h in enumerate(hs):
try:
# f = h[~h.err.isnull()].filter(regex="model.kern.convrbf.basek*")
ss = h[~h.err.isnull()]
f = ss.filter(regex=".*(lengthscales)")
if f.shape[1] > 0:
plt.plot(f, color="C%i" % i)
f = ss.filter(regex=".*(variance)")
plt.plot(f, color="C%i" % i, alpha=0.5)
# f = h.filter(regex="model.kern.convrbf.basek*")
# plt.plot(h.t, f[~f.acc.isnull()])
except:
pass
plt.xlabel("Time (hrs)")
plt.ylabel("Some hyperparameters")
# plt.figure()
# for i, h in enumerate(hs):
# p = h[~h.acc.isnull()]
# plt.plot(p.t / 3600, p.filter(regex="variance*"), color="C%i" % i)
plt.figure()
for h in hs:
p = h[~h.acc.isnull()]
plt.plot(p.t / 3600, p.err)
# plt.ylim(0.01, 0.03)
plt.xlabel("Time (hrs)")
plt.ylabel("Error")
if args.logscale:
plt.xscale('log')
plt.figure()
for h in hs:
p = h[~h.acc.isnull()]
plt.plot(p.t / 3600, p.nlpp)
# plt.ylim(0.03, 0.08)
plt.xlabel("Time (hrs)")
plt.ylabel("nlpp")
if args.logscale:
plt.xscale('log')
plt.figure()
for h in hs:
plt.plot(h.t / h.tt)
plt.xlabel("Record")
plt.ylabel("Proportion of time optimising")
def reshape_patches_for_plot(patches):
n_patch, dimx, dimy = patches.shape
n_rows = int(np.floor(np.sqrt(n_patch)))
n_cols = int(np.ceil(n_patch / n_rows))
image = np.empty((n_rows * dimx + n_rows - 1, n_cols * dimy + n_cols - 1))
image.fill(np.nan)
for count, p in enumerate(patches):
i = count // n_cols
j = count % n_cols
image[i * (dimx + 1):i * (dimx + 1) + dimx, j * (dimy + 1):j * (dimy + 1) + dimy] = p
return image, n_rows, n_cols
patches_fig = plt.figure()
qm_fig = plt.figure()
w_fig = plt.figure()
for i, h in enumerate(hs):
if not np.any(["conv" in cn or "basekern" in cn for cn in h.columns]):
continue
nsbplt = int(np.ceil(len(hs) ** 0.5))
plt.figure(patches_fig.number)
plt.subplot(nsbplt, nsbplt, i + 1)
Zend = h[~h.acc.isnull()].iloc[-1]['model.Z' if 'model.Z' in h.columns else 'model.Z1']
patch_size = int(Zend.shape[-1] ** 0.5)
qmu = h[~h.acc.isnull()]['model.q_mu'].iloc[-1]
if qmu.shape[1] == 1:
qm = np.vstack(h[~h.acc.isnull()]['model.q_mu'].iloc[-1]).flatten()
s = np.argsort(qm)
else:
s = np.arange(len(Zend))
try:
patch_image, n_rows, n_cols = reshape_patches_for_plot(1 - Zend.reshape(-1, patch_size, patch_size)[s, :, :])
plt.imshow(patch_image, cmap="gray")
plt.clim(-0.25, 1.25)
plt.colorbar()
except:
pass
if qmu.shape[1] == 1:
plt.figure(qm_fig.number)
plt.subplot(nsbplt, nsbplt, i + 1)
plt.imshow(np.hstack((qm[s], np.zeros(n_rows * n_cols - len(qm)))).reshape(n_rows, n_cols))
plt.colorbar()
plt.figure(w_fig.number)
plt.subplot(nsbplt, nsbplt, i + 1)
Wseries = h[~h.acc.isnull()].iloc[-1].filter(regex=".*.W")
if len(Wseries) >= 1 or len(Wseries) == 2352:
patch_weights = Wseries[0].flatten()
patch_h = int(np.ceil(patch_weights.shape[-1] ** 0.5))
if patch_h ** 2.0 != patch_weights.shape[-1]:
patch_h = int(np.ceil((patch_weights.shape[-1] / 3) ** 0.5))
patch_w = int(patch_weights.shape[-1] / patch_h)
plt.imshow(patch_weights.reshape(3, patch_h, patch_h).transpose(1, 0, 2).reshape(patch_h, patch_w))
else:
plt.imshow(patch_weights.reshape(patch_h, patch_h))
plt.colorbar()
plt.show()