Ejemplo n.º 1
0
def demo_table():
    actr.reset()
    #init()

    #...when manually setting the sentence (without syntetizer)
    text = "give fork"

    #...when using Aldebran proxy for speech recognition
    #text = AL_speech_recognition()

    #...when using Google Api (no Python 2.7)
    #text = GAPI_speech_recognition()

    string = tokenize(text)
    onset = 0
    actr.set_parameter_value(":sound-decay-time", 0.2)
    #actr.set_parameter_value(":save-audicon-history", True)
    actr.add_command("inner-speech-response", record_model_speech,
                     "Inner speech model response")
    actr.monitor_command("output-speech", "inner-speech-response")
    actr.install_device(["speech", "microphone"])
    for word in string:
        if TOK.descr[word.kind] == "WORD":
            print(str(word.txt))
            actr.new_word_sound(str(word.txt), onset)
            onset = onset + 0.2
    actr.run(30)
    actr.remove_command_monitor("output-speech", "inner-speech-response")
    actr.remove_command("inner-speech-response")
Ejemplo n.º 2
0
def set_parameters(**kwargs):
    """
    set parameter to current model
    :param kwargs: dict pair, indicating the parameter name and value (e.g. ans=0.1, r1=1, r2=-1)
    :return:
    """
    global reward
    for key, value in kwargs.items():
        if key == "r": reward = value
        else: actr.set_parameter_value(':' + key, value)
Ejemplo n.º 3
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")
Ejemplo n.º 4
0
    def simulate(self, trace=False, utility_offset=True):
        """Runs SP simulations using real stimuli"""
        # Function hook to modify the utility calculation
        # (will add a mismatch penalty). Need to be defined
        # before the model is loaded
        
        actr.add_command("parser-offset", self.utility_offset,
                         "Calculates a mismatch penalty for AI condition")

        actr.load_act_r_model(self.model)

        
        for condition in self.CONDITIONS:
            self.current_condition = condition
            subset = [t for t in self.trials if t.condition == condition]
            for j in range(self.n):
                actr.reset()

                # Make the model silent in case
                
                if not trace:
                    actr.set_parameter_value(":V", False)

                # The model does not really need a visual interface,
                # but the default AGI provides a virtual mic to record
                # voice output.
        
                win = actr.open_exp_window("SP", width = 80,
                                           height = 60,
                                           visible=False)
                actr.install_device(win)

                # Function hooks to record the model responses. 
                
                actr.add_command("record-response", self.record_response,
                                 "Accepts a response for the SP task")
                actr.monitor_command("output-speech",
                                     "record-response")

                
                # Run a single trial in the given condition
                
                trial = random.choice(subset)
                self.run_trial(trial)

                # Clean up the function hooks
                
                actr.remove_command_monitor("output-speech",
                                            "record-response")
                actr.remove_command("record-response")
                
        # Removes the offset
        actr.remove_command("parser-offset")
Ejemplo n.º 5
0
def run_experiment(model_name="response-monkey.lisp",
                   time=200,
                   verbose=True,
                   visible=True,
                   trace=True,
                   params=[]):
    """Runs an experiment"""
    actr.reset()
    # current directory
    curr_dir = os.path.dirname(os.path.realpath(__file__))
    actr.load_act_r_model(os.path.join(curr_dir, model_name))

    # Set then model parameters
    for name, val in params:
        actr.set_parameter_value(name, val)

    win = actr.open_exp_window("* STROOP TASK *",
                               width=800,
                               height=600,
                               visible=visible)

    actr.install_device(win)

    task = StroopTask(setup=False)
    #task.window = win

    actr.add_command("stroop-next", task.next, "Updates the internal task")
    actr.add_command("stroop-update-window", task.update_window,
                     "Updates the window")
    actr.add_command("stroop-accept-response", task.accept_response,
                     "Accepts a response for the Stroop task")

    actr.monitor_command("output-key", "stroop-accept-response")

    task.setup(win)
    if not trace:
        actr.set_parameter_value(":V", False)
    actr.run(time)
    if verbose:
        print("-" * 80)
        task.print_stats(task.run_stats())

    # Cleans up the interface
    # (Removes all the links between ACT-R and this object).

    actr.remove_command_monitor("output-key", "stroop-accept-response")
    actr.remove_command("stroop-next")
    actr.remove_command("stroop-update-window")
    actr.remove_command("stroop-accept-response")

    # Returns the task as a Python object for further analysis of data
    return task
Ejemplo n.º 6
0
def set_parameters(**kwargs):
    """
    set parameter to current model
    :param kwargs: dict pair, indicating the parameter name and value (e.g. ans=0.1, r1=1, r2=-1)
    :return:
    """
    for key, value in kwargs.items():
        # set reward parameter
        if key=='r1':
            actr.spp('step3-1', ':reward', value)
        elif key=='r2':
            actr.spp('step3-2', ':reward', value)
        elif key=='similarities' and actr.current_model()=='MODEL3':
            # set-similarities (DO undecided 0.5) (PO undecided 0.5)
            actr.sdp('undecided', ":similarities", [['DO', value], ['PO', value]])
            actr.sdp('DO', ":similarities", [['undecided', value]])
            actr.sdp('PO', ":similarities", [['undecided', value]])
        # normal parameters
        else:
            actr.set_parameter_value(':' + key, value)
Ejemplo n.º 7
0
    def simulate(self):
        """Runs a single simulation"""

        # Add commands and hooks
        actr.add_command("v_offset", self.chunk_v_term,
                         "Extra term in activation")

        actr.add_command("spreading", self.spreading_activation,
                         "Overrides normal spreading activation algorithm")

        actr.add_command("monitor_retrievals", self.monitor_retrievals,
                         "Monitors what is being retrieved")

        actr.add_command("next", self.present_new_situation,
                         "Presents a new situation")

        actr.add_command("keep_table", self.add_chunk)

        # Makes sure we are loading the current model from
        # the current directory
        curr_dir = os.path.dirname(os.path.realpath(__file__))
        actr.load_act_r_model(os.path.join(curr_dir, self.model))

        actr.set_parameter_value(":V", False)
        actr.set_parameter_value(":cmdt", False)

        # Apply the set of provided parameters
        for param, value in self.model_params.items():
            actr.set_parameter_value(param, value)

        # Run a life simulation

        event_time = 0.0

        while actr.mp_time() < self.max_time:
            actr.schedule_event(event_time, "next")
            event_time += self.event_step
            actr.run(self.event_step)  # No need to run beyond the event step

        # Clean-up

        actr.remove_command("next")
        actr.remove_command("v_offset")
        actr.remove_command("spreading")
        actr.remove_command("keep_table")
        actr.remove_command("monitor_retrievals")

        # Update counter

        self.counter += 1
Ejemplo n.º 8
0
def play(player1, player2):
    global window, p1, p2, p1_position, p2_position, current_player, game_over, safety_stop, p1_text, p2_text

    if (player1.lower() in (x.lower() for x in actr.mp_models())) and (
            player2.lower() in (x.lower() for x in actr.mp_models())):

        actr.reset()

        actr.set_current_model(player1)

        # create a goal chunk with the player's color and name
        actr.define_chunks([
            'goal', 'isa', 'play', 'my-color', 'red', 'my-name',
            "'%s'" % player1
        ])
        actr.goal_focus('goal')
        actr.set_parameter_value(':show-focus', 'red')

        actr.set_current_model(player2)

        # create a goal chunk with the player's color and name
        actr.define_chunks([
            'goal', 'isa', 'play', 'my-color', 'blue', 'my-name',
            "'%s'" % player2
        ])
        actr.goal_focus('goal')
        actr.set_parameter_value(':show-focus', 'blue')

        window = actr.open_exp_window("game",
                                      visible=True,
                                      width=200,
                                      height=100)
        safety_window = actr.open_exp_window('Safety',
                                             visible=True,
                                             height=100,
                                             width=100,
                                             x=100,
                                             y=100)

        actr.add_command('stop-a-run', stop_a_run,
                         'Set the flag to terminate the game.')

        actr.add_button_to_exp_window(safety_window,
                                      text="STOP",
                                      x=0,
                                      y=0,
                                      action='stop-a-run',
                                      height=80,
                                      width=80,
                                      color='red')

        p1 = player1
        p2 = player2
        game_over = False
        safety_stop = False
        current_player = player1
        p1_position = 0
        p2_position = 5

        for m in actr.mp_models():
            actr.set_current_model(m)
            actr.install_device(window)

        p1_text = actr.add_text_to_exp_window(window,
                                              str(p1_position),
                                              x=20,
                                              y=10,
                                              color='red',
                                              height=30,
                                              width=30,
                                              font_size=20)
        p2_text = actr.add_text_to_exp_window(window,
                                              str(p2_position),
                                              x=140,
                                              y=10,
                                              color='blue',
                                              height=30,
                                              width=30,
                                              font_size=20)

        actr.add_command("process-moves", process_moves,
                         "Handle player speak actions")
        actr.monitor_command("output-speech", "process-moves")

        # speak to all models telling them the name
        # of the first player.

        for m in actr.mp_models():
            actr.set_current_model(m)
            actr.new_word_sound(p1, 0, 'start')

        actr.add_command('is-game-over', is_game_over,
                         'Test whether game should stop running.')
        actr.add_command('set_game_over', set_game_over,
                         'Set the flag to stop the game.')

        actr.run_until_condition('is-game-over', True)

        actr.remove_command_monitor("output-speech", "process-moves")
        actr.remove_command("process-moves")
        actr.remove_command('stop-a-run')
        actr.remove_command('is-game-over')
        actr.remove_command('set_game_over')

    return game_over
Ejemplo n.º 9
0
 def reset(self):
     self.lock.acquire()
     self.delayed = None
     actr.set_parameter_value(':do-not-harvest', 'goal')
     self.lock.release()