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
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
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])
def test_compute_normalised_cooperations(self): for inter, coop in zip(self.interactions, self.normalised_cooperations): self.assertEqual(coop, iu.compute_normalised_cooperation(inter))
def normalised_cooperation(self): """Returns the count of cooperations by each player per turn""" return iu.compute_normalised_cooperation(self.result)
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])