Skip to content

Commit b3fba12

Browse files
authored
Merge branch 'int-brain-lab:main' into main
2 parents 17d55eb + 6f69408 commit b3fba12

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

iblrig_custom_tasks/nate_adaptiveTimeoutChoiceWorld/__init__.py

Whitespace-only changes.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
"""
2+
This task inherits TrainingChoiceWorldSession with the addition of configurable, adaptive timeouts for incorrect
3+
choices depending on the stimulus contrast.
4+
"""
5+
6+
import logging
7+
from pathlib import Path
8+
from typing import Any
9+
10+
import numpy as np
11+
import yaml
12+
from pydantic import NonNegativeFloat
13+
14+
from iblrig.misc import get_task_arguments
15+
from iblrig_tasks._iblrig_tasks_trainingChoiceWorld.task import Session as TrainingCWSession
16+
17+
log = logging.getLogger('iblrig.task')
18+
19+
20+
# read defaults from task_parameters.yaml
21+
with open(Path(__file__).parent.joinpath('task_parameters.yaml')) as f:
22+
DEFAULTS = yaml.safe_load(f)
23+
24+
25+
class AdaptiveTimeoutChoiceWorldTrialData(TrainingCWSession.TrialDataModel):
26+
adaptive_delay_nogo: NonNegativeFloat
27+
adaptive_delay_error: NonNegativeFloat
28+
29+
30+
class Session(TrainingCWSession):
31+
protocol_name = 'nate_adaptiveTimeoutChoiceWorld'
32+
TrialDataModel = AdaptiveTimeoutChoiceWorldTrialData
33+
34+
def __init__(
35+
self,
36+
*args,
37+
adaptive_delay_nogo=DEFAULTS['ADAPTIVE_FEEDBACK_NOGO_DELAY_SECS'],
38+
adaptive_delay_error=DEFAULTS['ADAPTIVE_FEEDBACK_ERROR_DELAY_SECS'],
39+
**kwargs,
40+
):
41+
self._adaptive_delay_nogo = adaptive_delay_nogo
42+
self._adaptive_delay_error = adaptive_delay_error
43+
super().__init__(*args, **kwargs)
44+
assert len(self._adaptive_delay_nogo) == len(self.task_params.CONTRAST_SET)
45+
assert len(self._adaptive_delay_error) == len(self.task_params.CONTRAST_SET)
46+
47+
def draw_next_trial_info(self, **kwargs):
48+
super().draw_next_trial_info(**kwargs)
49+
contrast = self.trials_table.at[self.trial_num, 'contrast']
50+
index = np.flatnonzero(np.array(self.task_params['CONTRAST_SET']) == contrast)[0]
51+
self.trials_table.at[self.trial_num, 'adaptive_delay_nogo'] = self._adaptive_delay_nogo[index]
52+
self.trials_table.at[self.trial_num, 'adaptive_delay_error'] = self._adaptive_delay_error[index]
53+
54+
@property
55+
def feedback_nogo_delay(self):
56+
return self.trials_table.at[self.trial_num, 'adaptive_delay_nogo']
57+
58+
@property
59+
def feedback_error_delay(self):
60+
return self.trials_table.at[self.trial_num, 'adaptive_delay_error']
61+
62+
def show_trial_log(self, extra_info: dict[str, Any] | None = None, log_level: int = logging.INFO):
63+
trial_info = self.trials_table.iloc[self.trial_num]
64+
info_dict = {
65+
'Adaptive no-go delay': f'{trial_info.adaptive_delay_nogo:.2f} s',
66+
'Adaptive error delay': f'{trial_info.adaptive_delay_error:.2f} s',
67+
}
68+
if isinstance(extra_info, dict):
69+
info_dict.update(extra_info)
70+
super().show_trial_log(extra_info=info_dict, log_level=log_level)
71+
72+
@staticmethod
73+
def extra_parser():
74+
parser = super(Session, Session).extra_parser()
75+
parser.add_argument(
76+
'--adaptive_delay_nogo',
77+
option_strings=['--adaptive_delay_nogo'],
78+
dest='adaptive_delay_nogo',
79+
default=DEFAULTS['ADAPTIVE_FEEDBACK_NOGO_DELAY_SECS'],
80+
nargs='+',
81+
type=float,
82+
help='list of delays for no-go condition (contrasts: 1.0, 0.5, 0.25, 0.125, 0.0625, 0.0)',
83+
)
84+
parser.add_argument(
85+
'--adaptive_delay_error',
86+
option_strings=['--adaptive_delay_error'],
87+
dest='adaptive_delay_error',
88+
default=DEFAULTS['ADAPTIVE_FEEDBACK_ERROR_DELAY_SECS'],
89+
nargs='+',
90+
type=float,
91+
help='list of delays for error condition (contrasts: 1.0, 0.5, 0.25, 0.125, 0.0625, 0.0)',
92+
)
93+
return parser
94+
95+
96+
if __name__ == '__main__': # pragma: no cover
97+
kwargs = get_task_arguments(parents=[Session.extra_parser()])
98+
sess = Session(**kwargs)
99+
sess.run()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'ADAPTIVE_GAIN': True
2+
'ADAPTIVE_REWARD': True
3+
'AG_INIT_VALUE': 8.0 # Adaptive Gain init value. Once the mouse completes 200 response trials whithin a session, this reverts to STIM_GAIN
4+
'CONTRAST_SET_PROBABILITY_TYPE': skew_zero # uniform, skew_zero
5+
'DEBIAS': True # Whether to use debiasing rule or not by repeating error trials
6+
'REWARD_AMOUNT_UL': 3.0 # Reward amount (uL), will oscillate between 1.5 and 3 uL depending on previous sessions if adaptive_reward is True
7+
8+
'CONTRAST_SET': [1.0, 0.5, 0.25, 0.125, 0.0625, 0.0]
9+
'ADAPTIVE_FEEDBACK_NOGO_DELAY_SECS': [2.0, 2.0, 2.0, 2.0, 2.0, 2.0]
10+
'ADAPTIVE_FEEDBACK_ERROR_DELAY_SECS': [2.0, 2.0, 2.0, 2.0, 2.0, 2.0]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "project_extraction"
7-
version = "0.3.0"
7+
version = "0.4.0"
88
description = "Custom extractors for satellite tasks"
99
dynamic = [ "readme" ]
1010
keywords = [ "IBL", "neuro-science" ]

0 commit comments

Comments
 (0)