Пример #1
0
    def _new_trial(self):
        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------
        dur = {'tmax': self.tmax}
        dur['fixation'] = (0, self.fixation)
        dur['sample'] = (dur['fixation'][1], dur['fixation'][1] + self.sample)
        dur['delay'] = (dur['sample'][1], dur['sample'][1] + self.delay)
        dur['test'] = (dur['delay'][1], dur['delay'][1] + self.test)
        dur['decision'] = (dur['test'][1], dur['test'][1] + self.decision)
        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------

        # TODO: may need to fix this
        gt = tasktools.choice(self.rng, [-1, 1])
        sample = tasktools.choice(self.rng, [0, 1])
        if gt == 1:
            test = sample
        else:
            test = 1 * (not sample)

        return {
            'durations': dur,
            'ground_truth': gt,
            'sample': sample,
            'test': test,
        }
Пример #2
0
    def _new_trial(self):
        # -------------------------------------------------------------------------
        # Epochs
        # --------------------------------------------------------------------------

        delay = tasktools.uniform(self.rng, self.dt, self.delay_min,
                                  self.delay_max)
        self.tmax = self.fixation + self.f1 + delay + self.f2 + self.decision
        durations = {
            'fixation': (0, self.fixation),
            'f1': (self.fixation, self.fixation + self.f1),
            'delay':
            (self.fixation + self.f1, self.fixation + self.f1 + delay),
            'f2': (self.fixation + self.f1 + delay,
                   self.fixation + self.f1 + delay + self.f2),
            'decision': (self.fixation + self.f1 + delay + self.f2, self.tmax),
        }

        ground_truth = tasktools.choice(self.rng, self.choices)
        fpair = tasktools.choice(self.rng, self.fpairs)
        if ground_truth == -1:
            f1, f2 = fpair
        else:
            f2, f1 = fpair
        return {
            'durations': durations,
            'ground_truth': ground_truth,
            'f1': f1,
            'f2': f2
        }
Пример #3
0
    def _new_trial(self):
        # ---------------------------------------------------------------------
        # Wager or no wager?
        # ---------------------------------------------------------------------

        wager = tasktools.choice(self.rng, self.wagers)

        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------

        stimulus = self.stimulus_min +\
            tasktools.truncated_exponential(self.rng, self.dt,
                                            self.stimulus_mean,
                                            xmax=self.stimulus_max)

        delay = tasktools.truncated_exponential(self.rng,
                                                self.dt,
                                                self.delay_mean,
                                                xmin=self.delay_min,
                                                xmax=self.delay_max)
        # maximum duration of current trial
        self.tmax = self.fixation + stimulus + delay + self.decision
        if wager:
            sure_onset =\
                tasktools.truncated_exponential(self.rng, self.dt,
                                                self.sure_mean,
                                                xmin=self.sure_min,
                                                xmax=self.sure_max)

        durations = {
            'fixation': (0, self.fixation),
            'stimulus': (self.fixation, self.fixation + stimulus),
            'delay':
            (self.fixation + stimulus, self.fixation + stimulus + delay),
            'decision': (self.fixation + stimulus + delay, self.tmax),
        }
        if wager:
            durations['sure'] = (self.fixation + stimulus + sure_onset,
                                 self.tmax)

        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------

        ground_truth = tasktools.choice(self.rng, self.choices)

        coh = tasktools.choice(self.rng, self.cohs)

        return {
            'durations': durations,
            'wager': wager,
            'ground_truth': ground_truth,
            'coh': coh
        }
Пример #4
0
    def _new_trial(self):
        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------
        measure = tasktools.choice(self.rng, self.measures)
        production = measure * self.gain
        self.tmax = self.fixation + measure + self.set + 2 * production

        durations = {
            'fixation': (0, self.fixation),
            'ready': (self.fixation, self.fixation + self.ready),
            'measure': (self.fixation, self.fixation + measure),
            'set':
            (self.fixation + measure, self.fixation + measure + self.set),
            'production': (self.fixation + measure + self.set, self.tmax),
        }

        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------
        return {
            'durations': durations,
            'measure': measure,
            'production': production,
        }
Пример #5
0
    def _new_trial(self):
        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------

        stimulus = tasktools.truncated_exponential(self.rng,
                                                   self.dt,
                                                   self.stimulus_mean,
                                                   xmin=self.stimulus_min,
                                                   xmax=self.stimulus_max)
        # maximum duration of current trial
        self.tmax = self.fixation + stimulus + self.resp_delay + self.decision
        durations = {
            'fixation': (0, self.fixation),
            'stimulus': (self.fixation, self.fixation + stimulus),
            'resp_delay': (self.fixation + stimulus,
                           self.fixation + stimulus + self.resp_delay),
            'decision':
            (self.fixation + stimulus + self.resp_delay, self.tmax),
        }

        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------
        ground_truth = tasktools.choice(self.rng, self.choices)

        return {
            'durations': durations,
            'ground_truth': ground_truth,
        }
Пример #6
0
    def _new_trial(self):
        # -----------------------------------------------------------------------
        # Epochs
        # -----------------------------------------------------------------------

        delay = self.delay_min +\
            tasktools.truncated_exponential(self.rng, self.dt, self.delay_mean,
                                            xmax=self.delay_max)
        # maximum duration of current trial
        self.tmax = self.fixation + self.stimulus + delay + self.decision
        durations = {
            'fixation': (0, self.fixation),
            'stimulus': (self.fixation, self.fixation + self.stimulus),
            'delay': (self.fixation + self.stimulus,
                      self.fixation + self.stimulus + delay),
            'decision': (self.fixation + self.stimulus + delay, self.tmax),
        }

        # -------------------------------------------------------------------------
        # Trial
        # -------------------------------------------------------------------------

        context_ = tasktools.choice(self.rng, self.contexts)

        left_right_m = tasktools.choice(self.rng, self.choices)

        left_right_c = tasktools.choice(self.rng, self.choices)

        coh_m = tasktools.choice(self.rng, self.cohs)

        coh_c = tasktools.choice(self.rng, self.cohs)

        if context_ == 'm':
            ground_truth = 2 * (left_right_m > 0) - 1
        else:
            ground_truth = 2 * (left_right_c > 0) - 1

        return {
            'durations': durations,
            'context': context_,
            'left_right_m': left_right_m,
            'left_right_c': left_right_c,
            'coh_m': coh_m,
            'coh_c': coh_c,
            'ground_truth': ground_truth
        }
Пример #7
0
 def __init__(self, env, prob=(.2, .8), block_dur=200):
     Wrapper.__init__(self, env=env)
     self.env = env
     self.prob = prob
     # keeps track of the repeating prob of the current block
     self.curr_block = tasktools.choice(self.env.rng, [0, 1])
     # duration of block (in number oif trials)
     self.block_dur = block_dur
     self.prev_trial = self.env.trial['ground_truth']
Пример #8
0
    def _new_trial(self):
        """
        _new_trial() is called when a trial ends to get the specifications of
        the next trial. Such specifications are stored in a dictionary with
        the following items:
            durations, which stores the duration of the different periods (in
            the case of rdm: fixation, stimulus and decision periods)
            ground truth: correct response for the trial
            coh: stimulus coherence (evidence) for the trial

        """
        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------
        stimulus = tasktools.truncated_exponential(self.rng,
                                                   self.dt,
                                                   self.stimulus_mean,
                                                   xmin=self.stimulus_min,
                                                   xmax=self.stimulus_max)
        # maximum length of current trial
        self.tmax = self.fixation + stimulus + self.decision
        durations = {
            'fixation': (0, self.fixation),
            'stimulus': (self.fixation, self.fixation + stimulus),
            'decision': (self.fixation + stimulus,
                         self.fixation + stimulus + self.decision),
        }

        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------
        ground_truth = tasktools.choice(self.rng, self.choices)
        coh = tasktools.choice(self.rng, self.cohs)

        return {
            'durations': durations,
            'ground_truth': ground_truth,
            'coh': coh
        }
Пример #9
0
    def _new_trial(self):
        # ---------------------------------------------------------------------
        # Epochs
        # ---------------------------------------------------------------------

        offer_on = tasktools.uniform(self.rng, self.dt, self.offer_on_min,
                                     self.offer_on_max)
        # maximum duration of current trial
        self.tmax = self.fixation + offer_on + self.decision
        durations = {
            'fixation': (0, self.fixation),
            'offer-on': (self.fixation, self.fixation + offer_on),
            'decision': (self.fixation + offer_on, self.tmax),
        }

        # ---------------------------------------------------------------------
        # Trial
        # ---------------------------------------------------------------------

        juice = tasktools.choice(self.rng, self.juices)

        offer = tasktools.choice(self.rng, self.offers)

        juiceL, juiceR = juice
        nB, nA = offer

        if juiceL == 'A':
            nL, nR = nA, nB
        else:
            nL, nR = nB, nA

        return {
            'durations': durations,
            'juice': juice,
            'offer': offer,
            'nL': nL,
            'nR': nR
        }
Пример #10
0
 def __init__(self,
              env,
              rep_prob=(.2, .8),
              block_dur=200,
              blk_ch_prob=None):
     Wrapper.__init__(self, env=env)
     self.env = env
     # we get the original task, in case we are composing wrappers
     env_aux = env
     while env_aux.__class__.__module__.find('wrapper') != -1:
         env_aux = env.env
     self.task = env_aux
     self.rep_prob = rep_prob
     # keeps track of the repeating prob of the current block
     self.curr_block = tasktools.choice(self.task.rng, [0, 1])
     # duration of block (in number oif trials)
     self.block_dur = block_dur
     self.prev_trial = self.task.trial['ground_truth']
     self.blk_ch_prob = blk_ch_prob
Пример #11
0
    def _new_trial(self):
        # -------------------------------------------------------------------------
        # Epochs
        # --------------------------------------------------------------------------

        delay = tasktools.uniform(self.rng, self.dt, self.delay_min,
                                  self.delay_max)
        # maximum duration of current trial
        self.tmax = self.fixation + self.dpa1 + delay + self.dpa2 +\
            self.resp_delay + self.decision

        durations = {
            'fixation':   (0, self.fixation),
            'dpa1':         (self.fixation, self.fixation + self.dpa1),
            'delay':      (self.fixation + self.dpa1,
                           self.fixation + self.dpa1 + delay),
            'dpa2':         (self.fixation + self.dpa1 + delay,
                             self.fixation + self.dpa1 + delay + self.dpa2),
            'resp_delay': (self.fixation + self.dpa1 + delay + self.dpa2,
                           self.fixation + self.dpa1 + delay + self.dpa2 +
                           self.resp_delay),
            'decision':   (self.fixation + self.dpa1 + delay + self.dpa2 +
                           self.resp_delay, self.tmax),
            }

        pair = tasktools.choice(self.rng, self.dpa_pairs)

        if np.diff(pair)[0] == 2:
            ground_truth = 1
        else:
            ground_truth = -1

        return {
            'durations': durations,
            'ground_truth':     ground_truth,
            'pair':     pair
            }
Пример #12
0
 def seed(self, seed=None):
     self.task.seed(seed=seed)
     # keeps track of the repeating prob of the current block
     self.curr_block = tasktools.choice(self.task.rng, [0, 1])