def create_teams(strategy1, strategy2, max_tries_1=1, max_tries_2=1, num_agents=10): agents1 = [ AgentWithStrategy(strategy1, architecture='matrix', creator='uniform_random', max_tries=max_tries_1) for i in range(num_agents)] agents2 = [ AgentWithStrategy(strategy2, architecture='matrix', creator='uniform_random', max_tries=max_tries_2) for i in range(num_agents)] return agents1, agents2
def create_game(neg_beta): env = GridEnvironment(env_size, env_size, goals=GOALS, symbols=AgentKnowledge.holistic_symbols) RandomInitializer(num_objects=num_objects, reduced=True).init_environments(env) learners = [AgentWithStrategy(StrategyTypes.MIXED, architecture=HolisticCognitiveArchitecture(len(AgentKnowledge.holistic_symbols), len(env.goals), neg_beta=neg_beta, random=True), role=Role.LISTENER, max_tries=num_tries, failure_alignment=True) for i in range(num_agents)] teacher = AgentWithStrategy(StrategyTypes.MIXED, architecture=HolisticCognitiveArchitecture(len(AgentKnowledge.holistic_symbols), len(env.goals)), role=Role.LISTENER) teacher.architecture.language_matrix = get_non_zero_permutation_matrix(len(AgentKnowledge.holistic_symbols), len(env.goals)) name = "teachers_learners_game_holistic_"+str(num_tries) game = CooperationHolisticGameWithTeachersAndLearners(env, [teacher], learners, name, umpire=HolisticGameUmpire(env, len(env.goals))) return game
def setup_game_with_new_agents(size, num_agents, num_objects): env_1, env_2 = setup_environments(size, num_objects) number_agents = num_agents cooperative_agents = [ AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='multiple', creator='uniform_random') for i in range(number_agents) ] cooperative_game = CooperationGame(env_1, cooperative_agents, "cooperative_10_agents_1") non_cooperative_agents = [ AgentWithStrategy(StrategyTypes.NON_EXHAUSTIVE, architecture='multiple', creator='uniform_random') for i in range(number_agents) ] non_cooperative_game = CooperationGame(env_2, non_cooperative_agents, "non_cooperative_10_agents_1") return cooperative_game, non_cooperative_game
Agents keep a matrix representation of association between symbols and meanings Word order is fixed: ACTION-COLOR-SHAPE-DIRECTION """ num_agents = 10 env_size = 8 num_objects = 60 num_games = 50 max_attempts = 20 if __name__ == "__main__": results = [] for i in range(max_attempts): print("group: ", i agents = [AgentWithStrategy(StrategyTypes.MIXED, architecture='matrix', max_tries=i+1) for i in range(num_agents)] grid_env = get_new_environment(env_size, num_objects) game = CooperationGame(grid_env, agents, "cooperation-game-test", umpire="fixed_word_order") is_game_finished = False time_steps = [] for j in range(num_games): print("game: ", j num_timesteps = 0 while not is_game_finished: is_game_finished = game.consume_time_step() num_timesteps += 1 time_steps.append(num_timesteps) game.set_new_environment(get_new_environment(env_size, num_objects)) is_game_finished = False results.append((game.umpire, time_steps, agents)) with open('/Users/mariano/developing/repos/phdnotebooks/results/20_groups_umpires_fixed_order.pkl', 'w') as f:
num_games = 5 if __name__ == "__main__": # agents = [AgentWithStrategy(StrategyTypes.MIXED, architecture='matrix_word_order', max_tries=5) for i in range(num_agents)] # grid_env = GridEnvironment(env_size, env_size) # RandomInitializer(num_objects=num_objects).init_environments(grid_env) # game = CooperationGameWithWordOrder(grid_env, agents, "One_game_test") # is_game_finished = False # while not is_game_finished: # is_game_finished = game.consume_time_step() results = [] for i in range(max_attempts): agents = [ AgentWithStrategy(StrategyTypes.MIXED, architecture='matrix_variable_word_order', max_tries=i + 1) for i in range(num_agents) ] grid_env = get_new_environment(env_size, num_objects) game = CooperationGameWithWordOrder(grid_env, agents, "cooperation-game-test") is_game_finished = False time_steps = [] for j in range(num_games): num_timesteps = 0 while not is_game_finished: is_game_finished = game.consume_time_step() num_timesteps += 1 time_steps.append(num_timesteps) game.set_new_environment(get_new_environment( env_size, num_objects))
from strategies import StrategyTypes from game_utils import get_new_environment, get_stochastic_permutation_matrix from environment import meanings, Categories num_agents = 20 num_games = 5 env_size = 8 num_objects = 60 if __name__ == "__main__": learners = [AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='counting_variable_word_order', role=Role.LISTENER) for i in range(num_agents/2)] teachers = [AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='matrix_3D_fixed_word_order', role=Role.SPEAKER) for i in range(num_agents/2)] language_matrix = get_stochastic_permutation_matrix(len(AgentKnowledge.symbols), len(meanings), Categories.get_number_of_categories()) for teacher in teachers: teacher.architecture.language_matrix = language_matrix env = get_new_environment(env_size, num_objects) game = CooperationGameWithTeachersAndLearners(env, teachers, learners, "teachers_learners_game") time_steps = [] num_timesteps = 0 is_game_finished = False for i in range(num_games): while not is_game_finished: if game.status.number_of_attempts == 6: pass is_game_finished = game.consume_time_step() num_timesteps += 1
return perform_interaction(game) if __name__ == "__main__": grid_env_1 = GridEnvironment(8, 8) grid_env_2 = GridEnvironment(8, 8) initializer = RandomInitializer(num_objects=100) initializer.init_environments(grid_env_1, grid_env_2) app = QtGui.QApplication([]) window = DoubleWindow(grid_env_1, grid_env_2, interval=.1) number_agents = 10 cooperative_agents = [ AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='multiple', creator='uniform_random') for i in range(number_agents) ] cooperative_game = GraphicalGame(window.gridWidget_1, coop_interaction_cb, cooperative_agents, "cooperative_10_agents_1") non_cooperative_agents = [ AgentWithStrategy(StrategyTypes.NON_EXHAUSTIVE, architecture='multiple', creator='uniform_random') for i in range(number_agents) ] non_cooperative_game = GraphicalGame(window.gridWidget_2, non_coop_interaction_cb, non_cooperative_agents,
from PyQt4 import QtGui if __name__ == "__main__": grid_env_1, grid_env_2 = setup_environments(8, 50) app = QtGui.QApplication([]) name1 = "NON_EXHAUSTIVE_10_AGENTS_WORD_ORDER" name2 = "EXHAUSTIVE_10_AGENTS_WORD_ORDER" window = DoubleWindow(grid_env_1, grid_env_2, label1=name1, label2=name2, interval=0.5) agents1 = [ AgentWithStrategy(StrategyTypes.NON_EXHAUSTIVE, architecture='matrix_word_order') for i in range(10) ] agents2 = [ AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='matrix_word_order') for i in range(10) ] game_1 = GraphicalGameWithStatus(window.gridWidget_1, agents1, name1) game_2 = GraphicalGameWithStatus(window.gridWidget_2, agents2, name2) window.timer.timeout.connect(game_1.timer_callback) window.timer.timeout.connect(game_2.timer_callback) window.show() app.exec_()
from strategies import StrategyTypes import pickle as pickle from game_utils import get_new_environment num_agents = 5 env_size = 8 num_objects = 40 num_games = 50 max_attempts = 20 if __name__ == "__main__": results = [] for i in range(max_attempts): print(i) agents = [AgentWithStrategy(StrategyTypes.MIXED, architecture='multiple', max_tries=i+1, creator='uniform_random') for i in range(num_agents)] grid_env = get_new_environment(env_size, num_objects) game = CooperationGame(grid_env, agents, "cooperation-game-test") is_game_finished = False time_steps = [] for j in range(num_games): print(j num_timesteps = 0 while not is_game_finished: is_game_finished = game.consume_time_step() num_timesteps += 1 time_steps.append(num_timesteps) game.set_new_environment(get_new_environment(env_size, num_objects)) is_game_finished = False results.append((game.umpire, time_steps, agents)) with open('/Users/mariano/developing/repos/phdnotebooks/results/20_groups_umpires_holophrastic.pkl', 'w') as f:
return costs if __name__ == "__main__": num_agents = 10 num_objects = 50 num_games = 100 size = 8 reward = 300 results = [] costs = [] strat1 = StrategyTypes.EXHAUSTIVE strat2 = StrategyTypes.MIXED cooperative_agents = [ AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture='multiple', creator='uniform_random') for i in range(num_agents) ] non_cooperative_agents = [ AgentWithStrategy(StrategyTypes.MIXED, architecture='multiple', creator='uniform_random', max_tries=2) for i in range(num_agents) ] for i in range(num_games): number_of_time_steps = 0 coop_game, not_coop_game = setup_game_with_agents( size, num_objects, cooperative_agents, non_cooperative_agents) is_game_finished = False while not is_game_finished:
return False def coop_interaction_cb(game): return perform_interaction(game, True) def non_coop_interaction_cb(game): return perform_interaction(game, False) if __name__ == "__main__": grid_env_1 = GridEnvironment(8, 8) grid_env_2 = GridEnvironment(8, 8) initializer = RandomInitializer(num_objects=100) initializer.init_environments(grid_env_1, grid_env_2) app = QtGui.QApplication([]) window = DoubleWindow(grid_env_1, grid_env_2, interval=2.5) number_agents = 10 cooperative_agents = [AgentWithStrategy(StrategyTypes.EXHAUSTIVE) for i in range(number_agents)] cooperative_game = GraphicalGame(window.gridWidget_1, coop_interaction_cb, cooperative_agents, "cooperative_10_agents_1") non_cooperative_agents = [AgentWithStrategy(StrategyTypes.NON_EXHAUSTIVE) for i in range(number_agents)] non_cooperative_game = GraphicalGame(window.gridWidget_2, non_coop_interaction_cb, non_cooperative_agents, "non_cooperative_10_agents_1") window.timer.timeout.connect(cooperative_game.timer_callback) window.timer.timeout.connect(non_cooperative_game.timer_callback) window.show() app.exec_()
from agent import AgentWithStrategy, AgentKnowledge, HolisticCognitiveArchitecture from game import CooperationHolisticGameWithTeachersAndLearners, Role, HolisticGameUmpire from strategies import StrategyTypes from game_utils import get_new_reduced_environment, get_permutation_matrix import numpy as np num_agents = 20 num_games = 30 env_size = 8 num_objects = 60 if __name__ == "__main__": env = get_new_reduced_environment(env_size, num_objects) learners = [AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture=HolisticCognitiveArchitecture(len(AgentKnowledge.symbols), len(env.goals)), role=Role.LISTENER) for i in range(num_agents/2)] teachers = [AgentWithStrategy(StrategyTypes.EXHAUSTIVE, architecture=HolisticCognitiveArchitecture(len(AgentKnowledge.symbols), len(env.goals)), role=Role.SPEAKER) for i in range(num_agents/2)] language_matrix = get_permutation_matrix(len(AgentKnowledge.symbols), len(env.goals), float) for teacher in teachers: teacher.architecture.language_matrix = language_matrix game = CooperationHolisticGameWithTeachersAndLearners(env, teachers, learners, "teachers_learners_game_holistic", umpire=HolisticGameUmpire(env, len(env.goals))) is_game_finished = False for i in range(num_games): while not is_game_finished: is_game_finished = game.consume_time_step() env = get_new_reduced_environment(env_size, num_objects) print("GAME FINISHED ", i game.env = env is_game_finished = False for i in range(language_matrix.shape[0]):