<jupyter_start><jupyter_text>Get model contribution by distance<jupyter_code>import pandas as pd
from parallelspaper.config.paths import DATA_DIR, FIGURE_DIR
from parallelspaper.birdsong_datasets import BCOL_DICT
import numpy as np
from parallelspaper import model_fitting as mf
from parallelspaper.utils import save_fig
from parallelspaper import information_theory as it 
from matplotlib import gridspec
import matplotlib.pyplot as plt
%matplotlib inline
# stats
CAVICATH_stats_df = pd.read_pickle(DATA_DIR / 'stats_df/CAVICATH_stats_df.pickle')
Starling_stats_df = pd.read_pickle(DATA_DIR / 'stats_df/starling_stats_df.pickle')
BF_stats_df = pd.read_pickle(DATA_DIR / 'stats_df/BF_stats_df.pickle')

stats_df = pd.concat([CAVICATH_stats_df, Starling_stats_df, BF_stats_df])
 MI_DF = pd.read_pickle(DATA_DIR / 'MI_DF/birdsong/birdsong_MI_DF_fitted.pickle')
subset_MI_DF = MI_DF[MI_DF.type == 'day']
subset_MI_DF
distances = np.logspace(0,2, base=10, num=1000)
fig, axs = plt.subplots(ncols = 4, figsize=(16,4))
for axi, (idx, row) in enumerate(subset_MI_DF.iterrows()):
    
    birdrow = stats_df.species.values == row.species
    median_syllable_len = np.median(stats_df[birdrow].syllable_duration_s.values[0])
    median_isi =  np.median(stats_df[birdrow].isi.values[0])
    
    max_peak_dist = distances[int(np.argmax(row.curvature))]
    lower_mask = row.distances < max_peak_dist
    y_model = mf.get_y(mf.pow_exp_decay, row.concat_results, row.distances)
    y_pow = mf.get_y(mf.powerlaw_decay, row.concat_results, row.distances)
    y_exp = mf.get_y(mf.exp_decay, row.concat_results, row.distances)
    y = row.MI - row.MI_shuff
    
    print(
        row.species, 
        np.sum(y_pow[lower_mask]/y_model[lower_mask])/np.sum(lower_mask),
        (median_syllable_len+median_isi)* max_peak_dist
    )
    
    
    axs[axi].loglog(row.distances, y_model, color = BCOL_DICT[row.species])
    axs[axi].loglog(row.distances, y_pow, color = BCOL_DICT[row.species], ls='dotted')
    axs[axi].loglog(row.distances, y_exp, color = BCOL_DICT[row.species], ls='dashed')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11174512601046124, 'fraction_numerical': 0.006657156443176415, 'mean_word_length': 5.224852071005917, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '23426', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 849, 'n_tokens_neox': 814, 'n_words': 129, 'path': 'notebooks/birdsong/17.0-birdsong-early-power-law-analysis.ipynb', 'repo_name': 'timsainb/ParallelsBirdsongLanguagePaper', 'size': '2103'}