Пример #1
0
    def _calculate_results(self, interactions):
        results = []

        scores = iu.compute_final_score(interactions, self.game)
        results.append(scores)

        score_diffs = scores[0] - scores[1], scores[1] - scores[0]
        results.append(score_diffs)

        turns = len(interactions)
        results.append(turns)

        score_per_turns = iu.compute_final_score_per_turn(
            interactions, self.game)
        results.append(score_per_turns)

        score_diffs_per_turns = score_diffs[0] / turns, score_diffs[1] / turns
        results.append(score_diffs_per_turns)

        initial_coops = tuple(
            map(bool, iu.compute_cooperations(interactions[:1])))
        results.append(initial_coops)

        cooperations = iu.compute_cooperations(interactions)
        results.append(cooperations)

        state_distribution = iu.compute_state_distribution(interactions)
        results.append(state_distribution)

        state_to_action_distributions = iu.compute_state_to_action_distribution(
            interactions)
        results.append(state_to_action_distributions)

        winner_index = iu.compute_winner_index(interactions, self.game)
        results.append(winner_index)

        return results
Пример #2
0
    def _calculate_results(self, interactions):
        results = []

        scores = iu.compute_final_score(interactions, self.game)
        results.append(scores)

        score_diffs = scores[0] - scores[1], scores[1] - scores[0]
        results.append(score_diffs)

        turns = len(interactions)
        results.append(turns)

        score_per_turns = iu.compute_final_score_per_turn(interactions, self.game)
        results.append(score_per_turns)

        score_diffs_per_turns = score_diffs[0] / turns, score_diffs[1] / turns
        results.append(score_diffs_per_turns)

        initial_coops = tuple(map(bool, iu.compute_cooperations(interactions[:1])))
        results.append(initial_coops)

        cooperations = iu.compute_cooperations(interactions)
        results.append(cooperations)

        state_distribution = iu.compute_state_distribution(interactions)
        results.append(state_distribution)

        state_to_action_distributions = iu.compute_state_to_action_distribution(
            interactions
        )
        results.append(state_to_action_distributions)

        winner_index = iu.compute_winner_index(interactions, self.game)
        results.append(winner_index)

        return results
Пример #3
0
 def test_compute_state_distribution(self):
     for inter, dist in zip(self.interactions, self.state_distribution):
         self.assertEqual(dist, iu.compute_state_distribution(inter))
Пример #4
0
 def state_distribution(self):
     """
     Returns the count of each state for a set of interactions.
     """
     return iu.compute_state_distribution(self.result)
Пример #5
0
 def test_compute_state_distribution(self):
     for inter, dist in zip(self.interactions, self.state_distribution):
         self.assertEqual(dist, iu.compute_state_distribution(inter))
Пример #6
0
    def _build_score_related_metrics(self,
                                     progress_bar=False,
                                     keep_interactions=False):
        """
        Read the data and carry out all relevant calculations.

        Parameters
        ----------
            progress_bar : bool
                Whether or not to display a progress bar
            keep_interactions : bool
                Whether or not to lad the interactions in to memory
        """
        match_chunks = self.read_match_chunks(progress_bar)

        for match in match_chunks:
            p1, p2 = int(match[0][0]), int(match[0][1])

            for repetition, record in enumerate(match):
                interaction = record[4:]

                if keep_interactions:
                    try:
                        self.interactions[(p1, p2)].append(interaction)
                    except KeyError:
                        self.interactions[(p1, p2)] = [interaction]

                scores_per_turn = iu.compute_final_score_per_turn(
                    interaction, game=self.game)
                cooperations = iu.compute_cooperations(interaction)
                state_counter = iu.compute_state_distribution(interaction)

                self._update_match_lengths(repetition, p1, p2, interaction)
                self._update_payoffs(p1, p2, scores_per_turn)
                self._update_score_diffs(repetition, p1, p2, scores_per_turn)
                self._update_normalised_cooperation(p1, p2, interaction)

                if p1 != p2:  # Anything that ignores self interactions

                    for player in [p1, p2]:
                        self.total_interactions[player] += 1

                    self._update_match_lengths(repetition, p2, p1, interaction)
                    self._update_wins(repetition, p1, p2, interaction)
                    self._update_scores(repetition, p1, p2, interaction)
                    self._update_normalised_scores(repetition, p1, p2,
                                                   scores_per_turn)
                    self._update_cooperation(p1, p2, cooperations)
                    initial_coops = iu.compute_cooperations(interaction[:1])
                    self._update_initial_cooperation_count(
                        p1, p2, initial_coops)
                    self._update_state_distribution(p1, p2, state_counter)
                    self._update_good_partner_matrix(p1, p2, cooperations)

        if progress_bar:
            self.progress_bar = tqdm.tqdm(total=12 + 2 * self.nplayers,
                                          desc="Finishing")
        self._summarise_normalised_scores()
        self._summarise_normalised_cooperation()

        self.ranking = self._build_ranking()
        self.normalised_state_distribution = self._build_normalised_state_distribution(
        )
        self.ranked_names = self._build_ranked_names()
        self.payoff_matrix = self._build_payoff_matrix()
        self.payoff_stddevs = self._build_payoff_stddevs()
        self.payoff_diffs_means = self._build_payoff_diffs_means()
        self.vengeful_cooperation = self._build_vengeful_cooperation()
        self.cooperating_rating = self._build_cooperating_rating()
        self.initial_cooperation_rate = self._build_initial_cooperation_rate()
        self.good_partner_rating = self._build_good_partner_rating()
        self.eigenjesus_rating = self._build_eigenjesus_rating()
        self.eigenmoses_rating = self._build_eigenmoses_rating()

        if progress_bar:
            self.progress_bar.close()
Пример #7
0
    def _build_score_related_metrics(self, progress_bar=False,
                                     keep_interactions=False):
        """
        Read the data and carry out all relevant calculations.

        Parameters
        ----------
            progress_bar : bool
                Whether or not to display a progress bar
            keep_interactions : bool
                Whether or not to lad the interactions in to memory
        """
        match_chunks = self.read_match_chunks(progress_bar)

        for match in match_chunks:
            p1, p2 = int(match[0][0]), int(match[0][1])

            for repetition, record in enumerate(match):
                interaction = record[4:]

                if keep_interactions:
                    try:
                        self.interactions[(p1, p2)].append(interaction)
                    except KeyError:
                        self.interactions[(p1, p2)] = [interaction]

                scores_per_turn = iu.compute_final_score_per_turn(interaction,
                                                                 game=self.game)
                cooperations = iu.compute_cooperations(interaction)
                state_counter = iu.compute_state_distribution(interaction)

                self._update_match_lengths(repetition, p1, p2, interaction)
                self._update_payoffs(p1, p2, scores_per_turn)
                self._update_score_diffs(repetition, p1, p2, scores_per_turn)
                self._update_normalised_cooperation(p1, p2, interaction)

                if p1 != p2:  # Anything that ignores self interactions

                    for player in [p1, p2]:
                        self.total_interactions[player] += 1

                    self._update_match_lengths(repetition, p2, p1, interaction)
                    self._update_wins(repetition, p1, p2, interaction)
                    self._update_scores(repetition, p1, p2, interaction)
                    self._update_normalised_scores(repetition, p1, p2,
                                                   scores_per_turn)
                    self._update_cooperation(p1, p2, cooperations)
                    self._update_state_distribution(p1, p2, state_counter)
                    self._update_good_partner_matrix(p1, p2, cooperations)

        if progress_bar:
            self.progress_bar = tqdm.tqdm(total=11 + 2 * self.nplayers,
                                          desc="Finishing")
        self._summarise_normalised_scores()
        self._summarise_normalised_cooperation()

        self.ranking = self._build_ranking()
        self.normalised_state_distribution = self._build_normalised_state_distribution()
        self.ranked_names = self._build_ranked_names()
        self.payoff_matrix = self._build_payoff_matrix()
        self.payoff_stddevs = self._build_payoff_stddevs()
        self.payoff_diffs_means = self._build_payoff_diffs_means()
        self.vengeful_cooperation = self._build_vengeful_cooperation()
        self.cooperating_rating = self._build_cooperating_rating()
        self.good_partner_rating = self._build_good_partner_rating()
        self.eigenjesus_rating = self._build_eigenjesus_rating()
        self.eigenmoses_rating = self._build_eigenmoses_rating()

        if progress_bar:
            self.progress_bar.close()
Пример #8
0
 def state_distribution(self):
     """
     Returns the count of each state for a set of interactions.
     """
     return iu.compute_state_distribution(self.result)