-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_alpha.py
60 lines (44 loc) · 1.5 KB
/
plot_alpha.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
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import gridspec as grd
import h5py
import sys
n_avg = 32
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage: %s <file.h5>" % (sys.argv[0],)
sys.exit(-1)
idx = -1
h5f = h5py.File(sys.argv[1], 'r')
test_loss = h5f['test_loss'][:]
for i in range(len(h5f['test_alpha'])-1, -1, -1):
idx = i
alpha = h5f['test_alpha'][idx]
alpha_shp = h5f['test_alpha_shp'][idx]
alpha.shape = alpha_shp
x = h5f['test_x'][idx]
x.shape = h5f['test_x_shp'][idx]
y = h5f['test_y'][idx]
'''
loss = np.convolve(
train_loss, np.ones((n_avg,))/n_avg, mode='valid')
plt.plot(loss)
plt.show()
'''
f, (a0, a1) = plt.subplots(2)
gs = grd.GridSpec(2,1, wspace=0.01) #, height_ratios=[1, 4])
a0 = plt.subplot(gs[0])
a0.matshow(x.T, cmap=plt.cm.Greys_r) #, aspect='auto')
probs = np.zeros_like(alpha)
for i in range(len(alpha)):
probs[i] = np.convolve(
alpha[i], np.ones((2,))/2., mode='same')
a1.matshow(alpha, interpolation='none', aspect='auto')
xticks = np.argmax(probs, axis=1)
a1.set_xticks(xticks)
a1.set_xticklabels(y, fontsize=16)
a1.grid(which='both')
#plt.tight_layout()
plt.subplots_adjust(top=None, bottom=None, wspace=0.05, hspace=0.05)
plt.show()
h5f.close()