コード例 #1
0
def main(n_iterations, failure_alignment, alignment_strategy, num_games,
         directory):
    for ite in range(n_iterations):
        winners = []
        games = create_games(failure_alignment, num_agents)
        is_game_finished = False
        computed_games = 0

        # def signal_handler(signal, frame):
        # 	print('You pressed Ctrl+C - or killed me with -2'
        # 	agents = [game.agents for game in games]
        # 	umpires = [game.umpire for game in games]
        # 	aligned = "negative" if failure_alignment else "positive"
        # 	file_name = "holistic/negotiated_{0}_{1}_games_{2}_agents.pkl".format(aligned, computed_games, num_agents)
        # 	store_files(umpires, agents, winners, file_name, directory)
        # 	sys.exit(0)

        # signal.signal(signal.SIGINT, signal_handler)

        for k, game_ in enumerate(games):
            game_.umpire.compute_distance_agents(game_.agents)
            game_.umpire.compute_distance_agents(game_.agents,
                                                 measure=Distances.HELLINGER)
            game_.umpire.compute_mean_fitness(game_.agents)

        for i in range(num_games):
            while not is_game_finished:
                for game in games:
                    is_game_finished = game.consume_time_step()
                    if is_game_finished:
                        winners.append(game.agents[0].strategy.max_tries)
                        reward_agents(game.agents, reward)
                        computed_games += 1
                        break
            print("GAME FINISHED ", i)
            envs = get_new_environments(
                max_tries,
                env_size,
                num_objects,
                symbols=AgentKnowledge.holistic_symbols)
            for k, game_ in enumerate(games):
                game_.umpire.compute_distance_agents(game_.agents)
                game_.umpire.compute_distance_agents(
                    game_.agents, measure=Distances.HELLINGER)
                game_.umpire.compute_mean_fitness(game_.agents)
                game_.reset_game(envs[k])
            is_game_finished = False

        agents = [game.agents for game in games]
        umpires = [game.umpire for game in games]
        aligned = "negative" if failure_alignment else "positive"
        file_name = "holistic/negotiated_{0}_{1}_games_{2}.pkl".format(
            aligned, computed_games, str(ite))

        store_files(umpires, agents, winners, file_name, directory)
コード例 #2
0
def main(n_iterations, failure_alignment, alignment_strategy, num_games, directory):

	for ite in range(n_iterations):
		print("ITERATION: ", ite)
		winners = []
		alignment = alignment_strategy() if alignment_strategy else None
		games = create_games(failure_alignment, num_agents, alignment)
		computed_games = 0

		# def signal_handler(signal, frame):
		# 	print('You pressed Ctrl+C - or killed me with -2'
		# 	agents = [game.agents for game in games]
		# 	umpires = [game.umpire for game in games]
		# 	aligned = "negative" if failure_alignment else "positive"
		# 	align_strat = games[0].learners[0].architecture.align_strat.__class__.__name__ if failure_alignment else ""
		# 	file_name = "word/teachers_{0}_{1}_{2}_games_{3}_agents.pkl".format(aligned, align_strat, computed_games, num_agents)
		# 	store_files(umpires, agents, winners, file_name, directory)
		# 	sys.exit(0)

		# signal.signal(signal.SIGINT, signal_handler)

		for k, game_ in enumerate(games):
			game_.umpire.compute_distance_learners(game_.learners, game_.teachers[0].architecture.language_matrix)
			game_.umpire.compute_distance_agents(game_.learners, measure=Distances.JENSEN_SHANNON)
			game_.umpire.compute_distance_agents(game_.learners, measure=Distances.HELLINGER)

		is_game_finished = False
		for i in range(num_games):
			while not is_game_finished:
				for game in games:
					is_game_finished = game.consume_time_step()
					if is_game_finished:
						winners.append(game.agents[0].strategy.max_tries)
						reward_agents(game.agents, reward)
						computed_games += 1
						break
			print("GAME FINISHED ", i)

			envs = get_new_environments(max_tries, env_size, num_objects)
			for k, game_ in enumerate(games):
				game_.umpire.compute_distance_learners(game_.learners, game_.teachers[0].architecture.language_matrix)
				game_.umpire.compute_distance_agents(game_.learners, measure=Distances.JENSEN_SHANNON)
				game_.umpire.compute_distance_agents(game_.learners, measure=Distances.HELLINGER)
				game_.umpire.compute_mean_fitness(game_.agents)
				game_.reset_game(envs[k])
			is_game_finished = False

		umpires = [game.umpire for game in games]
		learners = [game.learners for game in games]

		aligned = "negative" if failure_alignment else "positive"
		align_strat = games[0].learners[0].architecture.align_strat.__class__.__name__ if failure_alignment else ""
		file_name = "word/teachers_{0}_{1}_{2}_games_{3}.pkl".format(aligned, align_strat, num_games, str(ite))
		store_files(umpires, learners, winners, file_name, directory)