<jupyter_start><jupyter_text>This notebook reproduces the video-recall event correlation matrices  Imports<jupyter_code>import numpy as np
import pandas as pd
from scipy.spatial.distance import cdist

from sherlock_helpers.constants import DATA_DIR, EDGECOLOR, FIG_DIR

import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib.patches import Rectangle
import seaborn as sns
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Set plotting params<jupyter_code>sns.set_context('paper')
cmap = plt.cm.bone_r
mpl.rcParams['pdf.fonttype'] = 42<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>video_events = np.load(DATA_DIR.joinpath('video_events.npy'))
recall_events = np.load(DATA_DIR.joinpath('recall_events.npy'),
                        allow_pickle=True)<jupyter_output><empty_output><jupyter_text>Compute correlation matrices<jupyter_code>matchmats = [1 - cdist(video_events, r, 'correlation') for r in recall_events]<jupyter_output><empty_output><jupyter_text>Plot figure<jupyter_code>fig, axarr = plt.subplots(5, 4)
axarr = axarr.ravel()
fig.set_size_inches(8, 10)

# video model
for i, ax in enumerate(axarr):
    try:
        m = matchmats[i]
    except IndexError:
        ax.axis('off')
        continue
    
    sns.heatmap(m, 
                xticklabels=5, 
                yticklabels=5, 
                vmin=0, 
                vmax=1, 
                cmap=cmap, 
                cbar=False, 
                ax=ax)
    ax.set_ylabel('Video event')
    ax.set_xlabel('Recall event')
    ax.set_title(f'P{i + 1}')
    
    for spine in ax.spines.values():
        spine.set_visible(True)
        
    ax.hlines(range(video_events.shape[0]), *ax.get_xlim(), linewidth=.25)
    ax.vlines(range(recall_events[i].shape[0]), *ax.get_ylim(), linewidth=.25)
        
    bounds = m.argmax(axis=0)
    for j, b in enumerate(bounds):
        rect = Rectangle((j, b), 
                         1, 1, 
                         linewidth=1, 
                         edgecolor=EDGECOLOR, 
                         facecolor='none', 
                         zorder=2)
        ax.add_patch(rect)
        
plt.tight_layout()
# plt.savefig(FIG_DIR.joinpath('matchmats.pdf'))
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11071744906997343, 'fraction_numerical': 0.010628875110717449, 'mean_word_length': 2.790268456375839, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '168969', 'license': 'MIT', 'n_tokens_mistral': 816, 'n_tokens_neox': 772, 'n_words': 132, 'path': 'code/notebooks/supp/matchmats.ipynb', 'repo_name': 'paxtonfitzpatrick/sherlock-topic-model-paper', 'size': '2258'}