示例#1
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")
示例#2
0
def request(name, buffer, spec):
    chunk_desc = actr.chunk_spec_to_chunk_def(spec)
    actr.release_chunk_spec(spec)

    if chunk_desc:
        actr.schedule_event_now('create-goal-buffer-chunk',
                                params=[buffer, chunk_desc],
                                module='goal',
                                priority=-100)
    else:
        actr.print_warning('Invalid request made to the goal buffer.')
示例#3
0
def clear_delayed_goal(model):
    module = goal_modules[model.lower()]

    if not (module):
        actr.print_warning(
            'No goal module found for model %s when trying to clear delayed goal.'
            % model)
    else:
        module.lock.acquire()
        module.delayed = None
        module.lock.release()
示例#4
0
def query(name, buffer, slot, value):
    s = slot.lower()
    if hasattr(value, 'lower'):
        v = value.lower()
    else:
        v = value

    if s == 'state':
        if v == 'free':
            return True
        elif v == 'busy':
            return False
        elif v == 'error':
            return False
        else:
            actr.print_warning('Unknown state query %s to goal module' % v)
            return False
    else:
        actr.print_warning('Unknown query %s %s to goal module' % (s, v))
        return False
示例#5
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.'
                )
示例#6
0
def experiment(n,new_offset=0,s1="eh",s2="es",s3="nl",s4="mh"):
    global offset,slots

    if all(list(map(lambda x: isinstance(x,str),[s1,s2,s3,s4]))):
        s1 = s1.lower()
        s2 = s2.lower()
        s3 = s3.lower()
        s4 = s4.lower()

        if s1 in [s2,s3,s4] or s2 in [s1,s3,s4] or s3 in [s1,s2,s4] or s4 in [s1, s2, s3]:
            actr.print_warning("Duplicate slot names provided. Using default slots.")
            slots = ["eh", "es", "nl", "mh"]
        elif 'category' in [s1,s2,s3,s4]:
            actr.print_warning("Slot named category cannot be used. Using default slots.")
            slots = ["eh", "es", "nl", "mh"]
        else:
            slots=[s1,s2,s3,s4]
    else:
        actr.print_warning("Not all slot names provided are strings. Using default slots.")
        slots = ["eh", "es", "nl", "mh"]

    if isinstance(new_offset,numbers.Number):
        offset = new_offset
    else:
        offset = 0

    trials = len(cat_data)

    results = [0] * trials
    counts = [0] * trials

    for i in range(n):
        answers,responses = do_experiment()
        results = list(map(lambda x,y: x + y,results,answers))
        counts = list(map(lambda x,y: x + y,counts,responses))

    results=list(map(lambda x: x/n,results))

    offset = 0

    actr.correlation(results,cat_data)
    actr.mean_deviation(results,cat_data)

    print("P(C=1)")
    print("        ",end="")
    for i in range(trials):
        print("(%4d) " % counts[i],end="")
    print()
    print("data  ",end="")
    for i in range(trials):
        print("%7.3f" % cat_data[i],end="")
    print()
    print("model ",end="")
    for i in range(trials):
        print("%7.3f" % results[i],end="")
    print()
示例#7
0
def add_to_report(target, chunk):
    global report

    stem = actr.chunk_slot_value(chunk,"stem")
    word = actr.chunk_slot_value(chunk,"verb")
    suffix = actr.chunk_slot_value(chunk,"suffix")
    irreg = (target[2] == 'blank')

    if target[0].lower() == word.lower():
        if stem == word and suffix.lower() == 'ed':
            report.append([irreg,'reg'])
        elif stem == None and suffix == None:
            report.append([irreg,'none'])
        elif stem.lower() == target[1].lower() and suffix.lower() == 'blank':
            report.append([irreg,'irreg'])
        else:
            actr.print_warning(
                "Incorrectly formed verb. Presented %s and produced verb %s,stem %s,suffix %s."%
                (target[0],word,stem,suffx))
    else:
        actr.print_warning(
            "Incorrectly formed verb. Presented %s and produced verb %s,stem %s,suffix %s."%
            (target[0],word,stem,suffx))
        report.append([irreg,'error'])
示例#8
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