From 7f4ab99cb2d9b7870cd283c88ea4490a49e41606 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 8 Sep 2026 10:31:20 -0700 Subject: [PATCH 1/2] fixes bias calculation if no choices on one side --- .../task_logic/utils/calculate_bias.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aind_behavior_dynamic_foraging/task_logic/utils/calculate_bias.py b/src/aind_behavior_dynamic_foraging/task_logic/utils/calculate_bias.py index 3442641..32965c1 100644 --- a/src/aind_behavior_dynamic_foraging/task_logic/utils/calculate_bias.py +++ b/src/aind_behavior_dynamic_foraging/task_logic/utils/calculate_bias.py @@ -67,12 +67,12 @@ def calculate_bias(outcomes: List[TrialOutcome]) -> float: logger.warning("No choices in the last %d trials. Returning bias of 0.", trial_window_length) return 0 if n_right_choice == 0: - logger.warning("No right choices in the last %d trials. Returning bias of -1.", trial_window_length) - return -1 + logger.warning("No right choices in the last %d trials. Returning bias of +1.", trial_window_length) + return 1 if n_left_choice == 0: - logger.warning("No left choices in the last %d trials. Returning bias of +1.", trial_window_length) - return 1 + logger.warning("No left choices in the last %d trials. Returning bias of -1.", trial_window_length) + return -1 logistic_reg = LogisticRegression(solver=solver, l1_ratio=l1_ratio, C=1 / regularization_strength) logistic_reg.fit(x, y) From 14d17139c38db590a69fb725cac27e7a23862dd6 Mon Sep 17 00:00:00 2001 From: Micah Woodard Date: Tue, 8 Sep 2026 10:57:08 -0700 Subject: [PATCH 2/2] fixes tests --- tests/trial_generators/test_calculate_bias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/trial_generators/test_calculate_bias.py b/tests/trial_generators/test_calculate_bias.py index 528a834..1cf6ca2 100644 --- a/tests/trial_generators/test_calculate_bias.py +++ b/tests/trial_generators/test_calculate_bias.py @@ -42,7 +42,7 @@ def test_uniform_choices_returns_nan(self): """All same choice and reward should return nan since bias is undefined.""" outcomes = make_outcomes(100, 1, 1) bias = calculate_bias(outcomes) - self.assertTrue(bias == 1) + self.assertTrue(bias == -1) def test_ignored_trials_excluded(self): """Adding ignored trials should not change the result."""