Attention is all you need, and a chunky prefrontal cortex
ALien Brain ExtRacTion Analytics (ALBERTA) Consortium
import numpy as np
import pandas as pd
import plotly.express as px
from scipy.stats import pearsonr
import math
import plotly.io as pio
pio.renderers.default = "plotly_mimetype"
# Seed for reproducibility
np.random.seed(42)
# Number of datapoints for each scatter plot
n_points = 400
# Function to generate synthetic data for brain volume vs. cognitive performance
def generate_synthetic_data(volume_mean, volume_std, score_mean, score_std, correlation, n_points):
volume = np.random.normal(volume_mean, volume_std, n_points)
volume_jitter = np.random.normal(0, volume_std * 1.5, n_points) # Add jitter to volume
noise = np.random.normal(0, score_std * 43.5, n_points) # Increase noise for jitter in score
score = -0.5*score_mean + correlation * (volume - volume_mean) + noise
return volume + volume_jitter, score
# Function to generate additional metrics
def generate_additional_metrics(volume, score, volume_std, score_std, n_points):
# Hypothetical Brain Density: Based on volume with added noise
density = volume / (volume_std * np.random.uniform(0.8, 1.2, n_points))
noise = np.random.normal(0, score_std * 0.21, n_points) # Increase noise for jitter in score
# Hypothetical Neural Efficiency: Positively correlated with score but with noise
efficiency = score / (score_std * np.random.uniform(1.2, 11.7, n_points))
return density, efficiency
# Generate synthetic data for 10 scatter plots
data_dict = {}
# Scatter plot 2: Prefrontal Cortex Volume vs. Attention Score
data_dict["Prefrontal_Attention"] = generate_synthetic_data(2000, 800, 60, 9, 0.35, n_points)
df_dict = {key: pd.DataFrame({'Volume': value[0], 'Score': value[1]}) for key, value in data_dict.items()}
# Apply additional metrics to all regions
for key, df in df_dict.items():
volume_std = np.std(df['Volume'])
score_std = np.std(df['Score'])
# Generate new metrics for Brain Density and Neural Efficiency
density, efficiency = generate_additional_metrics(df['Volume'], df['Score'], volume_std, score_std, n_points)
# Add the new metrics to the DataFrame
df['Density'] = density
df['Efficiency'] = efficiency
def plot_correlation(df_dict, key, x_col, y_col, title_prefix, color='blue', marker_size=10, marker_opacity=0.7):
df = df_dict[key]
# Calculate Spearman correlation
corr, _ = pearsonr(df[x_col], df[y_col])
# Create scatter plot with customized marker colors, size, and opacity
fig = px.scatter(
df,
x=x_col,
y=y_col,
title=f'{title_prefix} (Pearson: {corr:.2f})',
trendline='ols',
color_discrete_sequence=[color],
template = "seaborn"
)
# Update marker style
fig.update_traces(marker=dict(size=marker_size, opacity=marker_opacity))
# Update figure layout
fig.update_layout(height=600)
return fig
fig1 = plot_correlation(df_dict, "Prefrontal_Attention", 'Volume', 'Score', 'Prefrontal', color='slategray', marker_size=10, marker_opacity=0.7)
fig1.show()
fig2 = plot_correlation(df_dict, "Prefrontal_Attention", 'Density', 'Score', 'Prefrontal', color='purple', marker_size=10, marker_opacity=0.4)
fig2.show()
fig2 = plot_correlation(df_dict, "Prefrontal_Attention", 'Efficiency', 'Score', 'Prefrontal', color="crimson", marker_size=10, marker_opacity=0.7)
fig2.show()