<jupyter_start><jupyter_text>DSR<jupyter_code>with open('../experiments/successor-data/20191109-run4-20k.pkl', 'rb') as handle:
    DSR = pickle.load(handle)<jupyter_output><empty_output><jupyter_text>Visualize differences in successor features for consecutive coordinates<jupyter_code>xDSR = {}
yDSR = {}
with torch.no_grad():
    for pos, sf in DSR.items():
        x, y = pos
        if x in xDSR:
            xDSR[x][0] += sf
            xDSR[x][1] += 1
        else:
            xDSR[x] = [sf, 1]
        if y in yDSR:
            yDSR[y][0] += sf
            yDSR[y][1] += 1
        else:
            yDSR[y] = [sf, 1]
    for x, data in xDSR.items():
        xDSR[x] = data[0] / data[1]
    for y, data in yDSR.items():
        yDSR[y] = data[0] / data[1]
fig = plt.hist(xDSR[12] - xDSR[11], bins=50)
fig = plt.hist(xDSR[11] - xDSR[10], bins=50)
fig = plt.hist(yDSR[6] - xDSR[5], bins=50)
fig = plt.hist(yDSR[5] - xDSR[4], bins=50)<jupyter_output><empty_output><jupyter_text>Visualize varying x<jupyter_code>fig = plt.figure(figsize=(17, 17))
ax = fig.add_subplot(111, projection='3d')
# for z in sorted(xDSR.keys()):
for z in range(10, 15):
    ys = xDSR[z]

    hist, bins = np.histogram(ys)
    xs = (bins[:-1] + bins[1:])/2

    ax.bar(xs, hist, zs=z, zdir='y', alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()<jupyter_output><empty_output><jupyter_text>Visualize varying y<jupyter_code>fig = plt.figure(figsize=(17, 17))
ax = fig.add_subplot(111, projection='3d')
nbins = 50
# for z in sorted(yDSR.keys()):
for z in range(4, 9):
    ys = yDSR[z]

    hist, bins = np.histogram(ys)
    xs = (bins[:-1] + bins[1:])/2

    ax.bar(xs, hist, zs=z, zdir='y', alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()
env_id = 'MiniGrid-FourRooms-v0'
mode = 'random'
minigrid_config = {'mode': mode}
env = gym_make(id=env_id, minigrid_config=minigrid_config)
model = load_model('../experiments/trained-models/20191109-run4.pkl', env, mode=mode)<jupyter_output><empty_output><jupyter_text>Reconstruction<jupyter_code>env_id = 'MiniGrid-FourRooms-v0'
mode = 'small'
minigrid_config = {'mode': mode}
env = gym_make(id=env_id, minigrid_config=minigrid_config)
model = load_model('../experiments/trained-models/20191119-run4.pkl', env, mode=mode)<jupyter_output><empty_output><jupyter_text>First layer filters visualized as images<jupyter_code>first_layer = model.encoder[0].weight
images = []
for f in first_layer:
    f_np = f.permute(1, 2, 0).detach().numpy()
    f_np = np.interp(f_np, (f_np.min(), f_np.max()), (0, 255))
    image = Image.fromarray(f_np, 'RGB').resize((60, 60), Image.NEAREST)
    images.append(image)
plt.figure(figsize=(20,10))
columns = 8
for i, image in enumerate(images):
    plt.subplot(len(images) / columns + 1, columns, i + 1)
    plt.imshow(image)<jupyter_output><empty_output><jupyter_text>Image embedding feature vectors<jupyter_code>_ = env.reset()
positions = np.array(list(DSR.keys()))
features = []
for pos in positions:
    env.unwrapped.agent_pos = pos
    obs, _, _, _ = env.step(0)
    obs = torch.Tensor(obs).unsqueeze(0) / 255
    f = model(obs).squeeze(0).detach().numpy()
    features.append(f)
features = np.stack(features)
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
reduced = pca.fit_transform(features)
pca.explained_variance_ratio_
plt.scatter(reduced[:, 0], reduced[:, 1])
plt.scatter(positions[:, 0], reduced[:, 0], color='blue')
plt.scatter(positions[:, 0], reduced[:, 1], color='green')
plt.scatter(positions[:, 1], reduced[:, 0], color='blue')
plt.scatter(positions[:, 1], reduced[:, 1], color='green')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17936117936117937, 'fraction_numerical': 0.036309036309036306, 'mean_word_length': 4.372434017595308, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '652647', 'license': 'MIT', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1495, 'n_words': 274, 'path': 'playground/visualization.ipynb', 'repo_name': '2016choang/sfl', 'size': '3663'}