-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_density.py
54 lines (48 loc) · 1.6 KB
/
plot_density.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
import pickle
import tqdm
import collections
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
with open("best_sets.pkl", "rb") as fin:
best_sets = pickle.load(fin)
vmax = 0
for iter_budget, option_sets in tqdm.tqdm(best_sets.items()):
X, Y = np.meshgrid(range(7), range(7))
Z = np.zeros((7, 7))
total = 0
# for idx in range(49):
for option_set in option_sets:
goal_idxs, score = option_set
for goal_idx in goal_idxs:
if goal_idx is not None:
x = goal_idx % 7
y = goal_idx // 7
Z[x][y] += 1
total += 1
vmax = max(vmax, (Z / total).max())
for iter_budget, option_sets in tqdm.tqdm(best_sets.items()):
X, Y = np.meshgrid(range(7), range(7))
Z = np.zeros((7, 7))
total = 0
# for idx in range(49):
for option_set in option_sets:
goal_idxs, score = option_set
for goal_idx in goal_idxs:
if goal_idx is not None:
x = goal_idx % 7
y = goal_idx // 7
Z[x][y] += 1
total += 1
Z = np.rot90(Z / total)
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(Z, interpolation='nearest', vmax=vmax, vmin=0, cmap='jet')
fig.colorbar(cax)
ax.set_title('Goal distribution for budget: {} iterations'.format(iter_budget))
# Add colorbar, make sure to specify tick locations to match desired ticklabels
# cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
plt.savefig("plots/best_sets{}.png".format(iter_budget))
fig.clear()
# plt.show()