예제 #1
0
    def build_normalised_cooperation(self):
        """
        Returns:
        --------

            The list of per turn cooperation counts.
            List of the form:

            [ML1, ML2, ML3..., MLn]

            Where n is the number of players and MLi is a list of the form:

            [pi1, pi2, pi3, ..., pin]

            Where pij is the mean number of
            cooperations per turn played by player i against player j in each
            repetition.
        """
        plist = list(range(self.nplayers))
        normalised_cooperations = [[0 for opponent in plist]
                                   for player in plist]

        for player in plist:
            for opponent in plist:
                coop_counts = []

                if (player, opponent) in self.interactions:
                    repetitions = self.interactions[(player, opponent)]
                    for interaction in repetitions:
                        coop_counts.append(
                            iu.compute_normalised_cooperation(interaction)[0])

                if (opponent, player) in self.interactions:
                    repetitions = self.interactions[(opponent, player)]
                    for interaction in repetitions:
                        coop_counts.append(
                            iu.compute_normalised_cooperation(interaction)[1])

                if ((player, opponent) not in self.interactions) and (
                    (opponent, player) not in self.interactions):
                    coop_counts.append(0)

                # Mean over all reps:
                normalised_cooperations[player][opponent] = mean(coop_counts)

        return normalised_cooperations
예제 #2
0
파일: result_set.py 프로젝트: 314pe/Axelrod
    def build_normalised_cooperation(self):
        """
        Returns:
        --------

            The list of per turn cooperation counts.
            List of the form:

            [ML1, ML2, ML3..., MLn]

            Where n is the number of players and MLi is a list of the form:

            [pi1, pi2, pi3, ..., pin]

            Where pij is the mean number of
            cooperations per turn played by player i against player j in each
            repetition.
        """
        plist = list(range(self.nplayers))
        normalised_cooperations = [[0 for opponent in plist] for player in plist]

        for player in plist:
            for opponent in plist:
                coop_counts = []

                if (player, opponent) in self.interactions:
                    repetitions = self.interactions[(player, opponent)]
                    for interaction in repetitions:
                        coop_counts.append(iu.compute_normalised_cooperation(interaction)[0])

                if (opponent, player) in self.interactions:
                    repetitions = self.interactions[(opponent, player)]
                    for interaction in repetitions:
                        coop_counts.append(iu.compute_normalised_cooperation(interaction)[1])

                if ((player, opponent) not in self.interactions) and ((opponent, player) not in self.interactions):
                    coop_counts.append(0)

                # Mean over all reps:
                normalised_cooperations[player][opponent] = mean(coop_counts)

        return normalised_cooperations
예제 #3
0
    def _update_normalised_cooperation(self, p1, p2, interaction):
        """
        During a read of the data, update the normalised cooperation attribute

        Parameters
        ----------

            p1, p2 : int
                The indices of the first and second player
            interaction : list of tuples
                A list of interactions
        """
        normalised_cooperations = iu.compute_normalised_cooperation(interaction)

        self.normalised_cooperation[p1][p2].append(normalised_cooperations[0])
        self.normalised_cooperation[p2][p1].append(normalised_cooperations[1])
예제 #4
0
    def _update_normalised_cooperation(self, p1, p2, interaction):
        """
        During a read of the data, update the normalised cooperation attribute

        Parameters
        ----------

            p1, p2 : int
                The indices of the first and second player
            interaction : list of tuples
                A list of interactions
        """
        normalised_cooperations = iu.compute_normalised_cooperation(interaction)

        self.normalised_cooperation[p1][p2].append(normalised_cooperations[0])
        self.normalised_cooperation[p2][p1].append(normalised_cooperations[1])
예제 #5
0
 def test_compute_normalised_cooperations(self):
     for inter, coop in zip(self.interactions, self.normalised_cooperations):
         self.assertEqual(coop, iu.compute_normalised_cooperation(inter))
예제 #6
0
파일: match.py 프로젝트: tscizzle/Axelrod
 def normalised_cooperation(self):
     """Returns the count of cooperations by each player per turn"""
     return iu.compute_normalised_cooperation(self.result)
예제 #7
0
 def test_compute_normalised_cooperations(self):
     for inter, coop in zip(self.interactions, self.normalised_cooperations):
         self.assertEqual(coop, iu.compute_normalised_cooperation(inter))
예제 #8
0
파일: match.py 프로젝트: tscizzle/Axelrod
 def normalised_cooperation(self):
     """Returns the count of cooperations by each player per turn"""
     return iu.compute_normalised_cooperation(self.result)
예제 #9
0
    def _update_normalised_cooperation(self, p1, p2, interaction):
        normalised_cooperations = iu.compute_normalised_cooperation(
            interaction)

        self.normalised_cooperation[p1][p2].append(normalised_cooperations[0])
        self.normalised_cooperation[p2][p1].append(normalised_cooperations[1])