Post-hoc Temporal Analysis¶
Functions for analyzing temporal dynamics of behavioral states.
Overview¶
This module provides tools to:
- Analyze state transitions over time
- Compute dwell times in different states
- Examine temporal patterns within sessions
- Compare temporal dynamics across conditions
Functions¶
compass_labyrinth.post_hoc_analysis.level_1.temporal_analysis
¶
TEMPORAL EVOLUTION OF STATE PROBABILITIES Author: Shreya Bangera Goal: ├── Tracks probability of being in a chosen HMM state over time bins per genotype and session-averaged plots
NODE_TYPE_MAPPING
module-attribute
¶
NODE_TYPE_MAPPING = {
"decision_reward": DECISION_REWARD,
"nondecision_reward": NONDECISION_REWARD,
"corner_reward": CORNER_REWARD,
"decision_nonreward": DECISION_NONREWARD,
"nondecision_nonreward": NONDECISION_NONREWARD,
"corner_nonreward": CORNER_NONREWARD,
"entry_zone": ENTRY_ZONE_NODES,
"target_zone": TARGET_ZONE_NODES,
"decision_3way": DECISION_3WAY,
"decision_4way": DECISION_4WAY,
}
compute_node_state_medians_over_time
¶
compute_node_state_medians_over_time(
df_hmm: DataFrame,
state_types: list,
lower_lim: int,
upper_lim: int,
bin_size: int,
decision_nodes: str = "decision_reward",
nondecision_nodes: str = "nondecision_reward",
) -> pd.DataFrame
Compute time-binned medians of HMM state proportions for decision and non-decision nodes.
Parameters:
-
df_hmm(DataFrame) –Dataframe with 'Genotype', 'Session', 'HMM_State', and 'Grid Number'.
-
state_types(list) –List of HMM states to compute proportions for (e.g., [2])
-
lower_lim(int) –Range of rows to consider per session
-
upper_lim(int) –Range of rows to consider per session
-
bin_size(int) –Number of rows per time bin
-
decision_nodes(str, default:'decision_reward') –Type of decision node to consider for surveillance probability.
-
nondecision_nodes(str, default:'nondecision_reward') –Type of non-decision node to consider for surveillance probability.
Returns:
-
DataFrame–Dataframe with median proportions per session, time bin, node type, and genotype
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/temporal_analysis.py
plot_node_state_median_curve
¶
plot_node_state_median_curve(
config: dict,
deci_df: DataFrame,
figure_ylimit: tuple = (0.0, 1.1),
palette: list = ["grey", "black"],
fig_title: str | None = None,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot time-binned inverse median probabilities (1 - median) for decision and non-decision nodes.
Parameters:
-
deci_df(DataFrame) –DataFrame containing 'Time_Bins', '1-Median_Probability', and 'Genotype + Node Type'
-
palette(list, default:['grey', 'black']) –List of colors to apply to each unique category in hue
-
figure_ylimit(tuple, default:(0.0, 1.1)) –Tuple like (0, 0.6) for y-axis limits
-
fig_title(str | None, default:None) –Title of the figure
-
save_fig(bool, default:True) –Whether to save the figure.
-
show_fig(bool, default:True) –Whether to display the figure.
-
return_fig(bool, default:False) –Whether to return the figure object.
Returns:
-
Figure–Seaborn FacetGrid object
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/temporal_analysis.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
get_max_session_row_bracket
¶
Finds the session with the maximum number of rows and returns the largest lower multiple of 10,000.
Parameters:
-
df_combined(DataFrame) –Combined dataframe containing multiple sessions.
-
session_col(str, default:'Session') –Name of the column representing session ID.
Returns:
-
int–Lower bracketed row count (e.g., 20000 if max session has 23567 rows).
Source code in src/compass_labyrinth/post_hoc_analysis/level_1/temporal_analysis.py
get_min_session_row_bracket
¶
Finds the session with the minimum number of rows and returns the largest lower multiple of 10,000.
Parameters:
-
df_combined(DataFrame) –Combined dataframe containing multiple sessions.
-
session_col(str, default:'Session') –Name of the column representing session ID.
Returns:
-
int–Lower bracketed row count (e.g., 10000 if min session has 10234 rows).