def run(self, agent): """Builds and runs the test agent and task""" vision = agent.vision audition = agent.audition typing = agent.typing instruction = agent.instruction typed = [] def type_handler(key): typed.append(key) typing.add_type_fn(type_handler) # add a visual stimulus "a" and a pointer pointing to it vision.add(Visual(50, 50, 20, 20, 'text'), 'a') pointer = Visual(50, 50, 1, 1, 'pointer') vision.add(pointer, 'pointer') # create the ACE instruction text ace_instructions = [ 'to perform-task', 'Psychomotor-Vigilance has a box and a target that is a letter.', 'Acknowledge is a button.', 'If Psychomotor-Vigilance is active then a letter appears in the box of Psychomotor-Vigilance.', 'If the target of Psychomotor-Vigilance appears in the box of Psychomotor-Vigilance then the subject remembers the letter and clicks Acknowledge.', # ['read letter', (50, 50)], 'done' ] # start a thread that presents the instructions via speech every 3 # seconds def stimulus_thread(): for line in ace_instructions: agent.wait(3.0) if isinstance(line, str): # if it's just a string, create a speech stimulus audition.add(Aural(isa='speech'), line) else: # if it's a string + pointer location, # move the pointer there and create a speech stimulus audition.add(Aural(isa='speech'), line[0]) loc = line[1] pointer.move(loc[0], loc[1]) agent.run(stimulus_thread) # on the main thread, start the instruction-following process goal = instruction.listen_and_learn() instruction.execute(goal) # wait for all processes to finish (both the stimuli and the agent) agent.wait_for_all() print(typed)
def fn(): for i in range(PairedAssociatesTest.N_BLOCKS): self.block_index = i pairs = PairedAssociatesTest.PAIRS.copy() random.shuffle(pairs) for pair in pairs: self.trial_start = agent.time() vision.clear().add(Visual(50, 50, 20, 20, 'word'), pair[0]) agent.wait(5.0) vision.clear().add( Visual(50, 50, 20, 20, 'digit'), pair[1]) agent.wait(5.0)
def add_visuals(self, sentence, vision): spc = 16 x = 50 y = 50 h = spc for word in sentence.words: w = spc * len(word.string) visual = Visual(x + w / 2, y + h / 2, w, h, 'word') visual.freq = word.freq visual.set('data', word) vision.add(visual, word.string) x += w + spc
def fn(): vision.clear() agent.wait(1.0) self.button = Visual(random.randint(0, 500), random.randint(0, 500), 30, 30, 'button') vision.add(self.button, "X")
def run(self, time=10): def handle_key(key): self.vision.clear() self.record('response') self.typing.add_type_fn(handle_key) for line in self.instructions: self.wait(5.0) if isinstance(line, str): self.audition.add(Aural(isa='speech'), line) else: self.audition.add(Aural(isa='speech'), line[0]) # loc = line[1] # pointer.move(loc[0], loc[1]) while self.time() < time: self.wait(10) # allow for index self.n_targets for target not present target_index = random.randint(0, self.n_targets) for i in range(self.n_targets): isa = 'vertical-line' if i == target_index else 'distractor' string = '|' if i == target_index else '-' self.vision.add( Visual(random.randint(10, 90), random.randint(10, 90), 20, 20, isa), string) self.record('stimulus')
def test_vision(self, output=False): agent = Agent(output=output) eyes = Eyes(agent) vision = Vision(agent, eyes) eyes.move_to(100, 100) vision.add(Visual(50, 50, 20, 20, 'text'), "Hello") vision.add(Visual(150, 150, 20, 20, 'text'), "Goodbye") self.assertEqual("Hello", vision.find_and_encode( Query(isa='text').lt('x', 100))) self.assertEqual("Goodbye", vision.find_and_encode(seen=False)) vision.start_wait_for(isa='cross') agent.wait(2.0) vision.add(Visual(200, 200, 20, 20, 'cross'), "cross") self.assertEqual("cross", vision.encode(vision.get_found())) self.assertAlmostEqual(2.7, agent.time(), 1) agent.wait_for_all()
def run(self, agent): vision = agent.vision audition = agent.audition typing = agent.typing instruction = agent.instruction typed = [] def type_handler(key): typed.append(key) typing.add_type_fn(type_handler) vision.add(Visual(50, 50, 20, 20, 'text'), 'a') pointer = Visual(50, 50, 1, 1, 'pointer') vision.add(pointer, 'pointer') speech = [ 'to type', ['read letter', (50, 50)], 'type letter', 'done' ] def stimulus_thread(): for line in speech: agent.wait(3.0) if isinstance(line, str): audition.add(Aural(isa='speech'), line) else: audition.add(Aural(isa='speech'), line[0]) loc = line[1] pointer.move(loc[0], loc[1]) agent.run_thread(stimulus_thread) goal = instruction.listen_and_learn() instruction.execute(goal) agent.wait_for_all() print(typed)
def run(self, time=10): """Builds and runs the test agent and task""" def handle_key(key): self.vision.clear() self.record('response') self.typing.add_type_fn(handle_key) for line in self.instructions: self.wait(5.0) if isinstance(line, str): self.audition.add(Aural(isa='speech'), line) else: self.audition.add(Aural(isa='speech'), line[0]) # loc = line[1] # pointer.move(loc[0], loc[1]) while self.time() < time: self.wait(random.randint(2.0, 10.0)) stimulus = Visual(50, 50, 20, 20, 'Letter') self.vision.add(stimulus, 'A') self.record('stimulus')