def graph_it(data): win = actr.open_exp_window("Irregular Verbs correct",visible=True,width=500,height=475) low = min(data) zoom = min([.9,math.floor(10 * low)/10]) actr.clear_exp_window(win) actr.add_text_to_exp_window(win, "1.0", x=5, y=5, width=22) actr.add_text_to_exp_window(win, "%0.2f" % zoom, x=5, y=400, width=22) actr.add_text_to_exp_window(win, "%0.2f" % (zoom + ((1.0 - zoom) / 2)), x=5, y=200, width=22) actr.add_text_to_exp_window(win, "Trials", x=200, y=420, width=100) actr.add_line_to_exp_window(win,[30,10],[30,410],'black') actr.add_line_to_exp_window(win,[450,410],[25,410],'black') for i in range(10): actr.add_line_to_exp_window(win,[25,10 + i*40],[35,10 + i*40],'black') start = data[0] increment = max([1.0,math.floor( 450 / len(data))]) r = math.floor (400/ (1.0 - zoom)) intercept = r + 10 lastx =30 lasty = intercept - math.floor(r * start) for p in data[1:]: x = lastx + 30 y = intercept - math.floor(r * p) actr.add_line_to_exp_window(win,[lastx,lasty],[x,y],'red') lastx = x lasty = y
def person(): global response window = actr.open_exp_window("Choice Experiment", visible=True) actr.add_command("choice-response", respond_to_key_press, "Choice task key response") actr.monitor_command("output-key", "choice-response") actr.add_text_to_exp_window(window, 'choose', x=50, y=100) response = '' while response == '': actr.process_events() actr.clear_exp_window(window) if actr.random(1.0) < .9: answer = 'heads' else: answer = 'tails' actr.add_text_to_exp_window(window, answer, x=50, y=100) start = actr.get_time(False) while (actr.get_time(False) - start) < 1000: actr.process_events() actr.remove_command_monitor("output-key", "choice-response") actr.remove_command("choice-response") return response
def present_next_trial(): global task_state,start_time,val1,val2 task_state = 'trial' actr.clear_exp_window(window) val1 = actr.random(4) val2 = actr.random(4) actr.add_text_to_exp_window(window, str(val1), x=10, y=50) actr.add_text_to_exp_window(window, str(val2), x=110, y=50) start_time = actr.get_time()
def present_trial(trial, new_window=True): if new_window: w = actr.open_exp_window("Alpha-arithmetic Experiment", visible=trial.visible) if run_model: actr.install_device(w) else: actr.clear_exp_window() actr.add_text_to_exp_window(None, trial.text, x=100, y=150) trial.start = actr.get_time(run_model)
def do_experiment(size, trials, human): actr.reset() result = [] model = not (human) window = actr.open_exp_window("Paired-Associate Experiment", visible=human) if model: actr.install_device(window) for i in range(trials): score = 0 time = 0 for prompt, associate in actr.permute_list(pairs[20 - size:]): actr.clear_exp_window(window) actr.add_text_to_exp_window(window, prompt, x=150, y=150) global response response = '' start = actr.get_time(model) if model: actr.run_full_time(5) else: while (actr.get_time(False) - start) < 5000: actr.process_events() if response == associate: score += 1 time += response_time - start actr.clear_exp_window(window) actr.add_text_to_exp_window(window, associate, x=150, y=150) start = actr.get_time(model) if model: actr.run_full_time(5) else: while (actr.get_time(False) - start) < 5000: actr.process_events() if score > 0: average_time = time / score / 1000.0 else: average_time = 0 result.append((score / size, average_time)) return result
def test_unit3(): """this test unit examines trace""" assert check_load() trial = ('?', 'Punishment', 'MostlyReward') prompt, feedback, block_type = trial window = actr.open_exp_window("Gambling Experiment", visible=False) actr.install_device(window) actr.clear_exp_window(window) actr.add_text_to_exp_window(window, prompt, x=150, y=150) actr.run_full_time(5) actr.clear_exp_window(window) actr.add_text_to_exp_window(window, feedback, x=150, y=150) actr.run_full_time(5)
def do_feedback(feedback, window): """ This function allows the model to encode feedback :param feedback: "win" or "lose" :param window: :return: """ actr.clear_exp_window(window) actr.add_text_to_exp_window(window, feedback, x=150, y=150) actr.run_full_time(5) # implement reward if actr.current_model() == "MODEL2": if feedback == "Reward": actr.trigger_reward(reward) elif feedback == "Punishment": actr.trigger_reward(-1.0 * reward)
def do_guess(prompt, window): """ this function allows model to do first half of the experiment, guessing :param prompt:"?" :param window: :return: response "f" for less, or "j" for more """ # display prompt actr.clear_exp_window(window) actr.add_text_to_exp_window(window, prompt, x=150, y=150) # wait for response global response response = '' start = actr.get_time() actr.run_full_time(5) time = response_time - start return response, time
def present_trial(given_letter = None, train_epochs = 1, new_window = True, open_window = True, delay_time = 10, display = False): global window, window_reading, clickList, chunk_names, chunk_defs if (given_letter == None): letterList = actr.permute_list(list(string.ascii_uppercase)) chosen_letter = letterList[0] else: chosen_letter = given_letter if display: train_n(10, chosen_letter) clickList = [] actr.clear_exp_window(window_reading) actr.clear_exp_window(window) actr.add_text_to_exp_window(window_reading, chosen_letter, 125, 150) actr.add_command('process-click',process_click) actr.monitor_command('click-mouse','process-click') actr.run(1000, open_window) # for actr time or real time correct = correct_drawing(chosen_letter, clickList) if (correct): train_once(chosen_letter) actr.run_full_time(delay_time) else: train_n(train_epochs, chosen_letter) actr.run_full_time(delay_time) actr.remove_command_monitor('click-mouse', 'process-click') actr.remove_command('process-click') return (clickList, correct)
def update_window(self): """Updates the experiment window""" if self.window is not None: # First, clean-up actr.clear_exp_window() # Then, add new elements if self.phase == "fixation": item = actr.add_text_to_exp_window(self.window, "+", x=400, y=300, color="black") elif self.phase == "stimulus": color = self.current_trial.color word = self.current_trial.word item = actr.add_text_to_exp_window(self.window, word, x=395, y=300, color=color) for i, col in enumerate(COLOR_MAPPINGS): item = actr.add_text_to_exp_window(self.window, COLOR_MAPPINGS[col], x=600 + i * 50, y=500, color=col) print(type(COLOR_MAPPINGS)) elif self.phase == "done": color = self.current_trial.color word = self.current_trial.word item = actr.add_text_to_exp_window(self.window, "done", x=395, y=300, color="black")
def respond_to_key_press(model, key): global response response = key actr.clear_exp_window()
def process_moves(model, string): global p1_position, p2_position, current_player, p1_text, p2_text # Let all other models hear this for m in actr.mp_models(): if not (m.lower() == model.lower()): # all other models will hear this actr.set_current_model(m) # Create the originating model's name as a simple chunk if # it isn't one already to avoid a warning of it being # created by default when the sound is generated. if not (actr.chunk_p(model)): actr.define_chunks(model) # Create the sound as a word with location indicating # the speaker. actr.new_word_sound(string, actr.mp_time(), model) if (string.lower() == "one"): move = 1 elif (string.lower() == "two"): move = 2 else: print("Wrong move assumed to be 1: %s" % string) move = 1 if current_player == p1: p1_position += move else: p2_position -= move actr.clear_exp_window(window) if (p2_position <= p1_position): # if there's a winner actr.schedule_event_relative(3, 'set_game_over', params=[current_player]) actr.add_text_to_exp_window(window, current_player, x=60, y=20, color='green', height=30, width=80, font_size=20) else: # not a winner so update the display with the new position 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) if current_player == p1: current_player = p2 else: current_player = p1
def present_feedback(result): global task_state task_state = 'feedback' actr.clear_exp_window(window) actr.add_text_to_exp_window(window, result, x=50, y=100)
def play(player1, player2): global p1, p2, p1_position, p2_position, game_over, current_player, safety_stop, winner, p1p1, p1p2, p2p1, p2p2 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.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') win = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=300) actr.add_button_to_exp_window('Safety', text='STOP', x=0, y=0, action='stop-a-run', height=90, width=90, color='red') actr.add_command('move', make_move, 'Handle player key presses') actr.monitor_command('output-key', 'move') actr.reset() # initialize the game information p1 = player1 p2 = player2 p1_position = 0 p2_position = 5 game_over = False current_player = player1 safety_stop = False winner = None actr.set_current_model(player1) actr.define_chunks(player2) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p1p1 = feats[0] p1p2 = feats[1] actr.set_current_model(player2) actr.define_chunks(player1) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p2p1 = feats[0] p2p2 = feats[1] 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') actr.clear_exp_window(win) actr.remove_command('stop-a-run') actr.remove_command_monitor('output-key', 'move') actr.remove_command('move') actr.remove_command('is-game-over') actr.remove_command('set_game_over') return winner
def do_experiment(subj="depressed", human=False, wlist_amount=2000): ''' Run the experiment ''' global subject subject = subj assert wlist_amount <= len( word_lists_dict ), "Chosen too many lists, choose less or create more word lists using function: create_lists()" # display_word_lists() for idx, (key, value) in enumerate(word_lists_dict.items()): actr.reset() window = setup_experiment(human) global current_list current_list = idx # keep track for which list words are recalled setup_dm(value) actr.add_command("retrieved-word", record_words_recalled, "Retrieves recalled words.") actr.add_command("rehearsed-word", record_words_rehearsed, "Retrieves rehearsed words.") for word in value: if "neutral" in word: color = "black" elif "positive" in word: color = "green" else: color = "red" actr.add_text_to_exp_window(window, word, x=475 - len(word), y=374, color=color, font_size=20) # change later actr.run( 6, human ) # True when choosing Human, False when choosing differently actr.clear_exp_window(window) actr.run(.5, human) # 500-ms blank screen prepare_for_recall() actr.remove_command("rehearsed-word") actr.goal_focus("startrecall") # set goal to start recalling actr.run(10, human) actr.remove_command("retrieved-word") print(f'Experiment {idx+1}/{wlist_amount} completed!', end="\r") if idx == wlist_amount - 1: # run for a chosen amount of word lists break close_exp_window() # close window at end of experiment avg_recalled, avg_recalled_unique = 0, 0 for key, val in recalled_words.items(): avg_recalled += len(val) avg_recalled_unique += len(set(val)) # print(f'\nList {key} (length={len(val)}, unique={len(set(val))})') print("\n\n#############################################") print(f'\n[{subj}] Results!\n') result = analysis(wlist_amount, False) print(f'Avg. Amount of words recalled = {avg_recalled//wlist_amount}') print( f'Avg. Amount of unique words recalled = {avg_recalled_unique//wlist_amount}' ) for key, val in result.items(): print(f'{key} = {dict(val)}') print()
def clear_screen(self): actr.clear_exp_window(self.window)
def display_prompt(window, prompt): actr.clear_exp_window() actr.add_text_to_exp_window(window, prompt, x=125, y=150)