<jupyter_start><jupyter_text>Analyzing Simulated Power SpectraThis notebook goes over analyzing the simulated power spectra.Note that this notebook covers how the simulated power spectra are analyzed, and plots some of the outputs, but does not run the full analysis that creates the final figures of the simulation analyses. To re-run the actual analyses of the simulated data, use the scripts available in `/scripts`.<jupyter_code>%matplotlib inline

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('talk')
# Import custom project code
import sys
sys.path.append('../bratios')
from ratios import *
from settings import *
from paths import DATA_PATHS as dp
from paths import FIGS_PATHS as fp<jupyter_output><empty_output><jupyter_text>Analyze results from single parameter simulationsFirst we will start by analyzing the set of single parameter variation simulations that we generated in the prior notebook.Recall that this data is a set of power spectra that vary across the power of the higher oscillation band.<jupyter_code># Load data from the prior notebook
pw_dat = np.load(dp.make_file_path(dp.demo, 'PW_DEMO', 'npy'))
# First we will extract the power values for each higher oscillation in the simulated spectra
pw_syns = []
for val in pw_dat[2]:
    pw_syns.append(val.gaussian_params[1][1])
# Calculate band ratios
pw_ratios = []
for pw in pw_dat[1]:
    pw_ratios.append(calc_band_ratio(pw_dat[0], pw, THETA_BAND, BETA_BAND))
# Collect measures together into a dataframe
pw_cols = np.array([pw_ratios, pw_syns]).T.tolist()
df_pw = pd.DataFrame(pw_cols, columns=["band_ratio", "power"])
# Plot the calculated band ratio measures across the change in power
plt.plot(df_pw.power, df_pw.band_ratio, color='r', linewidth=3)
plt.xlabel("High Band Power", {'fontsize' : 14})
plt.ylabel("Band Ratio", {'fontsize' : 14});<jupyter_output><empty_output><jupyter_text>Recall that we varied the power of the higher band. Here we see that as power increases, the band ratio value decreases. This is consistent with expectation since band ratios are calculated as avg(low-band power) / avg(high-band power). As the denominator increases, which is reflected by increasing the power of the higher band, band ratios decrease.  Plots for all single parameter simulationsThe main analysis of all the different single parameter simulations is run by an external script. All the figures from those analyses are available in the `figures` folder.<jupyter_code># Check all the figures available for single parameter simualations
fp.list_files('sims_single')<jupyter_output>Files in the sims_single directory:
     aperiodic_ABR.pdf
     aperiodic_TAR.pdf
     aperiodic_TBR.pdf
     periodic_ABR.pdf
     periodic_TAR.pdf
     periodic_TBR.pdf<jupyter_text>Analyze results from interacting parameter simulationsIn this next section, let's analyze some of the data from the interacting parameters simulations.Recall in the prior notebook we simulated some test data with varying aperiodic exponent and oscillation power. Here let's examine how band ratio measures are affected when these two parameters change together.<jupyter_code># Load the simulated data from the prior notebooks
exp_pw_dat = np.load(dp.make_file_path(dp.demo, 'EXP_PW_DEMO', 'npy'))
# Here, we will step across the data, calculate band ratio measures, and collect the outputs 
data = []
for param in exp_pw_dat:
    
    inner_list = []
    freqs = param[1]

    for psd in param[2]:
    
        curr_ratio = calc_band_ratio(freqs, psd, THETA_BAND, BETA_BAND)
        inner_list.append(curr_ratio)

    data.append(inner_list)
    
data = np.array(data)<jupyter_output><empty_output><jupyter_text>Now that we've collected the band ratio measures, let's plot the data. Since we are plotting across two dimensions (two parameters that vary), we'll use a heatmap.<jupyter_code># Plot the calculate band ratio measures
ax = sns.heatmap(data, xticklabels=PWS, yticklabels=EXPS)

# Plot aesthetics
ax.invert_yaxis()
plt.xlabel("Power", {'fontsize' : 14})
plt.ylabel("Exponent", {'fontsize' : 14});<jupyter_output><empty_output><jupyter_text>In the above plot, we see that changing exponent and/or power does change the measured band ratio value.However, one thing that we might notice as well, that is also known about band ratio values, is that this plot has a skewed distribution, with a small number of values with a very high value. This makes it hard to see the pattern across the other values. To deal with this, next we'll plot the same data in log spacing.  Plotting interacting parameters with logged ratios<jupyter_code># Replot the data in log
logged_data =np.log10(data)
ax = sns.heatmap(logged_data, xticklabels=PWS, yticklabels=EXPS)

# Plot aesthetics
ax.invert_yaxis()
plt.xlabel("Power", {'fontsize' : 14})
plt.ylabel("Exponent", {'fontsize' : 14});<jupyter_output><empty_output><jupyter_text>Consistent with the single parameter simulation we ran above, we can see that increasing power of the higher oscillation decreases measured band ratio, as expected. Looking up the y-axis, we can also see that increasing exponent value also impacts band ratio measures - in fact this looks like exponent has an even bigger effect. If you look across diagonal values, you can see how ratios change as both parameters change together.   Plots for all interacting parameter simulationsThe main analysis of all the different interacting parameter simulations is run by an external script. All the figures from those analyses are available in the `figures` folder.<jupyter_code># Check all the figures available for interacting parameter simualations
fp.list_files('sims_interacting')<jupyter_output>Files in the sims_interacting directory:
     EXP_highBW.pdf
     EXP_highCF.pdf
     EXP_highPW.pdf
     EXP_lowBW.pdf
     EXP_lowCF.pdf
     EXP_lowPW.pdf
     highCF_highBW.pdf
     highCF_highPW.pdf
     highCF_lowBW.pdf
     highCF_lowPW.pdf
     highPW_highBW.pdf
     highPW_lowBW.pdf
     lowBW_highBW.pdf
     lowCF_highBW.pdf
     lowCF_highCF.pdf
     lowCF_highPW.pdf
     lowCF_lowBW.pdf
     lowCF_lowPW.pdf
     lowPW_highBW.pdf
     lowPW_highPW.pdf
     lowPW_lowBW.pdf
{'fraction_non_alphanumeric': 0.06703190460844344, 'fraction_numerical': 0.003544956493715759, 'mean_word_length': 4.911428571428571, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '436525', 'license': 'MIT', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1769, 'n_words': 716, 'path': 'notebooks/4-Sims-Analysis.ipynb', 'repo_name': 'voytekresearch/BandRatios', 'size': '6206'}