-
Notifications
You must be signed in to change notification settings - Fork 11
/
util.py
executable file
·46 lines (39 loc) · 1.06 KB
/
util.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
"""
contourf.
"""
import matplotlib.pyplot as plt
import numpy as np
from keras.callbacks import Callback # Add by Steven Robot
from keras import backend as K
class LossHistory(Callback):
def on_train_begin(self, logs={}):
self.losses = []
self.acces = []
def on_batch_end(self, batch, logs={}):
self.losses.append(logs.get('loss'))
self.acces.append(logs.get('acc'))
def show(w, w_title):
"""
Show a weight matrix.
:param w: the weight matrix.
:param w_title: the title of the weight matrix
:return: None.
"""
# show w_z matrix of update gate.
axes_w = plt.gca()
plt.imshow(w)
plt.colorbar()
# plt.colorbar(orientation="horizontal")
plt.xlabel("$w_{1}$")
plt.ylabel("$w_{2}$")
axes_w.set_xticks([])
axes_w.set_yticks([])
matrix_size = "$:\ %d \\times\ %d$" % (len(w[0]), len(w))
w_title += matrix_size
plt.title(w_title)
# show the matrix.
plt.show()
if __name__ == "__main__":
w = np.random.random((8, 10))
title = " "
show(w, title)