示例#1
0
def mod_focus(*modifications):
    model = actr.current_model()

    if not (model):
        actr.print_warning('Mod-focus called with no current model.')
    else:
        module = goal_modules[model.lower()]

        if not (module):
            actr.print_warning(
                'No goal module found for model %s when trying to use mod-focus.'
                % model)
        else:
            chunk = actr.buffer_read('goal')
            module.lock.acquire()
            delayed = module.delayed
            module.lock.release()

            if chunk or delayed:
                actr.schedule_mod_buffer_chunk('goal',
                                               modifications,
                                               0,
                                               module='goal',
                                               priority=':max')
                if delayed:
                    return delayed
                else:
                    return chunk
            else:
                actr.print_warning(
                    'No chunk currently in the goal buffer and no pending goal-focus chunk to be modified.'
                )
示例#2
0
def show_model_results(mcards, ocards, mres, ores):

    if len(mcards) == 3:
        mhit = mcards[2]
    else:
        mhit = 'nil'

    if len(ocards) == 3:
        ohit = ocards[2]
    else:
        ohit = 'nil'

    if actr.buffer_read('goal'):
        actr.mod_focus('mc1', mcards[0], 'mc2', mcards[1], 'mc3', mhit, 'mtot',
                       score_cards(mcards), 'mstart', score_cards(mcards[0:2]),
                       'mresult', mres, 'oc1', ocards[0], 'oc2', ocards[1],
                       'oc3', ohit, 'otot', score_cards(ocards), 'ostart',
                       score_cards(ocards[0:1]), 'oresult', ores, 'state',
                       'results')
    else:
        actr.goal_focus(
            actr.define_chunks([
                'isa', 'game-state', 'mc1', mcards[0], 'mc2', mcards[1], 'mc3',
                mhit, 'mtot',
                score_cards(mcards), 'mstart',
                score_cards(mcards[0:2]), 'mresult', mres, 'oc1', ocards[0],
                'oc2', ocards[1], 'oc3', ohit, 'otot',
                score_cards(ocards), 'ostart',
                score_cards(ocards[0:1]), 'oresult', ores, 'state', 'results'
            ])[0])

    actr.run_full_time(10)
示例#3
0
def compute_difference():
    c = actr.buffer_read('imaginal')
    n = actr.copy_chunk(c)
    actr.mod_chunk(
        n, 'difference',
        abs(
            actr.chunk_slot_value(c, 'length') -
            actr.chunk_slot_value(c, 'goal-length')))
    return n
示例#4
0
def trials(n,cont=False,v=False):

    global report,word_list,reward_check
    
    actr.add_command("reward-check",verify_reward,
                     "Past tense code check for a reward each trial.")
    actr.monitor_command("trigger-reward","reward-check")

    if not(cont) or not(word_list):
        actr.reset()
        word_list = make_word_freq_list(verbs)
        new = []
        for x in word_list:
            for y in x[1:]:
                if y not in new:
                    new.append(y)
        for x in new:
            if not(actr.chunk_p(x)):
                actr.define_chunks([x])

        print_header()
        report = []
 
    actr.set_parameter_value(":v",v)

    start = 100 * math.floor(len(report) / 100)
    count = len(report) % 100

    for i in range(n):
        add_past_tense_to_memory()
        add_past_tense_to_memory()
        reward_check = False
        target = make_one_goal()
        duration = actr.run(100)[0]
        add_to_report(target,actr.buffer_read('imaginal'))
        actr.clear_buffer('imaginal')
        count += 1
        
        if count == 100:
            rep_f_i(start, start + 100, 100)
            count = 0
            start += 100
        if not(reward_check):
            actr.print_warning("Model did not receive a reward when given %s."% target[0])

        actr.run_full_time(200 - duration)

        if duration == 100:
            actr.print_warning("Model spent 100 seconds generating a past tense for %s."%
                               target[0])

    rep_f_i(start,start+count,100)

    actr.remove_command_monitor("trigger-reward","reward-check")
    actr.remove_command("reward-check")
示例#5
0
def show_model_cards(mcards, ocard):

    if actr.buffer_read('goal'):
        actr.mod_focus('mc1', mcards[0], 'mc2',
                       mcards[1], 'mc3', None, 'mtot', None, 'mstart',
                       score_cards(mcards), 'mresult', None, 'oc1', ocard,
                       'oc2', None, 'oc3', None, 'otot', None, 'ostart',
                       score_cards([ocard]), 'oresult', None, 'state', 'start')
    else:
        actr.goal_focus(
            actr.define_chunks([
                'isa', 'game-state', 'mc1', mcards[0], 'mc2', mcards[1],
                'mstart',
                score_cards(mcards), 'oc1', ocard, 'ostart',
                score_cards([ocard]), 'state', 'start'
            ])[0])

    global model_action
    model_action = 's'
    actr.run_full_time(10)
    return model_action
示例#6
0
def trial(*features):

    actr.reset()
 
    for slot,value in actr.permute_list(list(zip(slots,features))):
        attribute(slot,value)

    goal = actr.define_chunks(["state","categorize"])[0]
    actr.goal_focus(goal)
    actr.run(20)
    
    answer = actr.chunk_slot_value(actr.buffer_read("imaginal"),"category")

    if isinstance(answer,numbers.Number):
        if answer == 1 or answer == 2:
            return((answer,True))
        else:
            actr.model_output("Model responded with invalid category.")
            return((0,False))
    else:
        actr.model_output("Model did not respond or provided a non-numeric category.")
        return((0,False))
示例#7
0
def sentence(person, location, target, term):

    actr.reset()

    if term == 'person':
        actr.pdisable("retrieve-from-location")
    else:
        actr.pdisable("retrieve-from-person")

    actr.mod_chunk("goal", "arg1", person, "arg2", location, "state", "test")

    response_time = actr.run(30)[0]
    response = actr.chunk_slot_value(actr.buffer_read("goal"), "state")

    if target:
        if response.lower() == "'k'".lower():
            return (response_time, True)
        else:
            return (response_time, False)
    else:
        if response.lower() == "'d'".lower():
            return (response_time, True)
        else:
            return (response_time, False)
示例#8
0
def run_experiment(start_point,
                   end_point,
                   verbose=True,
                   visible=True,
                   trace=True):
    """Runs an experiment"""
    actr.reset()
    # current directory
    actr.load_act_r_model(r"C:\Users\syl\Desktop\ACTR_ATO\sp_new_2.0.lisp")
    window = actr.open_exp_window("* Speed trace *",
                                  width=800,
                                  height=600,
                                  visible=visible)
    actr.install_device(window)

    # actr.add_text_to_exp_window(window, text="当前推荐速度:", x=10, y=60, height=40, width=95, color='black', font_size=22)
    # # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=20, height=40, width=180, color='black', font_size=22)
    # actr.add_text_to_exp_window(window, text="当前实际速度:", x=10, y=100, height=40, width=95, color='black', font_size=22)
    # actr.add_text_to_exp_window(window, text="距离车站位置:", x=10, y=140, height=40, width=95, color='black', font_size=22)
    # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=180, height=40, width=95, color='black', font_size=22)

    # actr.add_button_to_exp_window(window, text="7", x=500, y=80, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
    # actr.add_button_to_exp_window(window, text="6", x=500, y=100, action=["sp-button-pressed", 0.2, "up"],height=20, width=100, color='yellow')
    # actr.add_button_to_exp_window(window, text="5", x=500, y=120, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
    # actr.add_button_to_exp_window(window, text="4", x=500, y=140, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
    # actr.add_button_to_exp_window(window, text="3", x=500, y=160, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
    # actr.add_button_to_exp_window(window, text="2", x=500, y=180, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
    actr.add_button_to_exp_window(
        window,
        text="up",
        x=500,
        y=200,
        action=["sp-button-pressed-up-keep-down", 2, "up"],
        height=20,
        width=100,
        color='yellow')
    actr.add_button_to_exp_window(
        window,
        text="keep",
        x=500,
        y=220,
        action=["sp-button-pressed-up-keep-down", 0, "keep"],
        height=20,
        width=100,
        color='gray')
    actr.add_button_to_exp_window(
        window,
        text="down",
        x=500,
        y=240,
        action=["sp-button-pressed-up-keep-down", 2, "down"],
        height=20,
        width=100,
        color='green')
    # actr.add_button_to_exp_window(window, text="-2", x=500, y=260, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="-3", x=500, y=280, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="-4", x=500, y=300, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="-5", x=500, y=320, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="-6", x=500, y=340, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="-7", x=500, y=360, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
    # actr.add_button_to_exp_window(window, text="EB", x=500, y=380, action=["sp-button-stop-pressed", 0.2, "stop"], height=20, width=100, color='red')
    actr.add_command("sp-button-pressed-up-keep-down", button_pressed,
                     "sp press button(up\keep\down) task")
    actr.start_hand_at_mouse()

    for i in range(start_point, end_point):

        target_speed = train_model().target_v(i)
        actual_speed = 10
        delta_speed = actual_speed - target_speed
        t_group.append(i)
        target_group.append(target_speed)
        actual_group.append(actual_speed)
        if delta_speed > 0:
            delta_speed_show = "+"
        elif delta_speed < 0:
            delta_speed_show = "-"
        else:
            delta_speed_show = "0"

        print(i, str(int(target_speed)))
        deltasudu = actr.add_text_to_exp_window(window,
                                                delta_speed_show,
                                                x=550,
                                                y=180,
                                                height=40,
                                                width=95,
                                                color='red',
                                                font_size=22)
        # mubiaosudu = actr.add_text_to_exp_window(window, str(int(target_speed)), x=200, y=60,height=40, width=95, color='red', font_size=22)
        # shijisudu = actr.add_text_to_exp_window(window, str(int(actual_speed)), x=200, y=100, height=40, width=95,color='red', font_size=22)

        actr.run(100, True)
        actr.print_visicon()
        print(
            "****************************end cmd actr.print_visicon()**********************************"
        )
        actr.all_productions()
        print(
            "****************************end cmd actr.all_productions()**********************************"
        )
        actr.clear_buffer("visual")
        actr.act_r_output(actr.dm())
        actr.buffer_read("manual")
        print(
            "****************************end cmd actr.buffer_read(manual)**********************************"
        )

        # actr.remove_items_from_exp_window(window, mubiaosudu)
        # actr.remove_items_from_exp_window(window, shijisudu)
        actr.remove_items_from_exp_window(window, deltasudu)

    Game().draw_target_actual_speed(t_group, target_group, actual_group)
    actr.remove_command_monitor("output-key", "sp-key-press")
示例#9
0
def goal_focus(name=None):
    model = actr.current_model()

    if not (model):
        actr.print_warning('Goal-focus called with no current model.')
    else:
        module = goal_modules[model.lower()]

        if not (module):
            actr.print_warning(
                'No goal module found for model %s when trying to use goal-focus.'
                % model)
        elif name:
            if actr.chunk_p(name):

                actr.schedule_set_buffer_chunk('goal',
                                               name,
                                               0,
                                               module='goal',
                                               priority=':max',
                                               requested=False)
                actr.schedule_event_after_module('goal',
                                                 'clear-delayed-goal',
                                                 params=[model],
                                                 module='goal',
                                                 maintenance=True,
                                                 output=False)

                module.lock.acquire()
                module.delayed = name
                module.lock.release()
                return name

            else:
                actr.print_warning(
                    '%S is not the name of a chunk in the current model - goal-focus failed'
                    % name)

        else:
            chunk = actr.buffer_read('goal')
            module.lock.acquire()
            delayed = module.delayed
            module.lock.release()

            if not (chunk) and not (delayed):
                actr.command_output('Goal buffer is empty')
                return None
            elif not (chunk):
                actr.command_output(
                    'Will be a copy of %s when the model runs' % delayed)
                actr.pprint_chunks(delayed)
                return delayed
            elif not (delayed):
                actr.pprint_chunks(chunk)
                return chunk
            else:
                copy = actr.chunk_copied_from(chunk)

                if copy.lower() == delayed.lower():

                    actr.pprint_chunks(chunk)
                    return chunk
                else:
                    actr.command_output(
                        'Will be a copy of %s when the model runs' % delayed)
                    actr.command_output('Currently holds:')
                    actr.pprint_chunks(chunk)
                    return delayed