Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions schema/coupled_baiting.json
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down Expand Up @@ -703,7 +703,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down
4 changes: 2 additions & 2 deletions schema/uncoupled.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down Expand Up @@ -665,7 +665,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down
4 changes: 2 additions & 2 deletions schema/uncoupled_baiting.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down Expand Up @@ -665,7 +665,7 @@
"upper": 0.5,
"lower": 0.0
},
"intervention_interval": 10,
"intervention_interval": 20,
"maximum_water_corrections": 2,
"bias_window_length": 200,
"lickspout_offset_delta": 0.05,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ def update(self, outcome: TrialOutcome | str):
# trial ignored so current baiting state retained
pass

self.bias = calculate_bias(outcomes=self.outcome_history)
self.bias = calculate_bias(
outcomes=self.outcome_history,
outcome_window_length=(
200
if not self.spec.bias_intervention_parameters
else self.spec.bias_intervention_parameters.bias_window_length
),
)

def next(self) -> Trial | None:
"""Generates the next trial in the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
logger = logging.getLogger(__name__)


def calculate_bias(outcomes: List[TrialOutcome]) -> float:
def calculate_bias(outcomes: List[TrialOutcome], outcome_window_length: int = 200) -> float:
"""Estimate the side bias of an animal using logistic regression on recent trial history.

Fits a Su2022-style logistic regression model using rewarded and unrewarded choice
Expand All @@ -20,7 +20,9 @@ def calculate_bias(outcomes: List[TrialOutcome]) -> float:
----------
outcomes : List[TrialOutcome]
List of trial outcomes. Auto-response and ignored trials are excluded.
Only the most recent 200 trials are used.
Only the most recent `outcome_window_length` trials are used.
outcome_window_length : int
Number of recent trials to consider for bias calculation.

Returns
-------
Expand All @@ -34,7 +36,7 @@ def calculate_bias(outcomes: List[TrialOutcome]) -> float:
trial_window_length = 5
regularization_strength = 10

outcomes = outcomes[-200:]
outcomes = outcomes[-outcome_window_length:]

# exclude auto response and ignored trials
filtered = [t for t in outcomes if t.is_right_choice is not None]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def make_s_stage_final():
autowater_parameters=None,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand Down Expand Up @@ -387,7 +387,7 @@ def make_s_stage_graduated():
autowater_parameters=None,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def make_s_stage_final():
reward_consumption_duration=3.0,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand All @@ -357,7 +357,7 @@ def make_s_stage_graduated():
autowater_parameters=None,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def make_s_stage_final():
autowater_parameters=None,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand Down Expand Up @@ -377,7 +377,7 @@ def make_s_stage_graduated():
autowater_parameters=None,
bias_intervention_parameters=BiasInterventionParameters(
threshold=BiasThreshold(upper=0.5, lower=0.0),
intervention_interval=10,
intervention_interval=20,
maximum_water_corrections=2,
bias_window_length=200,
lickspout_offset_delta=0.05,
Expand Down