def test_target_number_less_than_alp(self): """Test when requested number of targets is less than the length of the alphabet.""" alp = list(range(10)) targets = generate_targets(alp, 5) self.assertEqual(len(targets), 5) self.assertEqual(len(targets), len(set(targets)))
def test_remainder(self): """Test behavior when number of targets is greater than the length of the alphabet by a value other than a multiple of the alphabet length. """ alp = list(range(5)) targets = generate_targets(alp, 12) counts = Counter(targets) for item in alp: self.assertGreaterEqual(counts[item], 2) self.assertLessEqual(counts[item], 3)
def test_target_greater_than_alp(self): """Test behavior when number of targets is greater than the length of the alphabet""" alp = list(range(5)) targets = generate_targets(alp, 10) self.assertEqual(len(targets), 10) counts = Counter(targets) for item in alp: self.assertEqual(counts[item], 2)
def execute(self): """Execute the task""" self.logger.debug('Starting Icon to Icon Task!') icons = generate_targets(self.alp, self.stim_number) self.logger.debug('Icon sequence: %s', icons) selections = [] copy_phrase_task = self.init_copy_phrase_task(task_list=[(icons, [])]) epoch = EpochManager(icons, copy_phrase_task, self.timing[0]) correct_trials = 0 data = self.init_session_data(save=True) run = self.await_start() epoch.next() while run and self.user_wants_to_continue(): sequence_timing = self.present_sequence( epoch.current_sequence, epoch.current_durations, show_target=epoch.first_sequence) # Write triggers to file write_triggers_from_sequence_icon_to_icon( sequence_timing, self.trigger_file, epoch.target, target_displayed=epoch.first_sequence) core.wait(self.buffer_val) # Delete calibration if epoch.first_stimulus: del sequence_timing[0] # Delete the target presentation if epoch.first_sequence: del sequence_timing[0] # Reshape the data and triggers as needed for analysis. raw_data, triggers, target_info = process_data_for_decision( sequence_timing, self.daq, self.window, self.parameters, self.rsvp.first_stim_time) # Data Record for session.json entry = { 'stimuli': epoch.stimuli, 'eeg_len': len(raw_data), 'timing_sti': epoch.timing_sti, 'triggers': triggers, 'target_info': target_info, 'target_letter': epoch.target } if self.fake: new_epoch = True correct_trials += 1 selections.append(epoch.target) self.display_feedback(selection=epoch.target, correct=True) else: # Evaluate the data and make a decision. decision_made, new_sti = copy_phrase_task.evaluate_sequence( raw_data, triggers, target_info, self.collection_window_len) new_epoch = decision_made # Add the evidence to the data record. ev_hist = copy_phrase_task.conjugator.evidence_history likelihood = copy_phrase_task.conjugator.likelihood entry['lm_evidence'] = ev_hist['LM'][0].tolist() entry['eeg_evidence'] = ev_hist['ERP'][-1].tolist() entry['likelihood'] = likelihood.tolist() if decision_made: selection = copy_phrase_task.decision_maker.last_selection selections.append(selection) correct = selection == epoch.target if correct: correct_trials += 1 self.display_feedback(selection, correct) epoch.add_stim_data(entry) self.update_session_data(data, epoch, save=True) if new_epoch: epoch.next() else: epoch.next_stimulus(new_sti) run = self.stoppage_criteria_ok(epoch.seq_counter, data['total_time_spent']) # end while loop self.write_data(correct_trials, len(selections)) self.exit_display() return self.file_save