Success Metrics¶
Functions for computing success rates and analyzing task performance across sessions.
Overview¶
This module provides tools for:
- Assigning bout indices based on entry nodes
- Computing success rates per session and across bins
- Statistical analysis of success patterns
- Visualizing success metrics over time
Bout Assignment¶
assign_bout_indices_from_entry_node¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.assign_bout_indices_from_entry_node
¶
assign_bout_indices_from_entry_node(
navigation_df: DataFrame, delimiter_node: int = 47
) -> pd.DataFrame
Assigns bout indices to each row of a session based on entries to a delimiter node (e.g., Entry node = 47). A new bout starts every time the delimiter node is encountered.
Parameters:
-
navigation_df(DataFrame) –DataFrame with 'Session' and 'Grid Number' columns.
-
delimiter_node(int, default:47) –Grid number that marks the entry point for bouts.
Returns:
-
DataFrame–DataFrame with an added 'Bout_ID' column.
Source code in src/compass_labyrinth/behavior/behavior_metrics/task_performance_analysis/success_metrics.py
Success Rate Analysis¶
summarize_bout_success_by_session¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.summarize_bout_success_by_session
¶
summarize_bout_success_by_session(
navigation_df: DataFrame,
optimal_regions: list = [
"entry_zone",
"reward_path",
"target_zone",
],
target_region_label: list = ["target_zone"],
min_bout_length: int = 20,
) -> pd.DataFrame
Computes number of total, valid, successful, and perfect bouts per session.
Parameters:
-
navigation_df(DataFrame) –DataFrame with 'Session', 'Genotype', 'Region', and 'Bout_Index'.
-
optimal_regions(list, default:['entry_zone', 'reward_path', 'target_zone']) –Ordered list of region labels that define a perfect bout.
-
target_region_label(list, default:['target_zone']) –Region considered as successful bout completion.
-
min_bout_length(int, default:20) –Minimum length of frames required to count a bout as valid.
Returns:
-
summary_table(DataFrame) –DataFrame summarizing bout stats by session.
Source code in src/compass_labyrinth/behavior/behavior_metrics/task_performance_analysis/success_metrics.py
compute_binned_success_summary¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.compute_binned_success_summary
¶
compute_binned_success_summary(
df_all_csv: DataFrame,
lower_succ_lim: int = 0,
upper_succ_lim: int = 90000,
diff_succ: int = 5000,
valid_bout_threshold: int = 19,
optimal_path_regions: list[str] = [
"entry_zone",
"reward_path",
"target_zone",
],
target_zone: str = "target_zone",
) -> pd.DataFrame
Computes successful bout metrics per session, binned by cumulative frame index.
Parameters:
-
df_all_csv(DataFrame) –DataFrame with 'Session', 'Genotype', 'Region', 'Bout_ID', and 'Frame' columns.
-
lower_succ_lim(int, default:0) –Lower limit of frames to start binning.
-
upper_succ_lim(int, default:90000) –Upper limit of frames to end binning.
-
diff_succ(int, default:5000) –Size of each frame bin.
-
valid_bout_threshold(int, default:19) –Minimum number of frames for a bout to be considered valid.
-
optimal_path_regions(list, default:['entry_zone', 'reward_path', 'target_zone']) –Regions defining a perfect bout.
-
target_zone(str, default:'target_zone') –Region considered as successful bout completion.
Returns:
-
DataFrame–DataFrame summarizing binned successful bout metrics per session.
Source code in src/compass_labyrinth/behavior/behavior_metrics/task_performance_analysis/success_metrics.py
Visualization¶
plot_success_rate¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.plot_success_rate
¶
plot_success_rate(
config: dict,
summary_table: DataFrame,
palette: list = None,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plots a barplot showing success rates across genotypes from the bout summary.
Parameters:
-
config(dict) –Project configuration dictionary.
-
summary_table(DataFrame) –Output from summarize_bout_success_by_session.
-
palette(list, default:None) –Optional color palette for different genotypes.
-
save_fig(bool, default:True) –Whether to save the figure as a PDF.
-
show_fig(bool, default:True) –Whether to display the figure.
-
return_fig(bool, default:False) –Whether to return the figure object.
Returns:
-
Figure or None–The matplotlib figure object if return_fig is True, else None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/task_performance_analysis/success_metrics.py
plot_binned_success¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.plot_binned_success
¶
plot_binned_success(
config: dict,
summary_df: DataFrame,
palette: list[str] = None,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plots % of successful bouts over time across genotypes.
Parameters:
-
config(dict) –Project configuration dictionary.
-
summary_df(DataFrame) –DataFrame containing summary statistics for each session.
-
palette(list, default:None) –Optional color palette for different genotypes.
-
save_fig(bool, default:True) –Whether to save the figure as a PDF.
-
show_fig(bool, default:True) –Whether to display the figure.
-
return_fig(bool, default:False) –Whether to return the figure object.
Returns:
-
Figure or None–The matplotlib figure object if return_fig is True, else None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/task_performance_analysis/success_metrics.py
Statistical Analysis¶
perform_genotype_ttests¶
compass_labyrinth.behavior.behavior_metrics.task_performance_analysis.success_metrics.perform_genotype_ttests
¶
Performs t-tests between genotypes on a given rate column (e.g., success_rate or perfect_rate).
Parameters:
-
summary_table(DataFrame) –DataFrame from
summarize_bout_success_by_session -
rate_col(str, default:'success_rate') –Column to compare across genotypes. Default is 'success_rate'.
Returns:
-
dict–Dictionary with t-test results between each genotype pair.