<jupyter_start><jupyter_text>Mutual information<jupyter_code>from childes_mi.information_theory import mutual_information as mi
distances = np.arange(1,1001)
(MI, MI_var), (shuff_MI, shuff_MI_var) = mi.sequential_mutual_information(
    [np.random.permutation(i) for i in bouts_indv], distances=distances, n_jobs=-1
)
MI_DF = pd.DataFrame(
    [[MI, MI_var, shuff_MI, shuff_MI_var, distances]],
    columns=["MI", "MI_var", "shuff_MI", "shuff_MI_var", "distances"],
)
MI_DF.to_pickle(DATA_DIR / "mi" / "drosophila_mi_1000_shuffled.pickle")
row = MI_DF.iloc[0]
fig, ax = plt.subplots(figsize=(10,5))
MI = row.MI-row.shuff_MI
MI_var = row.MI_var

ax.scatter(distances, MI)
ax.fill_between(distances, MI-MI_var, MI+MI_var, alpha = 0.25, color= 'k')
ax.set_ylim([1e-2, 3])
ax.set_yscale('log')
ax.set_xscale('log')
plt.loglog(row.MI)
plt.loglog(row.shuff_MI)
from matplotlib import gridspec
from childes_mi.utils.paths import DATA_DIR, FIGURE_DIR
from childes_mi.utils.general import flatten,save_fig
yoff=-.20
ncols = 4
zoom = 5
hr = [1, 0.5, 0.5, 0.5]
nrows = np.ceil(len(MI_DF)/ncols).astype(int)
fig = plt.figure(figsize=(len(MI_DF)*zoom*1.0,np.sum(hr)*zoom)) 
gs = gridspec.GridSpec(ncols=len(MI_DF), nrows=4, height_ratios=hr) 

axi = 0
row = MI_DF.iloc[0]

color = 'k'#LCOL_DICT[row.language]
ax0 = plt.subplot(gs[0,axi])
ax = ax0
sig = np.array(row.MI-row.shuff_MI)
distances = row.distances
sig = sig
# get signal limits
sig_lims = np.log([np.min(sig[sig>0]), np.nanmax(sig)])
sig_lims = [sig_lims[0] - (sig_lims[1]-sig_lims[0])/10,
                sig_lims[1] + (sig_lims[1]-sig_lims[0])/10]

if axi==0: 
        ax.set_ylabel('MI (bits)', labelpad=5, fontsize=24)
        ax.yaxis.set_label_coords(yoff,0.5)

# plot real data
ax.scatter(distances, sig, alpha = 1, s=60, color=color)   

ax.set_xlabel('Distance (states)', labelpad=5, fontsize=24)
#print(row.language, distances[peak_of_interest])

for ax in [ax0]:
    ax.set_xlim([distances[0], distances[-1]])
    sig_lims[0] = np.log(10e-6)
    ax.set_ylim([1e-6, 0.5])
    ax.tick_params(which='both', direction='in', labelsize=14, pad=10)
    ax.tick_params(which='major', length=10, width =3)
    ax.tick_params(which='minor', length=5, width =2)
    ax.set_xscale( "log" , basex=10)
    ax.set_yscale( "log" , basey=10)
    ax.set_xticks([])
    for axis in ['top','bottom','left','right']:
        ax.spines[axis].set_linewidth(3)
        ax.spines[axis].set_color('k')

ax.set_xticks([1,10,100, 1000])
ax.set_xticklabels(['1','10','100', '1000'])
ax.set_xlim([0.9, 1000])
if axi !=0:
    for ax in [ax0,ax1,ax2]:
        ax.yaxis.set_ticklabels([])

gs.update(wspace=0.075, hspace=0.1)
ax0.set_title("Drosophila", fontsize=24)
save_fig(FIGURE_DIR/'drosophila_mi-1000-shuffled')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17958889289578076, 'fraction_numerical': 0.04688063469166967, 'mean_word_length': 5.096703296703296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '495228', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1207, 'n_words': 194, 'path': 'notebooks/drosophila2/1.0-load-drosophila-compute-mi-shuffled.ipynb', 'repo_name': 'timsainb/LongRangeSequentialOrgPaper', 'size': '2773'}