-
Notifications
You must be signed in to change notification settings - Fork 26
/
plotgradients.py
51 lines (46 loc) · 1.88 KB
/
plotgradients.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
import sys, os, pprint, math
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from blocks.serialization import load
statistics = dict(batchmean=lambda x: x.mean(axis=1),
batchvar=lambda x: x.var(axis=1),
#minbatchvar=lambda x: x.var(axis=1).min(axis=1),
#maxbatchvar=lambda x: x.var(axis=1).max(axis=1),
norm=lambda x: np.sqrt((x**2).sum(axis=(1, 2))))
paths = dict(enumerate(sys.argv[1:]))
pprint.pprint(paths)
subplotrows = int(math.ceil(math.sqrt(len(paths))))
instances = dict((k, load(v)) for k, v in paths.items())
keys = list(next(iter(instances.values())).keys())
print keys
for key in keys:
for statlabel, statistic in statistics.items():
figure, axes = plt.subplots(subplotrows, subplotrows)
if subplotrows == 1:
# morons
axes = [[axes]]
label = 0
for i in range(subplotrows):
for j in range(subplotrows):
try:
instance = instances[label]
except:
continue
result = statistic(instance[key])
axis = axes[i][j]
if result.ndim == 1:
# logarithmic line plot
axis.plot(result)
axis.set_yscale("log")
elif result.ndim == 2:
# heatmap
mappable = axis.imshow(result.T, cmap="bone", interpolation="none", aspect="auto")
divider = make_axes_locatable(axis)
figure.colorbar(mappable, cax=divider.append_axes("right", size="5%", pad=0.05))
axis.set_title("#%i" % label)
title = "%s %s" % (key, statlabel)
figure.suptitle(title)
figure.canvas.set_window_title(title)
import pdb; pdb.set_trace()
plt.show()