Esempio n. 1
0
    def score_history(self) -> Tuple[List[str], np.ndarray]:
        """
        Compute the history of the scores for every agent.

        To do so, we need to simulate the game again, by settling transactions one by one
        and get the scores after every transaction.

        :return: a matrix of shape (nb_transactions + 1, nb_agents), where every row i contains the scores
                 after transaction i (i=0 is a row with the initial scores.)
        """
        nb_transactions = len(self.game.transactions)
        nb_agents = self.game.configuration.nb_agents
        result = np.zeros((nb_transactions + 1, nb_agents))

        temp_game = Game(self.game.configuration, self.game.initialization)

        # initial scores
        scores_dict = temp_game.get_scores()
        result[0, :] = list(scores_dict.values())
        keys = list(scores_dict.keys())

        # compute the partial scores for every agent after every transaction
        # (remember that indexes of the transaction start from one, because index 0 is reserved for the initial scores)
        for idx, tx in enumerate(self.game.transactions):
            temp_game.settle_transaction(tx)
            scores_dict = temp_game.get_scores()
            result[idx + 1, :] = list(scores_dict.values())

        return keys, result
Esempio n. 2
0
    def adjusted_score(self) -> Tuple[List[str], np.ndarray]:
        """
        Compute the adjusted score of each agent.

        :return: a matrix of shape (1, nb_agents), where every column i contains the score of the agent.
        """
        nb_agents = self.game.configuration.nb_agents
        current_scores = np.zeros((1, nb_agents), dtype=np.float32)

        eq_agent_states = dict((
            agent_pbk,
            AgentState(
                self.game.initialization.eq_money_holdings[i],
                [int(h) for h in self.game.initialization.eq_good_holdings[i]],
                self.game.initialization.utility_params[i],
            ),
        ) for agent_pbk, i in zip(
            self.game.configuration.agent_pbks,
            range(self.game.configuration.nb_agents),
        ))  # type: Dict[str, AgentState]

        result = np.zeros((1, nb_agents), dtype=np.float32)

        eq_scores = np.zeros((1, nb_agents), dtype=np.float32)
        eq_scores[0, :] = [
            eq_agent_state.get_score()
            for eq_agent_state in eq_agent_states.values()
        ]

        temp_game = Game(self.game.configuration, self.game.initialization)

        # initial scores
        initial_scores = np.zeros((1, nb_agents), dtype=np.float32)
        scores_dict = temp_game.get_scores()
        initial_scores[0, :] = list(scores_dict.values())
        keys = list(scores_dict.keys())
        current_scores = np.zeros((1, nb_agents), dtype=np.float32)
        current_scores[0, :] = initial_scores[0, :]

        # compute the partial scores for every agent after every transaction
        # (remember that indexes of the transaction start from one, because index 0 is reserved for the initial scores)
        for idx, tx in enumerate(self.game.transactions):
            temp_game.settle_transaction(tx)
            scores_dict = temp_game.get_scores()
            current_scores[0, :] = list(scores_dict.values())

        result[0, :] = np.divide(
            np.subtract(current_scores, initial_scores),
            np.subtract(eq_scores, initial_scores),
        )
        result = np.transpose(result)

        return keys, result
Esempio n. 3
0
    def test_baseline_agent_score_does_not_decrease(self):
        """Test that all the baseline agent scores do not decrease after each transaction."""
        finished_game = self.tac_controller.game_handler.current_game
        game_configuration = finished_game.configuration
        game_initialization = finished_game.initialization
        game = Game(game_configuration, game_initialization)

        scores_dict = game.get_scores()
        current_score = np.asarray(list(scores_dict.values()))
        next_scores = None
        for tx in finished_game.transactions:
            game.settle_transaction(tx)
            scores_dict = game.get_scores()
            next_scores = np.asarray(list(scores_dict.values()))
            assert not (next_scores < current_score).any()
            current_score = next_scores
Esempio n. 4
0
    def get_initial_scores(self) -> Dict[str, float]:
        """
        Get the initial score for all agents.

        :return: dictionary mapping agent name to initial score.
        """
        temp_game = Game(self.game.configuration, self.game.initialization)
        scores_dict = {
            self.game.configuration.agent_pbk_to_name[agent_pbk]: score
            for agent_pbk, score in temp_game.get_scores().items()
        }
        return scores_dict