-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathheatmap.py
executable file
·65 lines (49 loc) · 1.7 KB
/
heatmap.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools as it
import pickle
import numpy as np
from argparse import ArgumentParser
from util.misc import string_heatmap
np.set_printoptions(precision=2)
parser = ArgumentParser()
parser.add_argument(dest="input_filename")
parser.add_argument("--cli", default=False, action="store_true", dest="cli")
args = parser.parse_args()
stats = pickle.load(open(args.input_filename, "br"))
frameskips = stats["frameskips"]
actions = stats["actions"]
min_frameskip = frameskips.min()
max_frameskip = frameskips.max()
fs_values = list(range(min_frameskip, max_frameskip + 1))
a_values = list(range(max(actions) + 1))
buttons_num = max(int(np.ceil(np.log2(len(a_values)))), 3)
a_labels = [str(l) for l in it.product([0, 1], repeat=buttons_num)]
data = np.zeros((len(fs_values), len(a_labels)))
for f, a in zip(frameskips, actions):
data[f - min_frameskip, a] += 1
s = data.sum(0)
s[s == 0] = 1
action_normalized_data = data / s
data /= data.sum()
if args.cli:
print(string_heatmap(data.T, fs_values, a_labels))
print()
else:
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use("ggplot")
fig, axes = plt.subplots(1, 2)
fig.canvas.set_window_title(args.input_filename)
axes[0].set_title("")
axes[1].set_title("Action-wise normalized")
for i, d in enumerate([data, action_normalized_data]):
a = sns.heatmap(d.T,
ax=axes[i],
square=True
)
a.set_yticklabels(a_labels, rotation=0, fontsize=12)
a.set_xticklabels(fs_values, rotation=0, fontsize=12)
a.set_xlabel('frameskip', )
a.set_ylabel('action')
plt.show()