示例#1
0
    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""")
示例#2
0
    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""")
示例#3
0
    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""")
示例#4
0
    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'""")
示例#5
0
    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""")
示例#6
0
    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""")
示例#7
0
    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""")
示例#8
0
    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"))
示例#9
0
    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"))
示例#10
0
    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""")
示例#11
0
    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))
示例#12
0
    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))
示例#13
0
    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))
示例#14
0
    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 counting_model(sub):
    counting = actr.ACTRModel(subsymbolic=sub)

    #Each chunk type should be defined first.
    actr.chunktype("countOrder", ("first", "second"))
    #Chunk type is defined as (name, attributes)

    #Attributes are written as an iterable (above) or as a string, separated by comma:
    actr.chunktype("countOrder", "first, second")

    #creating goal buffer
    actr.chunktype("countFrom", ("start", "end", "count"))

    #production rules follow; using productionstring, they are similar to Lisp ACT-R

    counting.productionstring(name="start",
                              string="""
    =g>
    isa countFrom
    start =x
    count None
    ==>
    =g>
    isa countFrom
    count =x
    +retrieval>
    isa countOrder
    first =x""")

    counting.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""")

    counting.productionstring(name="stop",
                              string="""
    =g>
    isa     countFrom
    count       =x
    end         =x
    ==>
    ~g>""")

    return counting
示例#16
0
"""
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>
               592, 605, 603, 575, 620, 607, 622, 674])
ACCURACY = np.array([97.22, 95.56, 95.56, 96.3, 96.11, 94.26,\
                     95, 92.41, 91.67, 93.52, 91.85, 93.52,\
                     91.48, 90.93, 84.44, 74.63])/100

environment = actr.Environment(focus_position=(320, 180))
lex_decision = actr.ACTRModel(environment=environment,\
                       subsymbolic=True,\
                       automatic_visual_search=True,\
                       activation_trace=False,\
                       retrieval_threshold=-80,\
                       motor_prepared=True,
                       eye_mvt_scaling_parameter=0.18,\
                       emma_noise=False)

actr.chunktype("goal", "state")
actr.chunktype("word", "form")

# on average, 15 years of exposure is 112.5 million words

SEC_IN_YEAR = 365*24*3600
SEC_IN_TIME = 15*SEC_IN_YEAR

FREQ_DICT = {}
FREQ_DICT['guy'] = 242*112.5
FREQ_DICT['somebody'] = 92*112.5
FREQ_DICT['extend'] = 58*112.5
FREQ_DICT['dance'] = 40.5*112.5
FREQ_DICT['shape'] = 30.6*112.5
FREQ_DICT['besides'] = 23.4*112.5
FREQ_DICT['fit'] = 19*112.5
示例#18
0
"""
A left-corner parser.
"""

import pyactr as actr

environment = actr.Environment(focus_position=(320, 180))

actr.chunktype("read", "state word goal_cat")
actr.chunktype("parsing", "top bottom")
actr.chunktype("word", "form cat")

parser = actr.ACTRModel(environment)

parser.decmem.add(
    actr.chunkstring(string="isa word form 'Mary' cat 'ProperN'"))
parser.decmem.add(
    actr.chunkstring(string="isa word form 'Bill' cat 'ProperN'"))
parser.decmem.add(actr.chunkstring(string="isa word form 'likes' cat 'V'"))

parser.goal.add(
    actr.chunkstring(string="""
        isa     read
        state   start
        goal_cat 'S'"""))
parser.goal = "g2"
parser.goals["g2"].add(
    actr.chunkstring(string="""
        isa     parsing
        top     'S'"""))
parser.goals["g2"].delay = 0.2
示例#19
0
    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
示例#20
0
"""
An example of a model using retrieval and goal buffers. It corresponds to the simplest model in ACT-R tutorials, Unit 1, 'count'.
"""

import pyactr as actr

counting = actr.ACTRModel()

#Each chunk type should be defined first.
actr.chunktype("countOrder", ("first", "second"))
#Chunk type is defined as (name, attributes)

#Attributes are written as an iterable (above) or as a string, separated by comma:
actr.chunktype("countOrder", "first, second")

dm = counting.decmem
#this creates declarative memory

dm.add(actr.chunkstring(string="\
    isa countOrder\
    first 1\
    second 2"))
dm.add(actr.chunkstring(string="\
    isa countOrder\
    first 2\
    second 3"))
dm.add(actr.chunkstring(string="\
    isa countOrder\
    first 3\
    second 4"))
dm.add(actr.chunkstring(string="\
示例#21
0
    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""")
"""
A left-corner parser.
"""

import pyactr as actr
from ete3 import Tree
import simpy
import re

environment = actr.Environment(focus_position=(320, 180))

actr.chunktype(
    "parsing_goal",
    "task stack1 stack2 stack3 stack4 parsed_word right_frontier found gapped")
actr.chunktype("parse_state", "node_cat mother daughter1 daughter2 lex_head")
actr.chunktype("word", "form cat")

parser = actr.ACTRModel(environment,
                        subsymbolic=True,
                        retrieval_threshold=-5,
                        latency_factor=0.1,
                        latency_exponent=0.13)
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0)

dm.add(
    actr.chunkstring(string="""
    isa  word
    form 'Mary'
    cat  'ProperN'
示例#23
0
    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>""")
示例#24
0
文件: u2_demo.py 项目: jakdot/pyactr
"""

import string
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>
示例#25
0
"""
Syn/sem parser for fan experiment.
"""

import pyactr as actr
import simpy
import re
import itertools
from nltk.stem.snowball import SnowballStemmer


environment = actr.Environment(focus_position=(320, 180))

actr.chunktype("parsing_goal",
               "task stack1 stack2 stack3 stack4 arg_stack \
                expected1 expected2 expected3 parsed_word right_frontier\
                dref_peg")
actr.chunktype("parse_state",
               "node_cat mother daughter1 daughter2 lex_head")
actr.chunktype("word", "form cat pred")
actr.chunktype("drs",
               "dref pred arg1 arg2")

actr.chunktype("main_drs",
               "subdrs1 subdrs2 subdrs3")

parser = actr.ACTRModel(environment, subsymbolic=True,\
                        retrieval_threshold=-5, latency_factor=0.5,\
                        latency_exponent=0.5, emma_noise=False,\
                        rule_firing=0.1, buffer_spreading_activation={"g":2},\
                        strength_of_association=2)
示例#26
0
"""
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")
示例#27
0
"""
A left-corner parser.
"""

import pyactr as actr
from ete3 import Tree

environment = actr.Environment(focus_position=(320, 180))

actr.chunktype("parsing_goal",
               "task stack_top stack_bottom parsed_word right_frontier")
actr.chunktype("parse_state",
               "node_cat mother daughter1 daughter2 lex_head")
actr.chunktype("word", "form cat")

parser = actr.ACTRModel(environment)
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0)

dm.add(actr.chunkstring(string="""
    isa  word
    form 'Mary'
    cat  'ProperN'
"""))
dm.add(actr.chunkstring(string="""
    isa  word
    form 'Bill'
    cat  'ProperN'
"""))
dm.add(actr.chunkstring(string="""
#!/usr/bin/env python
# coding: utf-8

# In[2]:

get_ipython().system('pip3 install pyactr')

# In[ ]:

import pyactr as actr

# In[5]:

actr.chunktype("word", "meaning, category, number, synfunction")
actr.chunktype("goal_lexeme", "task, category, number")

carLexeme = actr.makechunk(nameofchunk="car",
                           typename="word",
                           meaning="[[car]]",
                           category="noun",
                           number="sg",
                           synfunction="subject")

agreement = actr.ACTRModel()

dm = agreement.decmem
dm.add(carLexeme)

agreement.goal.add(
    actr.chunkstring(string="""
    isa goal_lexeme
"""
A simple top-down parser.
"""

import pyactr as actr

actr.chunktype("parsing_goal", "stack_top stack_bottom parsed_word task")
actr.chunktype("sentence", "word1 word2 word3")
actr.chunktype("word", "form, cat")

parser = actr.ACTRModel()
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0.2)

dm.add(
    actr.chunkstring(string="""
    isa word
    form Mary
    cat ProperN
"""))
dm.add(
    actr.chunkstring(string="""
    isa word
    form Bill
    cat ProperN
"""))
dm.add(actr.chunkstring(string="""
    isa word
    form likes
    cat V
示例#30
0
    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>""")
示例#31
0
import pyactr as actr

playing_memory = actr.ACTRModel()


# Now we will create the knowledge that the mind has (point 2).
# 
# First, its current goal. The goal is seen as a container (in ACT-R terminology, a buffer) that carries a chunk. A chunk, in turn, is a list of attribute-value pairs. (Attributes are called slots in ACT-R.)
# 
# So, let's specify the chunk that the goal will carry. We do that first by defining a chunk type, that is, by defining what slots a chunk in the goal buffer can carry. We will define a chunk type "playgame" and assume that there are two slots in that chunk type: "game" and "activity".

# In[2]:


actr.chunktype("playgame", "game, activity")


# After defining the chunk type, we can specify the token that the goal buffer will have at the start of modeling/simulation. The starting point only specifies what game we are playing. Let's call this starting chunk "initial_chunk".

# In[3]:


initial_chunk = actr.makechunk(typename="playgame", game="memory")


# Note that the chunk has a value specified for "game", but no value for "activity". The activity will be decided by the mind through production knowledge. Before we get there, we have to set the goal buffer in the model and add the initial chunk into it. This will represent the current goal of the mind.

# In[4]:

"""
A left-corner parser.
"""

import pyactr as actr

environment = actr.Environment(focus_position=(320, 180))

actr.chunktype("parsing_goal",
               "task stack_top stack_bottom parsed_word right_frontier")
actr.chunktype("parse_state", "node_cat mother daughter1 daughter2 lex_head")
actr.chunktype("word", "form cat")

parser = actr.ACTRModel(environment, motor_prepared=True)
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0)

dm.add(
    actr.chunkstring(string="""
    isa  word
    form Mary
    cat  ProperN
"""))
dm.add(
    actr.chunkstring(string="""
    isa  word
    form Bill
    cat  ProperN
"""))
dm.add(actr.chunkstring(string="""
示例#33
0
"""
A basic model of grammar.
"""

import pyactr as actr

regular_grammar = actr.ACTRModel()

actr.chunktype("goal_chunk", "mother daughter1 daughter2 state")

dm = regular_grammar.decmem

regular_grammar.goal.add(actr.chunkstring(string="""
    isa         goal_chunk
    mother      'NP'
    state       rule
"""))

regular_grammar.productionstring(name="NP ==> N NP", string="""
    =g>
    isa         goal_chunk
    mother      'NP'
    daughter1   None
    daughter2   None
    state       rule
    ==>
    =g>
    isa         goal_chunk
    daughter1   'N'
    daughter2   'NP'
    state       show
示例#34
0
"""
A simple top-down parser.
"""

import pyactr as actr

actr.chunktype("parsing", "task stack_top stack_bottom parsed_word ")
actr.chunktype("sentence", "word1 word2 word3")

parser = actr.ACTRModel()

dm = parser.decmem
dm.add(actr.chunkstring(string="isa word form 'Mary' cat 'ProperN'"))
dm.add(actr.chunkstring(string="isa word form 'Bill' cat 'ProperN'"))
dm.add(actr.chunkstring(string="isa word form 'likes' cat 'V'"))

parser.goal.add(
    actr.chunkstring(string="isa parsing  task parse stack_top 'S'"))
parser.goal = "g2"
parser.goals["g2"].delay = 0.2
parser.goals["g2"].add(
    actr.chunkstring(
        string="isa sentence word1 'Mary' word2 'likes' word3 'Bill'"))

parser.productionstring(name="expand: S->NP VP",
                        string="""
        =g>
        isa         parsing
        task        parse
        stack_top   'S'
        ==>
示例#35
0
    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""")
示例#36
0
SIMULATIONNUMBER = int(sys.argv[1])
MP = 2.0
RT = 4

addition = actr.ACTRModel(subsymbolic=True,
                          retrieval_threshold=-2.25,
                          latency_factor=0.1,
                          latency_exponent=0.5,
                          instantaneous_noise=0.25,
                          decay=DECAY,
                          buffer_spreading_activation={"g": 1},
                          strength_of_association=4,
                          association_only_from_chunks=False)

actr.chunktype("countOrder", ("first", "second"))

actr.chunktype("number", "value")

actr.chunktype("add", ("state", "arg1", "arg2", "sum"))

dm = addition.decmem

numbers = []

for i in range(0, 30):
    #numbers.append(actr.makechunk("number"+str(i), "number", value=i))
    numbers.append(str(i))

#for i in range(0, 16):
#    dm.add(actr.makechunk("chunk"+str(i), "countOrder", first=numbers[i], second=numbers[i+1]))
    return worksheet


def load_file(lfile, index_col=None, sep=","):
    """
    Loads file as a list
    """
    csvfile = pd.read_csv(lfile, index_col=index_col, header=0, sep=sep)
    return csvfile


##############ACT-R model, basics#####################

environment = actr.Environment(size=(1366, 768), focus_position=(0, 0))

actr.chunktype("read", "state word")
actr.chunktype("parsing", "top")
actr.chunktype("word", "form cat")

#the model with basic parameters set up
parser = actr.ACTRModel(environment,
                        subsymbolic=True,
                        optimized_learning=OPTIMIZED_LEARNING,
                        retrieval_threshold=RETRIEVAL_THRESHOLD,
                        decay=DECAY,
                        emma_noise=EMMA_NOISE,
                        emma_landing_site_noise=EMMA_NOISE)

parser.productionstring(
    name="attend word",
    string="""
示例#38
0
"""
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>
示例#39
0
"""
A simple top-down parser.
"""

import pyactr as actr

actr.chunktype("parsing_goal", "stack_top stack_bottom parsed_word task")
actr.chunktype("sentence", "word1 word2 word3")
actr.chunktype("word", "form, cat")

parser = actr.ACTRModel()
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0.2)

dm.add(actr.chunkstring(string="""
    isa word
    form 'Mary'
    cat 'ProperN'
"""))
dm.add(actr.chunkstring(string="""
    isa word
    form 'Bill'
    cat 'ProperN'
"""))
dm.add(actr.chunkstring(string="""
    isa word
    form 'likes'
    cat 'V'
"""))
                        latency_exponent=0.01,
                        eye_mvt_angle_parameter=1,
                        emma_noise=False,
                        eye_mvt_scaling_parameter=0.01,
                        rule_firing=0.02,
                        motor_prepared=True,
                        automatic_visual_search=False)
temp_dm = {}

temp_activations = {}

stimuli_csv = stimuli_csv[stimuli_csv.critical.isin(["0", "1", "2", "3"])]

words = stimuli_csv.groupby('word', sort=False)

actr.chunktype("word", "form cat")

actr.chunktype("parsing_goal", "task")

actr.chunktype("reading",
               "state position word reanalysis retrieve_wh what_retrieve tag")

actr.chunktype(
    "action_chunk",
    "ACTION ACTION_RESULT_LABEL ACTION_PREV WORD_NEXT0_LEX WORD_NEXT0_POS TREE0_LABEL TREE1_LABEL TREE2_LABEL TREE3_LABEL TREE0_HEAD TREE0_HEADPOS TREE0_LEFTCHILD TREE0_RIGHTCHILD TREE1_HEAD TREE1_HEADPOS TREE1_LEFTCHILD TREE1_RIGHTCHILD TREE2_HEAD TREE2_HEADPOS TREE3_HEAD ANTECEDENT_CARRIED"
)

for name, group in words:
    word = group.iloc[0]['word']
    function = sentences_csv[sentences_csv.word.isin(
        [word])].function.to_numpy()[0]
示例#41
0
"""

import string
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
示例#42
0
    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""")
示例#43
0
文件: u5_fan.py 项目: jakdot/pyactr
    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'""")
示例#44
0
    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'""")
示例#45
0
"""
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
示例#46
0
from nltk.stem.snowball import SnowballStemmer

import numpy as np

# stemmer to generate non-logical constants for word meaning representations
stemmer = SnowballStemmer("english")

environment = actr.Environment(focus_position=(320, 180))

# we have a discourse_status feature in goal chunks, initialized to the value
# at_issue (as opposed to presupposed or unresolved DRSs)

actr.chunktype(
    "parsing_goal", "task stack1 stack2 stack3 \
                arg_stack1 arg_stack2 \
                right_edge_stack1 right_edge_stack2 \
                right_edge_stack3 right_edge_stack4 \
                parsed_word found discourse_status \
                dref_peg event_peg drs_peg prev_drs_peg embedding_level\
                entity_cataphora event_cataphora if_conseq_pred")
actr.chunktype(
    "parse_state", "node_cat daughter1 daughter2 daughter3 \
                mother mother_of_mother lex_head")
actr.chunktype("word", "form cat pred1 pred2")
actr.chunktype("pred", "constant_name arity")
actr.chunktype(
    "drs", "dref pred1 pred2 event_arg arg1 arg2 \
                discourse_status drs embedding_level")

parser = actr.ACTRModel(
    environment,
    subsymbolic=True,
"""
A left-corner parser.
"""

import pyactr as actr
from ete3 import Tree
import simpy
import re

environment = actr.Environment(focus_position=(320, 180))

actr.chunktype("parsing_goal",
               "task stack1 stack2 stack3 stack4 parsed_word right_frontier found gapped")
actr.chunktype("parse_state",
               "node_cat mother daughter1 daughter2 lex_head")
actr.chunktype("word", "form cat")

parser = actr.ACTRModel(environment, subsymbolic=True, retrieval_threshold=-5, latency_factor=0.1, latency_exponent=0.13)
dm = parser.decmem
g = parser.goal
imaginal = parser.set_goal(name="imaginal", delay=0)

dm.add(actr.chunkstring(string="""
    isa  word
    form 'Mary'
    cat  'ProperN'
"""))

dm.add(actr.chunkstring(string="""
    isa  word
    form 'The'