def go_on(self): yield {"=g": actr.makechunk("", "press", key="=k!b")} yield { "+manual": actr.makechunk("", "_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("", "press", key="c") }
def start(self): yield {"=g": actr.makechunk("", "press", key="=k!a")} yield { "+manual": actr.makechunk("", "_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("", "press", key="b") }
def __init__(self, **kwargs): actr.chunktype("goal", "arg1 arg2 arg3 arg4") actr.chunktype("fact", "arg1 arg2 arg3 arg4") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.dm.add(actr.makechunk("", "fact", arg1=3, arg2=3, arg3=5, arg4=1)) self.m.goal.add( actr.makechunk(nameofchunk="start", typename="goal", arg1=3)) self.m.productionstring(name="one", string=""" =g> isa goal arg1 =v1 arg2 =v2 arg2 ~5 arg3 =v2 arg4 =v3 ==> +retrieval> isa fact arg1 3 arg2 =v1 =g> isa goal arg1 =v2 arg2 =v3 arg3 =v1""") self.m.productionstring(name="two", string=""" =g> isa goal arg1 =v0 arg2 =v1 arg3 3 =retrieval> isa fact arg3 =v2 ==> ~retrieval> =g> isa goal arg2 =v2 arg3 =v1 arg4 =v0""") self.m.productionstring(name="three", string=""" =g> isa goal arg2 5 ?retrieval> buffer empty ==> =g> isa goal""")
def switch(self): yield { "=retrieval": actr.makechunk("", "twoVars", x="=num", y="=num2"), "=g": actr.makechunk("", "reverse", y="=num") } yield { "=retrieval": actr.makechunk("", "twoVars", x="=num2", y="=num") }
def still_go_on(self): yield { "=g": actr.makechunk("", "press", key="=k!c"), "?manual": { "state": "busy" } } yield {"=g": actr.makechunk("", "press", key="d")}
def finish(self): yield { "=g": actr.makechunk("", "press", key="=k!d"), "?manual": { "state": "free" } } yield {"=g": actr.makechunk("", "press", key="e")}
def __init__(self): self.model = actr.ACTRModel() self.model.chunktype("countOrder", ("first", "second")) dm = self.model.decmem for i in range(1, 6): dm.add(actr.makechunk("", "countOrder", first=i, second=i + 1)) self.model.chunktype("countFrom", ("start", "end", "count")) self.model.goal.add(actr.makechunk("", "countFrom", start=2, end=4)) self.model.productionstring(name="start", string=""" =g> isa countFrom start =x count None ?retrieval> state free ==> =g> isa countFrom count =x +retrieval> isa countOrder first =x""") self.model.productionstring(name="increment", string=""" =g> isa countFrom count =x end ~=x =retrieval> isa countOrder first =x second =y ==> =g> isa countFrom count =y +retrieval> isa countOrder first =y""") self.model.productionstring(name="stop", string=""" =g> isa countFrom count =x end =x ?retrieval> state free ==> ~g>""")
def __init__(self, **kwargs): actr.chunktype("goal", "arg1 arg2 arg3 arg4") actr.chunktype("fact", "arg1 arg2 arg3 arg4") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.dm.add(actr.makechunk("", "fact", arg1=3, arg2=3, arg3=5, arg4=1) ) self.m.goal.add(actr.makechunk(nameofchunk="start", typename="goal", arg1=3)) self.m.productionstring(name="one", string=""" =g> isa goal arg1 =v1 arg2 =v2 arg2 ~5 arg3 =v2 arg4 =v3 ==> +retrieval> isa fact arg1 3 arg2 =v1 =g> isa goal arg1 =v2 arg2 =v3 arg3 =v1""") self.m.productionstring(name="two", string=""" =g> isa goal arg1 =v0 arg2 =v1 arg3 3 =retrieval> isa fact arg3 =v2 ==> ~retrieval> =g> isa goal arg2 =v2 arg3 =v1 arg4 =v0""") self.m.productionstring(name="three", string=""" =g> isa goal arg2 5 ?retrieval> buffer empty ==> =g> isa goal""")
def __init__(self): self.model = actr.ACTRModel() self.model.chunktype("countOrder", ("first", "second")) dm = self.model.decmem for i in range(1, 6): dm.add(actr.makechunk("", "countOrder", first=i, second=i+1)) self.model.chunktype("countFrom", ("start", "end", "count")) self.model.goal.add(actr.makechunk("", "countFrom", start=2, end=4)) self.model.productionstring(name="start", string=""" =g> isa countFrom start =x count None ?retrieval> state free ==> =g> isa countFrom count =x +retrieval> isa countOrder first =x""") self.model.productionstring(name="increment", string=""" =g> isa countFrom count =x end ~=x =retrieval> isa countOrder first =x second =y ==> =g> isa countFrom count =y +retrieval> isa countOrder first =y""") self.model.productionstring(name="stop", string=""" =g> isa countFrom count =x end =x ?retrieval> state free ==> ~g>""")
def __init__(self, **kwargs): self.model = actr.ACTRModel(**kwargs) actr.chunktype("twoVars", ("x", "y")) actr.chunktype("reverse", ("x", "y")) self.dm = self.model.decmem self.dm.add(actr.makechunk("", "twoVars", x=10, y=20)) self.model.goal.add(actr.makechunk("", "reverse", x=10))
def finish(self): yield { "=g": actr.makechunk("", "press", key="=k!c"), "?manual": { "preparation": "free" } } yield { "+manual": actr.makechunk("", "_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("", "press", key="d") }
def __init__(self, **kwargs): self.model = actr.ACTRModel(**kwargs) actr.chunktype("twoVars", ("x", "y")) self.dm = self.model.decmem self.dm.add(actr.makechunk("", "twoVars", x=10, y=20)) self.model.goal.default_harvest = self.dm #default harvest is optional since only one harvest; but testing that it works actr.chunktype("reverse", ("x", "y")) self.model.goal.add(actr.makechunk("", "reverse", x=10))
def __init__(self, **kwargs): self.model = actr.ACTRModel(**kwargs) actr.chunktype("twoVars", ("x", "y")) self.dm = self.model.decmem self.dm.add(actr.makechunk("","twoVars", x=10, y=20)) self.model.goal.default_harvest = self.dm #default harvest is optional since only one harvest; but testing that it works actr.chunktype("reverse", ("x", "y")) self.model.goal.add(actr.makechunk("","reverse", x=10))
def __init__(self, **kwargs): actr.chunktype("goal", "arg1 arg2 arg3 arg4") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.m.goal.add(actr.makechunk(nameofchunk="start", typename="goal", arg1=1, arg2=None, arg4=10)) self.m.goal.default_harvest = self.dm self.m.productionstring(name="one", string=""" ?g> state free =g> isa goal arg1 1 ==> =g> isa goal arg1 2""") self.m.productionstring(name="two", string=""" ?g> buffer full =g> isa goal arg1 2 arg2 None arg3 None ==> =g> isa goal arg1 3""")
def __init__(self, **kwargs): actr.chunktype("goal", "arg1 arg2 arg3 arg4") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.m.goal.add(actr.makechunk(nameofchunk="start", typename="goal", arg1=3)) self.m.productionstring(name="one", string=""" =g> isa goal arg1 =v1 arg2 =v2 arg3 =v2 arg4 =v3 ==> =g> isa goal arg1 =v2 arg2 =v3 arg3 =v1""") self.m.productionstring(name="two", string=""" =g> isa goal arg1 =v0 arg2 =v1 arg3 3 ==> =g> isa goal arg3 =v1 arg4 =v0""")
def __init__(self, **kwargs): self.m = actr.ACTRModel(**kwargs) self.m.goal.add(actr.makechunk(typename="start", state="start")) self.m.productionstring(name="one", string=""" =g> isa start state 'start' ==> =g> isa change state 'change'""", utility=1) self.m.productionstring(name="two", string=""" =g> isa start state 'start' ==> =g> isa dontchange state 'start'""", utility=5) self.m.productionstring(name="three", string=""" =g> isa change state 'change' ==> ~g>""", reward=10)
def __init__(self, **kwargs): actr.chunktype("state", "starting ending") self.m = actr.ACTRModel(**kwargs) self.m.goal.add(actr.makechunk(nameofchunk="start", typename="state", starting=1)) self.m.productionstring(name="one", string=""" =g> isa state starting =x ending ~=x ==> =g> isa state ending =x""", utility=2) self.m.productionstring(name="two", string=""" =g> isa state starting =x ending =x ==> =g> isa state starting =x ending 4""")
def __init__(self, **kwargs): actr.chunktype("state", "starting ending") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.m.goal.add( actr.makechunk(nameofchunk="start", typename="state", starting=1, ending=1)) self.m.productionstring(name="one", string=""" =g> isa state starting =x ending =x ==> =g> isa state ending =x starting 4""") self.m.productionstring(name="two", string=""" =g> isa state starting =x ending ~=x ==> =g> isa state ending =x""")
def __init__(self, **kwargs): actr.chunktype("state", "starting ending") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.m.goal.add(actr.makechunk(nameofchunk="start", typename="state", starting=1, ending=2)) self.m.productionstring(name="one", string=""" =g> isa state starting 1 ending 2 ==> =g> isa state ending 1""", utility=10) self.m.productionstring(name="two", string=""" =g> isa state starting 1 ending 1 ==> =g> isa state ending 2""")
def __init__(self, **kwargs): actr.chunktype("state", "starting ending position") self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem self.m.goal.add(actr.makechunk(nameofchunk="start", typename="state", starting=1, ending=3, position='start')) self.m.goal.default_harvest = self.dm self.m.productionstring(name="one", string=""" =g> isa state starting =x ending ~=x position 'start' ==> +g> isa state starting None position 'end' ending =x""") self.m.productionstring(name="two", string=""" =g> isa state starting None position 'end' ==> =g> isa state position 'completeend'""")
def run_stimulus(word): """ Function running one instance of lexical decision for a word. """ # reset model state to initial state for a new simulation # (flush buffers without moving their contents to dec mem) try: lex_decision.retrieval.pop() except KeyError: pass try: lex_decision.goals["g"].pop() except KeyError: pass try: lex_decision.goals["imaginal"].pop() except KeyError: pass # reinitialize model stim = {1: {'text': word, 'position': (320, 180)}} lex_decision.goals["g"].add( actr.makechunk(nameofchunk='start', typename="goal", state='attend')) lex_decision.goals["imaginal"].add( actr.makechunk(nameofchunk='start', typename="word")) lex_decision.goals["imaginal"].delay = 0.2 environment.current_focus = [320, 180] lex_decision.model_parameters['motor_prepared'] = True # run new simulation; switch to gui=True to suppress pyactr output when estimating Bayesian model lex_dec_sim = lex_decision.simulation( realtime=False, gui=False, trace=False, environment_process=environment.environment_process, stimuli=stim, triggers='', times=10) while True: lex_dec_sim.step() if lex_dec_sim.current_event.action == "KEY PRESSED: J": estimated_time = lex_dec_sim.show_time() break if lex_dec_sim.current_event.action == "KEY PRESSED: F": estimated_time = -1 break return estimated_time
def __init__(self, **kwargs): self.m = actr.ACTRModel(**kwargs) self.dm = self.m.decmem actr.chunktype("phase", "state") self.m.goal.add(actr.makechunk("start", "phase", state="start"))
def run_stimulus(word): """ Function running one instance of lexical decision for a word. """ # reset model state to initial state for a new simulation # (flush buffers without moving their contents to dec mem) try: lex_decision.retrieval.pop() except KeyError: pass try: lex_decision.goals["g"].pop() except KeyError: pass try: lex_decision.goals["imaginal"].pop() except KeyError: pass # reinitialize model stim = {1: {'text': word, 'position': (320, 180)}} lex_decision.goals["g"].add(actr.makechunk(nameofchunk='start', typename="goal", state='attend')) lex_decision.goals["imaginal"].add(actr.makechunk(nameofchunk='start', typename="word")) lex_decision.goals["imaginal"].delay = 0.2 environment.current_focus = [320,180] lex_decision.model_parameters['motor_prepared'] = True # run new simulation lex_dec_sim = lex_decision.simulation(realtime=False, gui=False, trace=False, environment_process=environment.environment_process, stimuli=stim, triggers='', times=10) while True: lex_dec_sim.step() if lex_dec_sim.current_event.action == "KEY PRESSED: J": estimated_time = lex_dec_sim.show_time() break if lex_dec_sim.current_event.action == "KEY PRESSED: F": estimated_time = -1 break return estimated_time
def start(self): yield {"=g": actr.makechunk("","press", key="=k!a")} yield {"+manual": actr.makechunk("","_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("","press", key="b")}
def __init__(self, **kwargs): self.m = actr.ACTRModel(**kwargs) self.m.chunktype("press", "key") self.m.goal.add(actr.makechunk("","press", key="a"))
FREQ_DICT['seated'] = 3*112.5 FREQ_DICT['habitually'] = 1*112.5 ORDERED_FREQ = sorted(list(FREQ_DICT), key=lambda x:FREQ_DICT[x], reverse=True) def time_freq(freq): rehearsals = np.zeros((np.int(np.max(freq) * 113), len(freq))) for i in np.arange(len(freq)): temp = np.arange(np.int((freq[i]*112.5))) temp = temp * np.int(SEC_IN_TIME/(freq[i]*112.5)) rehearsals[:len(temp),i] = temp return(rehearsals.T) time = theano.shared(time_freq(FREQ), 'time') LEMMA_CHUNKS = [(actr.makechunk("", typename="word", form=word)) for word in ORDERED_FREQ] lex_decision.set_decmem({x: np.array([]) for x in LEMMA_CHUNKS}) lex_decision.goals = {} lex_decision.set_goal("g") lex_decision.productionstring(name="attend word", string=""" =g> isa goal state 'attend' =visual_location> isa _visuallocation ?visual> state free ==>
def __init__(self): self.model = actr.ACTRModel() self.model.chunktype("countOrder", ("first", "second")) self.model.chunktype("add", ("arg1", "arg2", "sum", "count")) dm = self.model.decmem for i in range(0, 11): dm.add( actr.makechunk("chunk" + str(i), "countOrder", first=i, second=i + 1)) self.model.goal.add(actr.makechunk("", "add", arg1=5, arg2=2)) self.model.productionstring(name="initAddition", string=""" =g> isa add arg1 =num1 arg2 =num2 sum None ==> =g> isa add sum =num1 count 0 +retrieval> isa countOrder first =num1""") self.model.productionstring(name="terminateAddition", string=""" =g> isa add count =num arg2 =num sum =answer ==> ~g>""") self.model.productionstring(name="incrementCount", string=""" =g> isa add count =count sum =sum =retrieval> isa countOrder first =count second =newcount ==> =g> isa add count =newcount +retrieval> isa countOrder first =sum""") self.model.productionstring(name="incrementSum", string=""" =g> isa add count =count arg2 ~=count sum =sum =retrieval> isa countOrder first =sum second =newsum ==> =g> isa add sum =newsum +retrieval> isa countOrder first =count""")
def still_go_on(self): yield {"=g": actr.makechunk("","press", key="=k!c"), "?manual": {"state": "busy"}} yield {"=g": actr.makechunk("","press", key="d")}
def __init__(self): self.model = actr.ACTRModel(motor_prepared=False) self.model.chunktype("press", "key") self.model.goal.add(actr.makechunk("","press", key="a"))
def two(self, utility=5): yield {"=g": actr.makechunk("start", "phase", state="start")} yield {"=g": actr.makechunk("dontchange", "phase", state="start")}
def __init__(self, env, **kwargs): self.m = actr.ACTRModel(environment=env, **kwargs) actr.chunktype("pair", "probe answer") actr.chunktype("goal", "state") self.dm = self.m.decmem self.m.visualBuffer("visual", "visual_location", self.dm, finst=30) start = actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="attending", typename="chunk", value="attending") actr.makechunk(nameofchunk="done", typename="chunk", value="done") self.m.goal.add(actr.makechunk(typename="read", state=start)) self.m.set_goal("g2") self.m.goals["g2"].delay=0.2 self.m.productionstring(name="find_probe", string=""" =g> isa goal state start ?visual_location> buffer empty ==> =g> isa goal state attend ?visual_location> attended False +visual_location> isa _visuallocation screen_x closest""") #this rule is used if automatic visual search does not put anything in the buffer self.m.productionstring(name="check_probe", string=""" =g> isa goal state start ?visual_location> buffer full ==> =g> isa goal state attend""") #this rule is used if automatic visual search is enabled and it puts something in the buffer self.m.productionstring(name="attend_probe", string=""" =g> isa goal state attend =visual_location> isa _visuallocation ?visual> state free ==> =g> isa goal state reading +visual> isa _visual cmd move_attention screen_pos =visual_location ~visual_location>""") self.m.productionstring(name="encode_probe_and_find_new_location", string=""" =g> isa goal state reading =visual> isa _visual value =val ?visual_location> buffer empty ==> =g> isa goal state attend ~visual> ?visual_location> attended False +visual_location> isa _visuallocation screen_x closest""")
def one(self, utility=1): yield {"=g": actr.makechunk("start", "phase", state="start")} yield {"=g": actr.makechunk("change", "phase", state="change")}
""" An example of a model using goal and retrieval. It corresponds to 'addition' in ACT-R tutorials, Unit 1. """ import pyactr as actr addition = actr.ACTRModel() actr.chunktype("countOrder", ("first", "second")) actr.chunktype("add", ("arg1", "arg2", "sum", "count")) dm = addition.decmem for i in range(0, 11): dm.add(actr.makechunk("chunk"+str(i), "countOrder", first=i, second=i+1)) addition.goal.add(actr.makechunk("", "add", arg1=5, arg2=2)) addition.productionstring(name="init_addition", string=""" =g> isa add arg1 =num1 arg2 =num2 sum None ==> =g> isa add sum =num1 count 0 +retrieval>
""" The most complex model in unit 1 of ACT-R tutorials, 'semantic'. """ import pyactr as actr semantic = actr.ACTRModel() actr.chunktype("property", ("object", "attribute", "value")) actr.chunktype("isMember", ("object", "category", "judgment")) chunk_dict = {} chunk_dict['shark'] = actr.makechunk(nameofchunk='shark', typename="elem", elem="shark") chunk_dict['dangerous'] = actr.makechunk(nameofchunk='dangerous', typename="elem", elem="dangerous") chunk_dict['locomotion'] = actr.makechunk(nameofchunk='locomotion', typename="elem", elem="locomotion") chunk_dict['swimming'] = actr.makechunk(nameofchunk='swimming', typename="elem", elem="swimming") chunk_dict['fish'] = actr.makechunk(nameofchunk='fish', typename="elem", elem="fish") chunk_dict['salmon'] = actr.makechunk(nameofchunk='salmon', typename="elem", elem="salmon") chunk_dict['edible'] = actr.makechunk(nameofchunk='edible', typename="elem", elem="edible") chunk_dict['breathe'] = actr.makechunk(nameofchunk='breathe', typename="elem", elem="breathe") chunk_dict['gills'] = actr.makechunk(nameofchunk='gills', typename="elem", elem="gills") chunk_dict['animal'] = actr.makechunk(nameofchunk='animal', typename="elem", elem="animal") chunk_dict['moves'] = actr.makechunk(nameofchunk='moves', typename="elem", elem="moves") chunk_dict['skin'] = actr.makechunk(nameofchunk='skin', typename="elem", elem="skin") chunk_dict['canary'] = actr.makechunk(nameofchunk='canary', typename="elem", elem="canary") chunk_dict['color'] = actr.makechunk(nameofchunk='color', typename="elem", elem="color") chunk_dict['sings'] = actr.makechunk(nameofchunk='sings', typename="elem", elem="sings") chunk_dict['bird'] = actr.makechunk(nameofchunk='bird', typename="elem", elem="bird") chunk_dict['ostrich'] = actr.makechunk(nameofchunk='ostrich', typename="elem", elem="ostrich") chunk_dict['flies'] = actr.makechunk(nameofchunk='flies', typename="elem", elem="flies")
def go_on(self): yield {"=g": actr.makechunk("","press", key="=k!b")} yield {"+manual": actr.makechunk("","_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("","press", key="c")}
def three(self, reward=10): yield {"=g": actr.makechunk("change", "phase", state="change")} yield {"~g": None}
def __init__(self, person, location, **kwargs): self.model = actr.ACTRModel(environment=None, **kwargs) actr.chunktype("comprehend", "relation arg1 arg2") actr.chunktype("meaning", "word") dict_dm = {} words = "hippie bank fireman lawyer guard beach castle dungeon earl forest giant park church captain cave debutante store in".split() for word in words: dict_dm[word] = actr.makechunk(nameofchunk=word, typename="meaning", word=word) for idx, word in enumerate("park church bank".split(), start=1): dict_dm[idx] = actr.makechunk(nameofchunk=idx, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["hippie"], arg2=dict_dm[word]) print(idx, word) for idx, word in enumerate("park cave".split(), start=4): dict_dm[idx] = actr.makechunk(nameofchunk=idx, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["captain"], arg2=dict_dm[word]) dict_dm[6] = actr.makechunk(nameofchunk=6, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["debutante"], arg2=dict_dm["bank"]) dict_dm[7] = actr.makechunk(nameofchunk=7, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["fireman"], arg2=dict_dm["park"]) for idx, word in enumerate("beach castle dungeon".split(), start=8): dict_dm[idx] = actr.makechunk(nameofchunk=idx, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["giant"], arg2=dict_dm[word]) for idx, word in enumerate("castle forest".split(), start=11): dict_dm[idx] = actr.makechunk(nameofchunk=idx, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["earl"], arg2=dict_dm[word]) dict_dm[13] = actr.makechunk(nameofchunk=idx, typename="comprehend", relation=dict_dm["in"], arg1=dict_dm["lawyer"], arg2=dict_dm["store"]) self.model.set_decmem(set(dict_dm.values())) self.dm = self.model.decmem self.harvest_person = actr.makechunk(nameofchunk="harvest_person", typename="chunk", value="harvest_person") self.harvest_location = actr.makechunk(nameofchunk="harvest_location", typename="chunk", value="harvest_location") self.test = actr.makechunk(nameofchunk="test", typename="chunk", value="test") self.get_retrieval = actr.makechunk(nameofchunk="get_retrieval", typename="chunk", value="get_retrieval") actr.chunktype("sentence_goal", "arg1 arg2 state") self.model.goal.add(actr.makechunk(typename="sentence_goal", arg1=person, arg2=location, state=self.test)) self.model.productionstring(name="start", string=""" =g> isa sentence_goal arg1 =person state test ==> =g> isa sentence_goal state harvest_person +retrieval> isa meaning word =person""") self.model.productionstring(name="harvesting_person", string=""" =g> isa sentence_goal arg2 =location state harvest_person =retrieval> isa nonempty ==> =g> isa sentence_goal state harvest_location arg1 =retrieval +retrieval> isa meaning word =location""") self.model.productionstring(name="harvesting_location", string=""" =g> isa sentence_goal state harvest_location =retrieval> isa nonempty ?retrieval> state free ==> =g> isa sentence_goal state get_retrieval arg2 =retrieval""") self.model.productionstring(name="retrieve_from_person", string=""" =g> isa sentence_goal state get_retrieval arg1 =person ==> =g> isa sentence_goal state None +retrieval> isa comprehend arg1 =person""") self.model.productionstring(name="retrieve_from_location", string=""" =g> isa sentence_goal state get_retrieval arg2 =location ==> =g> isa sentence_goal state None +retrieval> isa comprehend arg2 =location""") self.model.productionstring(name="respond_yes", string=""" =g> isa sentence_goal state None arg1 =person arg2 =location =retrieval> isa comprehend arg1 =person arg2 =location ==> =g> isa sentence_goal state 'k'""") self.model.productionstring(name="mismatch_person_no", string=""" =g> isa sentence_goal state None arg1 =person arg2 =location =retrieval> isa comprehend arg1 ~=person ==> =g> isa sentence_goal state 'd'""") t3= self.model.productionstring(name="mismatch_location_no", string=""" =g> isa sentence_goal state None arg1 =person arg2 =location =retrieval> isa comprehend arg2 ~=location ==> =g> isa sentence_goal state 'd'""")
def start(self): yield {"=g": actr.makechunk("", "reverse", x="=num", y="~=num")} yield { "+retrieval": actr.makechunk("", "twoVars", x="=num"), "=g": actr.makechunk("", "reverse", x="=num", y="=num") }
import random import warnings import tkinter as tk #delete later import pyactr as actr stimulus = random.sample(string.ascii_uppercase, 1)[0] text = {1: {'text': stimulus, 'position': (100,100)}} environ = actr.Environment(focus_position=(100,100)) m = actr.ACTRModel(environment=environ, motor_prepared=True) actr.chunktype("chunk", "value") actr.chunktype("read", "state") actr.chunktype("image", "img") actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="attend_let", typename="chunk", value="attend_let") actr.makechunk(nameofchunk="response", typename="chunk", value="response") actr.makechunk(nameofchunk="done", typename="chunk", value="done") m.goal.add(actr.chunkstring(name="reading", string=""" isa read state start""")) g2 = m.set_goal("g2") g2.delay = 0.2 t2 = m.productionstring(name="encode_letter", string=""" =g> isa read state start =visual>
def __init__(self): self.model = actr.ACTRModel(motor_prepared=False) self.model.chunktype("press", "key") self.model.goal.add(actr.makechunk("", "press", key="a"))
def __init__(self, **kwargs): self.model = actr.ACTRModel(**kwargs) actr.chunktype("recall_list", "group element list group_position") actr.chunktype("group", "id parent position") actr.chunktype("item", "name group position") li = actr.makechunk(typename="chunk", value="list") self.dictchunks = {1: actr.makechunk(nameofchunk="p1", typename="chunk", value="first"), 2: actr.makechunk(nameofchunk="p2", typename="chunk", value="second"), 3: actr.makechunk(nameofchunk="p3", typename="chunk", value="third"), 4: actr.makechunk(nameofchunk="p4", typename="chunk", value="fourth")} group1 = actr.makechunk(nameofchunk="group1", typename="group", parent=li, position=self.dictchunks[1], id="group1") group2 = actr.makechunk(nameofchunk="group2", typename="group", parent=li, position=self.dictchunks[2], id="group2") group3 = actr.makechunk(nameofchunk="group3", typename="group", parent=li, position=self.dictchunks[3], id="group3") self.model.set_decmem(set(self.dictchunks.values())) self.dm = self.model.decmem self.dm.add(set([group1, group2, group3])) self.dm.add(li) self.model.set_similarities(self.dictchunks[1], self.dictchunks[2], -0.5) self.model.set_similarities(self.dictchunks[2], self.dictchunks[3], -0.5) for n in range(1,4): self.dm.add(actr.makechunk(typename="item", name=n, group=group1, position=self.dictchunks[n])) for n in range(4,7): self.dm.add(actr.makechunk(typename="item", name=n, group=group2, position=self.dictchunks[(n+1)%4])) for n in range(7,10): self.dm.add(actr.makechunk(typename="item", name=n, group=group3, position=self.dictchunks[(n+1)%7])) self.model.retrieval.finst = 15 self.model.goal.add(actr.makechunk(typename="recall_list", list=li)) self.model.productionstring(name="recall_first_group", string=""" =g> isa recall_list list =l ?retrieval> buffer empty state free ==> =g> isa recall_list group_position p1 +retrieval> isa group parent =l position p1""") self.model.productionstring(name="start_recall_of_group", string=""" =g> isa recall_list list =l =retrieval> isa group id =sth ?retrieval> state free ==> =g> isa recall_list group =retrieval element p1 ?retrieval> recently_retrieved False +retrieval> isa item group =retrieval position p1""") self.model.productionstring(name="harvest_first_item", string=""" =g> isa recall_list element p1 group =group =retrieval> isa item name =name ?retrieval> state free ==> =g> isa recall_list element p2 ?retrieval> recently_retrieved False +retrieval> isa item group =group position p2""") self.model.productionstring(name="harvest_second_item", string=""" =g> isa recall_list element p2 group =group =retrieval> isa item name =name ?retrieval> state free ==> =g> isa recall_list element p3 ?retrieval> recently_retrieved False +retrieval> isa item group =group position p3""") self.model.productionstring(name="harvest_third_item", string=""" =g> isa recall_list element p3 group =group =retrieval> isa item name =name ?retrieval> state free ==> =g> isa recall_list element p4 ?retrieval> recently_retrieved False +retrieval> isa item group =group position p4""") self.model.productionstring(name="recall_second_group", string=""" =g> isa recall_list group_position p1 list =l ?retrieval> state error ==> =g> isa recall_list group_position p2 +retrieval> isa group parent =l position p2""") self.model.productionstring(name="recall_third_group", string=""" =g> isa recall_list group_position p2 list =l ?retrieval> state error ==> =g> isa recall_list group_position p3 +retrieval> isa group parent =l position p3""")
def __init__(self, env, **kwargs): self.m = actr.ACTRModel(environment=env, **kwargs) actr.chunktype("pair", "probe answer") actr.chunktype("goal", "state") actr.chunktype("chunk", "value") actr.chunktype("goal", "state") self.dm = self.m.decmem start = actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="attending", typename="chunk", value="attending") actr.makechunk(nameofchunk="testing", typename="chunk", value="testing") actr.makechunk(nameofchunk="response", typename="chunk", value="response") actr.makechunk(nameofchunk="study", typename="chunk", value="study") actr.makechunk(nameofchunk="attending_target", typename="chunk", value="attending_target") actr.makechunk(nameofchunk="done", typename="chunk", value="done") self.m.goal.add(actr.makechunk("read", typename="goal", state=start)) self.m.set_goal("g2", 0.2) self.m.productionstring(name="find_probe", string=""" =g> isa goal state start ?visual_location> buffer empty ==> =g> isa goal state attend ?visual_location> attended False +visual_location> isa _visuallocation screen_x >0""") self.m.productionstring(name="attend_probe", string=""" =g> isa goal state attend =visual_location> isa _visuallocation ?visual> state free ==> =g> isa goal state reading =visual_location> isa _visuallocation +visual> cmd move_attention screen_pos =visual_location""") self.m.productionstring(name="read_probe", string=""" =g> isa goal state reading =visual> isa _visual value =word ==> =g> isa goal state testing +g2> isa pair probe =word =visual> isa _visual +retrieval> isa pair probe =word""") self.m.productionstring(name="recall", string=""" =g> isa goal state testing =retrieval> isa pair answer =ans ?manual> state free ?visual> state free ==> +manual> isa _manual cmd 'press_key' key =ans =g> isa goal state study ~visual>""") self.m.productionstring(name="cannot_recall", string=""" =g> isa goal state testing ?retrieval> state error ?visual> state free ==> =g> isa goal state attending_target ~visual>""") self.m.productionstring(name="associate", string=""" =g> isa goal state attending_target =visual> isa _visual value =val =g2> isa pair probe =word ?visual> state free ==> =g> isa goal state reading ~visual> =g2> isa pair answer =val ~g2>""")
def __init__(self, env, **kwargs): self.m = actr.ACTRModel(environment=env, **kwargs) actr.chunktype("pair", "probe answer") actr.chunktype("goal", "state") self.dm = self.m.decmem start = actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="attending", typename="chunk", value="attending") actr.makechunk(nameofchunk="testing", typename="chunk", value="testing") actr.makechunk(nameofchunk="response", typename="chunk", value="response") actr.makechunk(nameofchunk="study", typename="chunk", value="study") actr.makechunk(nameofchunk="attending_target", typename="chunk", value="attending_target") actr.makechunk(nameofchunk="done", typename="chunk", value="done") self.m.goal.add(actr.makechunk(typename="read", state=start)) self.m.set_goal("g2") self.m.goals["g2"].delay=0.2 self.m.productionstring(name="find_probe", string=""" =g> isa goal state start ?visual_location> buffer empty ==> =g> isa goal state attend ?visual_location> attended False +visual_location> isa _visuallocation screen_x 320""") self.m.productionstring(name="attend_probe", string=""" =g> isa goal state attend =visual_location> isa _visuallocation ?visual> state free ==> =g> isa goal state reading =visual_location> isa _visuallocation +visual> cmd move_attention screen_pos =visual_location""") self.m.productionstring(name="read_probe", string=""" =g> isa goal state reading =visual> isa _visual value =word ==> =g> isa goal state testing +g2> isa pair probe =word =visual> isa visual +retrieval> isa pair probe =word""") self.m.productionstring(name="recall", string=""" =g> isa goal state testing =retrieval> isa pair answer =ans ?manual> state free ?visual> state free ==> +manual> isa _manual cmd 'press_key' key =ans =g> isa goal state study ~visual>""") self.m.productionstring(name="cannot_recall", string=""" =g> isa goal state testing ?retrieval> state error ?visual> state free ==> =g> isa goal state attending_target ~visual>""") self.m.productionstring(name="associate", string=""" =g> isa goal state attending_target =visual> isa _visual value =val =g2> isa pair probe =word ?visual> state free ==> =g> isa goal state reading ~visual> =g2> isa pair answer =val ~g2>""")
for i in range(1, UPTO + 1)] summing = sum(sum(x) for x in PROB) PROB = [[x / summing for x in y] for y in PROB] summing = sum(sum(x) for x in PROB) LEMMA_CHUNKS = {} print(PROB) for i in range(UPTO): for j in range(UPTO): count_freq = PROB[i][j] * NUMBER time_interval = TIME / count_freq chunk_times = np.arange(start=-time_interval, stop=-(time_interval * count_freq) - 1, step=-time_interval) LEMMA_CHUNKS[actr.makechunk("", typename="add", arg1=numbers[i + 1], arg2=numbers[j + 1], sum=i + 1 + j + 1)] = math.log( np.sum((0.2 - chunk_times)**(-DECAY))) #addition.set_decmem({x: np.array([]) for x in LEMMA_CHUNKS}) #addition.decmem.activations.update(LEMMA_CHUNKS) #for x in range(1,UPTO+1): # for y in range(1, UPTO+1): # print(x, y, addition.decmem.activations[actr.makechunk("", typename="add", arg1=numbers[x], arg2=numbers[y], sum=x+y)]) addition.productionstring(name="retrieve_addition", string=""" =g>
for i in range(1, UPTO + 1)] summing = sum(sum(x) for x in PROB) PROB = [[x / summing for x in y] for y in PROB] summing = sum(sum(x) for x in PROB) LEMMA_CHUNKS = {} print(PROB) for i in range(UPTO): for j in range(UPTO): count_freq = PROB[i][j] * NUMBER time_interval = TIME / count_freq chunk_times = np.arange(start=-time_interval, stop=-(time_interval * count_freq) - 1, step=-time_interval) LEMMA_CHUNKS[actr.makechunk("", typename="add", arg1=numbers[i + 1], arg2=numbers[j + 1], sum=i + 1 + j + 1)] = math.log( np.sum((0.2 - chunk_times)**(-DECAY))) LEMMA_CHUNKS[actr.makechunk("", typename="add", arg1=numbers[11], arg2=numbers[4], sum=numbers[15])] = -3.5 LEMMA_CHUNKS[actr.makechunk( "", typename="add", arg1=numbers[13], arg2=numbers[2], sum=numbers[15])] = -3.5 #to be found by simulation addition.set_decmem({x: np.array([]) for x in LEMMA_CHUNKS})
def __init__(self, **kwargs): self.m = actr.ACTRModel(**kwargs) self.m.chunktype("press", "key") self.m.goal.add(actr.makechunk("", "press", key="a"))
def simulation2(start, end, init_time, results, timing, time_stamps, feedback=True, learning=False): """ Second simulation, using production learning. """ attempts = collections.Counter() if learning: addition.productionstring(name="retrieve_addition", string=""" =g> isa add state reading arg1 =num1 arg2 =num2 sum None ?retrieval> state free buffer empty ==> =g> isa add state None +retrieval> isa add arg1 =num1 arg2 =num2""", utility=1) addition.productionstring(name="terminate_addition", string=""" =g> isa add state None =retrieval> isa add arg1 ~None sum =v7 ==> ~retrieval> =g> isa add sum =v7""", utility=1) addition.productionstring(name="done", string=""" =g> isa add state None sum =v7 sum ~None ==> =g> isa add state None""", reward=15) addition.model_parameters["production_compilation"] = True addition.model_parameters["utility_learning"] = True addition.model_parameters["utility_noise"] = 0.8 for loop in range(start + 1, end + 1): x = random.uniform(0, 1) #what problem should be used for i in range(len(PROB2)): if x < PROB2[i]: break else: i = UPTO x = random.uniform(0, 1) #what problem should be used for j in range(len(PROB2)): if x < PROB2[j]: break else: j = UPTO #print(i, j) correct = i + j attempts.update([(i, j)]) addition.goal.add( actr.makechunk("", "add", state="reading", arg1=numbers[i], arg2=numbers[j])) sim = addition.simulation(initial_time=init_time, trace=False, gui=False) addition.used_productions.rules.used_rulenames = {} while True: try: sim.step() except simpy.core.EmptySchedule: break if re.search("RETRIEVED: None", sim.current_event.action): results.setdefault((str(i), str(j)), collections.Counter()).update('X') if feedback and random.randint(0, 1) == 1: addition.retrieval.add( actr.makechunk("", "add", arg1=numbers[i], arg2=numbers[j], sum=numbers[correct])) addition.retrieval.clear(sim.show_time( )) #advise -- teacher tells the correct answer break if re.search("RULE FIRED: done", sim.current_event.action): x = addition.goal.copy().pop() addition.goal.clear(sim.show_time()) x = x._asdict() results.setdefault( (str(i), str(j)), collections.Counter()).update([str(x["sum"])]) if str(x["sum"]) != str(numbers[correct]): if feedback and random.randint(0, 1) == 1: addition.retrieval.add( actr.makechunk("", "add", arg1=numbers[i], arg2=numbers[j], sum=numbers[correct])) addition.retrieval.clear( sim.show_time() ) #advise -- teacher tells the correct answer in roughly 50% of cases if incorrect if learning: utilities.modify_utilities( sim.show_time(), -15, addition.used_productions.rules.used_rulenames, addition.used_productions.rules, addition.used_productions.model_parameters) elif timing: time_stamps.setdefault( (str(i), str(j)), []).append(sim.show_time() - init_time) break addition.retrieval.state = addition.retrieval._FREE addition.retrieval.clear() init_time = loop * DELAY return results, time_stamps, init_time
def finish(self): yield {"=g": actr.makechunk("","press", key="=k!c"), "?manual": {"preparation": "free"}} yield {"+manual": actr.makechunk("","_manual", cmd="press_key", key="=k"), "=g": actr.makechunk("","press", key="d")}
def __init__(self, env, **kwargs): self.m = actr.ACTRModel(environment=env, **kwargs) actr.chunktype("pair", "probe answer") actr.chunktype("goal", "state, arg1, arg2, sum, end, value") self.dm = self.m.decmem self.start = actr.makechunk(nameofchunk="start", typename="chunk", value="start") actr.makechunk(nameofchunk="done", typename="chunk", value="done") self.m.set_goal("g2") self.m.goals["g2"].delay = 0.2 self.m.productionstring( name="find_probe", string=""" =g> isa goal state start value =vv ?visual_location> buffer empty ==> =g> isa goal state attending ?visual_location> attended False +visual_location> isa _visuallocation value =vv screen_x lowest screen_y closest""" ) #this rule is used if automatic visual search does not put anything in the buffer self.m.productionstring( name="move_in_line", string=""" =g> isa goal state attending value =vv sum ~None ?visual_location> state error ==> =g> isa goal state attending sum None ?visual_location> attended False +visual_location> isa _visuallocation value =vv screen_x lowest screen_y closest""", utility=20 ) #this rule is used if automatic visual search does not put anything in the buffer self.m.productionstring( name="check_probe", string=""" =g> isa goal state start ?visual_location> buffer full ==> =g> isa goal state attending""" ) #this rule is used if automatic visual search is enabled and it puts something in the buffer self.m.productionstring(name="attend_probe", string=""" =g> isa goal state attending =visual_location> isa _visuallocation screen_x ~None ?visual> state free ==> =g> isa goal state reading sum None +visual> isa _visual cmd move_attention screen_pos =visual_location""") self.m.productionstring(name="encode_probe", string=""" =g> isa goal state reading =visual> isa _visual value =val ==> =g> isa goal sum None state None""") self.m.productionstring(name="retrieve_addition", string=""" =g> isa add state None arg1 =num1 arg2 =num2 arg2 ~None sum None ?retrieval> state free buffer empty ==> =g> isa add state None +retrieval> isa add arg1 =num1 arg2 =num2""", utility=7) self.m.productionstring(name="terminate_addition", string=""" =g> isa add =retrieval> isa add arg1 ~None sum =v7 ==> ~retrieval> =g> isa add state move sum =v7""", utility=7) for i, nums in enumerate([(2, 2), (4, 4), (4, 2), (3, 2), (2, 3), (5, 2), (7, 2), (7, 4), (9, 2), (9, 4), (11, 4), (13, 2)]): if nums[0] + nums[1] < 10: util = 7.5 else: util = 7 self.m.productionstring( name="retrieve_addition_terminate_addition" + str(i), string=""" =g> isa add state None arg1 """ + str(nums[0]) + """ arg2 """ + str(nums[1]) + """ sum None ?retrieval> state free buffer empty ==> =g> isa add state move sum """ + str(nums[0] + nums[1]), utility=util) self.m.productionstring(name="retrieve failure", string=""" =g> isa goal state None ?retrieval> state error ==> =g> isa goal state None arg2 None""") for i in range(15): self.m.productionstring(name="fast_increment" + str(i), string=""" =g> isa goal state None arg1 """ + str(i) + """ sum None ?retrieval> state free buffer empty ==> =g> isa goal state move sum """ + str(i + 1), utility=6) self.m.productionstring(name="move_vis_loc", string=""" =g> isa goal state move sum =csum sum ~None value =vv =visual_location> isa _visuallocation screen_y =sy ==> =g> isa goal state attending arg2 None arg1 =csum ~visual> ?visual_location> attended False +visual_location> isa _visuallocation value =vv screen_x closest screen_y =sy""") self.m.productionstring(name="can_find", string=""" =g> isa goal sum =x end =x ?manual> state free ==> ~retrieval> ~g> +manual> isa _manual cmd press_key key 'J'""", utility=5) self.m.productionstring(name="cannot_find", string=""" =g> isa goal state attending end ~unknown ?visual_location> state error ?manual> state free ==> ~retrieval> ~g> +manual> isa _manual cmd press_key key 'F'""", utility=-5) self.m.productionstring(name="switch", string=""" =g> isa goal state attending end unknown sum None ?visual_location> state error ?manual> state free ==> =g> isa goal state attending value B end 15 ?visual_location> attended False +visual_location> isa _visuallocation value B screen_x lowest screen_y closest""", utility=20) self.productions = self.m._ACTRModel__productions
A simple model of lexical decision. """ import pyactr as actr environment = actr.Environment(focus_position=(320,180)) lex_decision = actr.ACTRModel(environment=environment, motor_prepared=True, automatic_visual_search=False) actr.chunktype("goal", "state") actr.chunktype("word", "form") dm = lex_decision.decmem for string in {"elephant", "dog", "crocodile"}: dm.add(actr.makechunk(typename="word", form=string)) g = lex_decision.goal g.add(actr.makechunk(nameofchunk="beginning", typename="goal", state="start")) lex_decision.productionstring(name="find word", string=""" =g> isa goal state start ?visual_location> buffer empty ==> =g> isa goal
def finish(self): yield {"=g": actr.makechunk("","press", key="=k!d"), "?manual": {"state": "free"}} yield {"=g": actr.makechunk("","press", key="e")}