def test_mouse(self, output=False): agent = Agent(output=output) env = Environment() vision = Vision(agent, env.display) motor = Motor(agent, vision, env) self.button = None end = 20.0 def update(): if agent.time() < end: def fn(): vision.clear() agent.wait(1.0) self.button = env.display.add_button( random.randint(0, 500), random.randint(0, 500), 'X') agent.run_thread(fn) update() def fn(visual): if visual.obj == 'X': update() env.mouse.add_click_fn(fn) while agent.time() < end: visual = vision.wait_for(isa='button') motor.point_and_click(visual) agent.wait_for_all() self.assertGreaterEqual(agent.time(), end)
def test_mouse(self, output=False): agent = Agent(output=output) vision = Vision(agent) hands = Hands(agent) mouse = Mouse(hands, vision) self.button = None end = 20.0 def update(): if agent.time() < end: 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") agent.run_thread(fn) update() def fn(visual): if visual.equals(self.button): update() mouse.add_click_fn(fn) while agent.time() < end: visual = vision.wait_for(isa='button') mouse.point_and_click(visual) agent.wait_for_all() self.assertGreaterEqual(agent.time(), end)
def run_trial(self): agent = Agent(output=False) memory = Memory(agent, Memory.OPTIMIZED_DECAY) memory.decay_rate = .5 memory.activation_noise = .5 memory.retrieval_threshold = -1.8 memory.latency_factor = .450 vision = Vision(agent) typing = Typing(Hands(agent)) self.trial_start = 0 self.block_index = 0 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) agent.run_thread(fn) def type_fn(c): self.rt.add(self.block_index, agent.time() - self.trial_start) typing.add_type_fn(type_fn) for i in range(PairedAssociatesTest.N_BLOCKS): for _ in range(len(PairedAssociatesTest.PAIRS)): word = vision.encode(vision.wait_for(isa='word')) chunk = memory.recall(word=word) if chunk: typing.type(chunk.get('digit')) self.correct.add(i, 1) else: self.correct.add(i, 0) digit = vision.encode(vision.wait_for(isa='digit')) memory.store(word=word, digit=digit) agent.wait_for_all()
class VSAgent(Agent): def __init__(self, env): """Initializes the agent""" super().__init__(output=True) self.vision = Vision(self, env.display) #, eyes=Eyes(self)) self.motor = Motor(self, self.vision, env) def run(self, time): while self.time() < time: self.vision.wait_for(isa='letter', seen=False) visual = self.vision.search_for( Query(isa='letter', color='red', region='vs'), 'X') if visual: # self.log('target present') self.motor.type('w') self.wait(1.0) else: # self.log('target absent') self.motor.type('r') self.wait(1.0)
class PVTAgent(Agent): def __init__(self): """Initializes the agent""" super().__init__(output=True) self.vision = Vision(self) self.audition = Audition(self) self.typing = Typing(Hands(self)) def run(self, time=300): while self.time() < time: visual = self.vision.wait_for(seen=False) self.vision.start_encode(visual) self.typing.type('j') self.vision.get_encoded()
class PVTAgent(Agent): def __init__(self, env): """Initializes the agent""" super().__init__(output=True) self.vision = Vision(self, env.display) #, eyes=Eyes(self)) self.motor = Motor(self, self.vision, env) def run(self, time=60): while self.time() < time: visual = self.vision.wait_for(isa='letter', region='pvt', seen=False) self.vision.start_encode(visual) self.motor.type(' ') self.vision.get_encoded()
class SearchAgent(Agent): def __init__(self): super().__init__(output=True) self.vision = Vision(self) self.audition = Audition(self) self.typing = Typing(Hands(self)) def run(self, time=300): while self.time() < time: visual = self.vision.wait_for(seen=False) while (visual is not None and not visual.isa == 'vertical-line'): obj = self.vision.encode(visual) print('**** skip') visual = self.vision.find(seen=False) if visual: print('**** found') self.typing.type('j') self.vision.encode(visual) else: print('**** not found') self.typing.type('k')
class UndifferentiatedAgent(Agent): def __init__(self, env, output=True): super().__init__(output=output) #basic pass-ins for now for speed of testing self.memory = OntologyMemory(self,stopOldServer=False,owlFile='uagent.owl') self.vision = Vision(self, env.display) self.audition = Audition(self, env.speakers) self.motor = Motor(self, self.vision, env) self.interpreter = Interpreter(self.memory) self.language = Language(self) self.language.add_interpreter(lambda words: self.interpreter.interpret_ace(' '.join(words))) self.condition_handler = ConditionHandler(self) self.action_handler = ActionHandler(self) # #Not used at the moment. # self.item_role_list = ['target','stimulus','distractor','responseButton','infoButton'] # #"ItemRole" in the Ontology. # #For future implementations (trying to use other labs' instructions) # self.agent_synonym_list = ['subject','participant','you'] def is_action(self, rule): for action in rule.actions: if self.action_handler._has(action['name']): return True return False def check_condition(self, cond, context): handler = self.condition_handler._get(cond['name']) if handler: self.think('check condition "{}"'.format(cond)) return handler(cond, context) else: return True def execute_action(self, action, context): handler = self.action_handler._get(action['name']) if handler: self.think('execute action "{}"'.format(action)) handler(action, context) def process_rule(self, rule, context): if self.is_action(rule): self.think('process rule "{}"'.format(rule)) for cond in rule.conditions: if not self.check_condition(cond, context): return False for action in rule.actions: self.execute_action(action, context) return True def run(self, time=60): instr_visual = self.vision.wait_for(isa='text') instructions = self.vision.encode(instr_visual) self.language.interpret(instructions) while self.time() < time: context = Chunk() for rule in self.memory.recall_ground_rules(): self.process_rule(rule, context)