Simulated Agents¶
Agent-based models for simulating navigation behavior in the labyrinth.
Overview¶
This module provides computational models that simulate different navigation strategies:
- Basic simulated agents with configurable parameters
- Explore-exploit agents that balance exploration and exploitation
- Multi-agent simulations for comparative analysis
Simulated Agent¶
compass_labyrinth.behavior.behavior_metrics.simulation_modeling.simulated_agent
¶
SIMULATED AGENT MODELING AND ANALYSIS Author: Shreya Bangera Goal: ├── Simulated Agent Modeling & Visualisation ├── Chi Square Analysis, Visualisation
get_valid_and_optimal_transitions
¶
get_valid_and_optimal_transitions(
df: DataFrame,
decision_label: str = "Decision (Reward)",
reward_label: str = "reward_path",
) -> tuple[dict, dict]
Extract valid and optimal transitions per session.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
decision_label(str, default:'Decision (Reward)') –Label for decision points.
-
reward_label(str, default:'reward_path') –Label for reward path.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
simulate_agent_vs_actual
¶
simulate_agent_vs_actual(
df_slice: DataFrame,
valid_dict: dict,
optimal_dict: dict,
n_simulations: int,
decision_label: str = "Decision (Reward)",
) -> tuple[list, list]
Simulate random agent transitions and compare with actual.
Parameters:
-
df_slice(DataFrame) –DataFrame segment for the epoch.
-
valid_dict(dict) –Valid transitions for the session.
-
optimal_dict(dict) –Optimal transitions for the session.
-
n_simulations(int) –Number of random simulations per decision point.
-
decision_label(str, default:'Decision (Reward)') –Label for decision points.
Returns:
-
tuple of lists–Lists of actual and simulated optimal transitions (1 for optimal, 0 otherwise).
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
bootstrap_distribution
¶
Generate bootstrap sample means.
Parameters:
-
data(list) –Data points.
-
n_samples(int, default:10000) –Number of bootstrap samples.
Returns:
-
ndarray–Array of bootstrap sample means.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
compute_epoch_metrics
¶
compute_epoch_metrics(
df_slice: DataFrame,
valid_dict: dict,
optimal_dict: dict,
n_bootstrap: int,
n_simulations: int,
decision_label: str = "Decision (Reward)",
) -> pd.Series
Compute performance metrics for a single epoch of navigation.
Parameters:
-
df_slice(DataFrame) –DataFrame segment for the epoch.
-
valid_dict(dict) –Valid transitions for the session.
-
optimal_dict(dict) –Optimal transitions for the session.
-
n_bootstrap(int) –Number of bootstrap samples.
-
n_simulations(int) –Number of random simulations per decision point.
-
decision_label(str, default:'Decision (Reward)') –Label for decision points.
Returns:
-
Series–Series with computed metrics.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
segment_data_by_epoch
¶
Split DataFrame by genotype and session into sequential time-based epochs.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
epoch_size(int) –Number of rows per epoch.
Returns:
-
list of tuples–Each tuple contains (session, epoch_number, epoch_dataframe).
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
trim_to_common_epochs
¶
Trims the results dataframe to retain only the maximum number of epochs common across all sessions.
Parameters:
-
df_results(DataFrame) –The output of evaluate_agent_performance. - 'Session' (str): Column name indicating sessions. - 'Epoch_Number' (str): Column name indicating epoch/bin number.
Returns:
-
DataFrame–Trimmed dataframe with only common epochs.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
evaluate_agent_performance
¶
evaluate_agent_performance(
df: DataFrame,
epoch_size: int,
n_bootstrap: int,
n_simulations: int,
decision_label: str = "Decision (Reward)",
reward_label: str = "reward_path",
genotype: str | None = None,
trim: bool = True,
) -> pd.DataFrame
Run full evaluation pipeline for simulated agent vs. actual mouse.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
epoch_size(int) –Number of rows per epoch.
-
n_bootstrap(int) –Number of bootstrap samples.
-
n_simulations(int) –Number of random simulations per decision point.
-
decision_label(str, default:'Decision (Reward)') –Label for decision points.
-
reward_label(str, default:'reward_path') –Label for reward path.
-
genotype(str | None, default:None) –Genotype to filter data.
-
trim(bool, default:True) –Whether to trim to common epochs across sessions.
Returns:
-
DataFrame–DataFrame with performance metrics per epoch.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
plot_agent_transition_performance
¶
plot_agent_transition_performance(
config: dict,
evaluation_results: dict,
genotype: str | None = None,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot performance comparison between actual mouse and simulated agent over time.
Parameters:
-
config(dict) –Configuration dictionary containing project settings.
-
evaluation_results(dict) –Dictionary with evaluation results for each genotype.
-
genotype(str | None, default:None) –Specific genotype to plot. If None, plots all genotypes.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
plot_relative_agent_performance
¶
plot_relative_agent_performance(
config: dict,
evaluation_results: dict,
genotype: str | None = None,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot relative performance of mouse vs simulated agent over time.
Parameters:
-
config(dict) –Configuration dictionary containing project settings.
-
evaluation_results(dict) –Dictionary with evaluation results for each genotype.
-
genotype(str | None, default:None) –Specific genotype to plot. If None, plots all genotypes.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
plot_agent_performance_boxplot
¶
plot_agent_performance_boxplot(
df_long: DataFrame,
p_value: float,
palette: None | list = None,
) -> None
Plot boxplot comparing actual vs simulated agent with p-value annotation.
Parameters:
-
df_long(DataFrame) –Long-form DataFrame.
-
p_value(float) –P-value from mixed model.
-
palette(list or None, default:None) –Color palette for the boxplot.
Returns:
-
None–
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
reshape_for_mixedlm
¶
Reshape the dataframe to long format for mixed-effects modeling.
Parameters:
-
df_results(DataFrame) –DataFrame with columns 'Actual Reward Path %', 'Simulated Agent Reward Path %', 'Session', 'Epoch Number' and 'Genotype'.
Returns:
-
DataFrame–Long-form DataFrame suitable for mixedlm.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
fit_mixed_effects_model
¶
Fit a linear mixed-effects model comparing agent types.
Parameters:
-
df_long(DataFrame) –Long-form DataFrame.
Returns:
-
tuple–Tuple with result (Fitted model object) and p_value (P-value for AgentType effect).
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
plot_agent_performance_boxplot_ax
¶
plot_agent_performance_boxplot_ax(
ax: Axes,
df_long: DataFrame,
p_value: float,
palette: list | None = None,
genotype: str | None = None,
) -> None
Plot a boxplot of agent performance.
Parameters:
-
ax(Axes) –Matplotlib Axes object to plot on.
-
df_long(DataFrame) –Long-form DataFrame.
-
p_value(float) –P-value from mixed model.
-
palette(list or None, default:None) –Color palette for the boxplot.
-
genotype(str or None, default:None) –Genotype name for the title.
Returns:
-
None–
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
run_mixedlm_for_all_genotypes
¶
run_mixedlm_for_all_genotypes(
config: dict,
evaluation_results: dict,
plot_palette=None,
save_fig: bool = True,
show_fig: bool = True,
) -> dict
Run mixed-effects modeling and plot results for all genotypes.
Parameters:
-
config(dict) –Configuration dictionary containing project settings..
-
evaluation_results(dict) –Dictionary with evaluation results for each genotype.
-
plot_palette(list or None, default:None) –Color palette for the boxplots.
-
save_fig(bool, default:True) –Whether to save the figure.
-
show_fig(bool, default:True) –Whether to display the figure.
Returns:
-
dict–Dictionary with p-values for each genotype.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
compute_chi_square_statistic
¶
Compute the chi-square statistic between actual and simulated reward path usage for each row in the DataFrame. Also ensures 'Epoch Number' and 'Session' are integers.
Parameters:
-
df(DataFrame) –DataFrame with columns 'Actual Reward Path %' and 'Simulated Agent Reward Path %'.
Returns:
-
DataFrame–Updated DataFrame with 'Chi Square Statistic' and cleaned column types.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
compute_rolling_chi_square
¶
Compute rolling average of chi-square statistic within each session.
Patameters:
df : pd.DataFrame DataFrame with 'Chi Square Statistic' column. window : int Window size for rolling average.
Returns:
-
DataFrame–Updated DataFrame with 'Rolling Chi Square' column.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
compute_cumulative_chi_square
¶
Compute cumulative sum of chi-square statistic within each session.
Parameters:
-
df(DataFrame) –DataFrame with 'Chi Square Statistic' column.
Returns:
-
DataFrame–Updated DataFrame with 'Cumulative Chi Square' column.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
run_chi_square_analysis
¶
Run chi-square analysis for each genotype in the evaluation results.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
plot_chi_square_and_rolling
¶
plot_chi_square_and_rolling(
config: dict,
chisquare_results: dict,
epoch_col: str = "Epoch Number",
chi_col: str = "Chi Square Statistic",
rolling_col: str = "Rolling Chi Square",
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot chi-square and rolling statistics for each genotype.
Parameters:
-
config(dict) –Configuration dictionary containing project settings..
-
chisquare_results(dict) –Chi-square results dictionary.
-
epoch_col(str, default:'Epoch Number') –Column name for epochs.
-
chi_col(str, default:'Chi Square Statistic') –Column name for chi-square statistic.
-
rolling_col(str, default:'Rolling Chi Square') –Column name for rolling chi-square.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
plot_rolling_mean
¶
plot_rolling_mean(
config: dict,
chisquare_results: dict,
epoch_col: str = "Epoch Number",
rolling_col: str = "Rolling Chi Square",
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot rolling chi-square statistics for each genotype.
Parameters:
-
config(dict) –Configuration dictionary containing project settings..
-
chisquare_results(dict) –Chi-square results dictionary.
-
epoch_col(str, default:'Epoch Number') –Column name for epochs.
-
rolling_col(str, default:'Rolling Chi Square') –Column name for rolling chi-square.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
plot_cumulative_chi_square
¶
plot_cumulative_chi_square(
config: dict,
chisquare_results: dict,
epoch_col: str = "Epoch Number",
cum_col: str = "Cumulative Chi Square",
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot cumulative chi-square statistics for each genotype.
Parameters:
-
config(dict) –Configuration dictionary containing project settings..
-
chisquare_results(dict) –Chi-square results dictionary.
-
epoch_col(str, default:'Epoch Number') –Column name for epochs.
-
cum_col(str, default:'Cumulative Chi Square') –Column name for cumulative chi-square.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
Explore-Exploit Agent¶
compass_labyrinth.behavior.behavior_metrics.simulation_modeling.explore_exploit_agent
¶
EXPLORATION-EXPLOITATION AGENT MODELING AND ANALYSIS Author: Shreya Bangera
trim_to_common_epochs
¶
Trims the results dataframe to retain only the maximum number of epochs common across all sessions.
Parameters:
-
df_results(DataFrame) –The output of evaluate_agent_performance. - 'Session' (str): Column name indicating sessions. - 'Epoch_Number' (str): Column name indicating epoch/bin number.
Returns:
-
DataFrame–Trimmed dataframe with only common epochs.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
track_valid_and_optimal_transitions_EE
¶
track_valid_and_optimal_transitions_EE(
df: DataFrame, decision_label: str, reward_label: str
) -> tuple[dict, dict]
Tracks valid and optimal transitions for an exploration-exploitation agent.
Parameters:
-
df(DataFrame) –DataFrame containing maze navigation data.
-
decision_label(str) –Label indicating decision nodes.
-
reward_label(str) –Label indicating reward paths.
Returns:
-
valid_transitions(dict) –Dictionary of valid transitions per session.
-
optimal_transitions(dict) –Dictionary of optimal transitions per session.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
simulate_exploration_agent_EE
¶
simulate_exploration_agent_EE(
segment: DataFrame,
valid_dict: dict,
optimal_dict: dict,
exploration_rate: float,
n_simulations: int,
decision_label: str,
) -> tuple[list, list]
Simulates the behavior of an exploration-exploitation agent.
Parameters:
-
segment(DataFrame) –DataFrame segment containing maze navigation data.
-
valid_dict(dict) –Dictionary of valid transitions.
-
optimal_dict(dict) –Dictionary of optimal transitions.
-
exploration_rate(float) –Probability of exploring a non-optimal path.
-
n_simulations(int) –Number of simulations to run per decision point.
-
decision_label(str) –Label indicating decision nodes.
Returns:
-
actual(list) –List of actual outcomes (1 for optimal, 0 for non-optimal).
-
simulated(list) –List of simulated outcomes (mean proportion of optimal choices).
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
calculate_segment_metrics_EE
¶
calculate_segment_metrics_EE(
segment: DataFrame,
valid_dict: dict,
optimal_dict: dict,
exploration_rate: float,
n_bootstrap: int,
n_simulations: int,
decision_label: str,
) -> pd.Series
Calculates performance metrics for a segment of maze navigation data.
Parameters:
-
segment(DataFrame) –DataFrame segment containing maze navigation data.
-
valid_dict(dict) –Dictionary of valid transitions.
-
optimal_dict(dict) –Dictionary of optimal transitions.
-
exploration_rate(float) –Probability of exploring a non-optimal path.
-
n_bootstrap(int) –Number of bootstrap samples for confidence intervals.
-
n_simulations(int) –Number of simulations to run per decision point.
-
decision_label(str) –Label indicating decision nodes.
Returns:
-
Series–Series containing calculated metrics.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
split_sessions_into_segments_EE
¶
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
run_exploration_agent_analysis_EE
¶
run_exploration_agent_analysis_EE(
df: DataFrame,
exploration_rate: float,
segment_size: int = 1000,
n_bootstrap: int = 10000,
n_simulations: int = 100,
decision_label: str = "Decision (Reward)",
reward_label: str = "reward_path",
trim: bool = True,
) -> pd.DataFrame
Run exploration agent analysis on the given DataFrame.
Parameters:
-
df(DataFrame) –DataFrame containing maze navigation data.
-
exploration_rate(float) –Probability of exploring a non-optimal path.
-
segment_size(int, default:1000) –Size of each segment for analysis (default is 1000).
-
n_bootstrap(int, default:10000) –Number of bootstrap samples for confidence intervals (default is 10000).
-
n_simulations(int, default:100) –Number of simulations to run per decision point (default is 100).
-
decision_label(str, default:'Decision (Reward)') –Label indicating decision nodes (default is "Decision (Reward)").
-
reward_label(str, default:'reward_path') –Label indicating reward paths (default is "reward_path").
-
trim(bool, default:True) –Whether to trim the DataFrame to common epochs (default is True).
Returns:
-
DataFrame–DataFrame containing analysis results for each segment.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
plot_exploration_rate_performance_EE
¶
plot_exploration_rate_performance_EE(
config: dict,
df_source: DataFrame,
exploration_rates: list[float],
segment_size: int = 1000,
decision_label: str = "Decision (Reward)",
reward_label: str = "reward_path",
trim: bool = True,
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plots the performance of an exploration-exploitation agent across varying exploration rates.
Parameters:
-
config(dict) –Configuration dictionary containing project settings.
-
df_source(DataFrame) –DataFrame containing maze navigation data.
-
exploration_rates(list of float) –List of exploration rates to evaluate.
-
segment_size(int, default:1000) –Size of each segment for analysis (default is 1000).
-
decision_label(str, default:'Decision (Reward)') –Label indicating decision nodes (default is "Decision (Reward)").
-
reward_label(str, default:'reward_path') –Label indicating reward paths (default is "reward_path").
-
trim(bool, default:True) –Whether to trim the DataFrame to common epochs (default is True).
-
save_fig(bool, default:True) –Whether to save the figure (default is True).
-
show_fig(bool, default:True) –Whether to display the figure (default is True).
-
return_fig(bool, default:False) –Whether to return the figure object (default is False).
Returns:
-
None or Figure–Returns the figure if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/explore_exploit_agent.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
Multi-Agent Simulation¶
compass_labyrinth.behavior.behavior_metrics.simulation_modeling.multi_agent
¶
MULTI-AGENT MODELING Author: Shreya Bangera Goal: ├── Simulated Agent, Binary Agent, 3/4 way Agent Modelling ├── Comparsion across Agents
trim_to_common_epochs
¶
Trims the results dataframe to retain only the maximum number of epochs common across all sessions.
Parameters:
-
df_results(DataFrame) –The output of evaluate_agent_performance. - 'Session' (str): Column name indicating sessions. - 'Epoch_Number' (str): Column name indicating epoch/bin number.
Returns:
-
DataFrame–Trimmed dataframe with only common epochs.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/simulated_agent.py
split_into_epochs_multi
¶
Split the DataFrame into epochs of specified size for each session.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
epoch_size(int) –Number of steps per epoch.
Returns:
-
list–A list of tuples containing (session, epoch index, chunk DataFrame).
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
track_valid_transitions_multi
¶
track_valid_transitions_multi(
df: DataFrame, decision_label: str, reward_label: str
) -> tuple[dict, dict]
Track valid and optimal transitions for each session.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
decision_label(str) –Label for decision nodes.
-
reward_label(str) –Label for reward path regions.
Returns:
-
tuple[dict, dict]–A tuple containing two dictionaries: - session_valid: Maps session to valid transitions. - session_optimal: Maps session to optimal transitions.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
simulate_random_agent_multi
¶
simulate_random_agent_multi(
chunk: DataFrame,
valid_dict: dict,
optimal_dict: dict,
decision_label: str,
n_simulations: int,
) -> tuple[list, list]
Simulate a random agent's performance over the given chunk of data.
Parameters:
-
chunk(DataFrame) –DataFrame chunk representing an epoch of navigation data.
-
valid_dict(dict) –Dictionary mapping current grid numbers to valid next grid numbers.
-
optimal_dict(dict) –Dictionary mapping current grid numbers to optimal next grid numbers.
-
decision_label(str) –Label for decision nodes.
-
n_simulations(int) –Number of simulations to run for estimating performance.
Returns:
-
tuple[list, list]–A tuple containing two lists: - actual: List of actual performance (1 for optimal transition, 0 otherwise). - random_perf: List of average performance from random agent simulations.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
simulate_binary_agent_multi
¶
simulate_binary_agent_multi(
chunk: DataFrame,
valid_dict: dict,
optimal_dict: dict,
decision_label: str,
n_simulations: int,
) -> list
Simulate a binary agent's performance over the given chunk of data.
Parameters:
-
chunk(DataFrame) –DataFrame chunk representing an epoch of navigation data.
-
valid_dict(dict) –Dictionary mapping current grid numbers to valid next grid numbers.
-
optimal_dict(dict) –Dictionary mapping current grid numbers to optimal next grid numbers.
-
decision_label(str) –Label for decision nodes.
-
n_simulations(int) –Number of simulations to run for estimating performance.
Returns:
-
list–A list containing the average performance of the binary agent simulations.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
simulate_multiway_agent_multi
¶
simulate_multiway_agent_multi(
chunk: DataFrame,
decision_label: str,
three_nodes: list,
four_nodes: list,
n_simulations: int,
) -> list
Simulate a multiway agent's performance over the given chunk of data.
Parameters:
-
chunk(DataFrame) –DataFrame chunk representing an epoch of navigation data.
-
decision_label(str) –Label for decision nodes.
-
three_nodes(list) –List of grid numbers for three-way decision nodes.
-
four_nodes(list) –List of grid numbers for four-way decision nodes.
-
n_simulations(int) –Number of simulations to run for estimating performance.
Returns:
-
list–A list containing the average performance of the multiway agent simulations.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
bootstrap_means_multi
¶
evaluate_epoch_multi
¶
evaluate_epoch_multi(
chunk: DataFrame,
valid_dict: dict,
optimal_dict: dict,
decision_label: str,
three_nodes: list,
four_nodes: list,
n_bootstrap: int,
n_simulations: int,
) -> pd.Series
Evaluate performance metrics for all agent types over a given epoch chunk.
Parameters:
-
chunk(DataFrame) –DataFrame chunk representing an epoch of navigation data.
-
valid_dict(dict) –Dictionary mapping current grid numbers to valid next grid numbers.
-
optimal_dict(dict) –Dictionary mapping current grid numbers to optimal next grid numbers.
-
decision_label(str) –Label for decision nodes.
-
three_nodes(list) –List of grid numbers for three-way decision nodes.
-
four_nodes(list) –List of grid numbers for four-way decision nodes.
-
n_bootstrap(int) –Number of bootstrap samples for confidence intervals.
-
n_simulations(int) –Number of simulations for agent performance.
Returns:
-
Series–Series containing performance metrics for the epoch.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
evaluate_agent_performance_multi
¶
evaluate_agent_performance_multi(
df: DataFrame,
epoch_size: int,
n_bootstrap: int,
n_simulations: int,
decision_label: str = "Decision (Reward)",
reward_label: str = "reward_path",
trim: bool = True,
three_nodes: list | None = None,
four_nodes: list | None = None,
) -> pd.DataFrame
Evaluate the performance of different agent types over multiple epochs.
Parameters:
-
df(DataFrame) –DataFrame containing navigation data.
-
epoch_size(int) –Number of steps per epoch.
-
n_bootstrap(int) –Number of bootstrap samples for confidence intervals.
-
n_simulations(int) –Number of simulations for agent performance.
-
decision_label(str, default:'Decision (Reward)') –Label for decision nodes.
-
reward_label(str, default:'reward_path') –Label for reward path regions.
-
trim(bool, default:True) –Whether to trim results to common epochs across sessions.
-
three_nodes(list, default:None) –List of grid numbers for three-way decision nodes.
-
four_nodes(list, default:None) –List of grid numbers for four-way decision nodes.
Returns:
-
DataFrame–DataFrame with performance metrics for each epoch.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
plot_agent_vs_mouse_performance_multi
¶
plot_agent_vs_mouse_performance_multi(
config: dict,
df_metrics: DataFrame,
cohort_metadata: DataFrame,
genotype: str,
figsize: tuple = (12, 6),
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plot actual vs. simulated agent reward path performance across epochs for a specified genotype.
Parameters:
-
config(dict) –Configuration dictionary containing project settings.
-
df_metrics(DataFrame) –Output from evaluate_agent_performance_multi().
-
cohort_metadata(DataFrame) –Metadata mapping sessions to genotypes.
-
genotype(str) –Genotype to filter (e.g., 'WT-WT').
-
figsize(tuple, default:(12, 6)) –Size of the plot.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | |
plot_cumulative_agent_comparison_boxplot_multi
¶
plot_cumulative_agent_comparison_boxplot_multi(
config: dict,
df_metrics: DataFrame,
cohort_metadata: DataFrame,
genotype: str,
figsize: tuple = (10, 6),
save_fig: bool = True,
show_fig: bool = True,
return_fig: bool = False,
) -> None | plt.Figure
Plots a boxplot comparing the cumulative reward path transition percentage across all sessions for the specified genotype for mouse and simulated agents.
Parameters:
-
config(dict) –Configuration dictionary containing project settings.
-
df_metrics(DataFrame) –Output from evaluate_agent_performance_multi().
-
cohort_metadata(DataFrame) –Metadata mapping sessions to genotypes.
-
genotype(str) –Genotype to filter (e.g., 'WT-WT').
-
figsize(tuple, default:(10, 6)) –Size of the plot.
-
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 or None–The figure object if return_fig is True, otherwise None.
Source code in src/compass_labyrinth/behavior/behavior_metrics/simulation_modeling/multi_agent.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | |