From 0842ac14836534dedb59421c19ccc4172398395d Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Fri, 22 Jul 2016 14:40:50 +0100 Subject: [PATCH 1/3] Simplify calculation of payoff_diffs_mean Now calculated as an actual mean of the score_diffs. --- axelrod/result_set.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/axelrod/result_set.py b/axelrod/result_set.py index 6ec59ae60..0a8b4fb25 100644 --- a/axelrod/result_set.py +++ b/axelrod/result_set.py @@ -464,28 +464,8 @@ def build_payoff_diffs_means(self): Where pij is the mean difference of the scores per turn between player i and j in repetition m. """ - plist = list(range(self.nplayers)) - payoff_diffs_means = [[0 for opponent in plist] for player in plist] - - for player in plist: - for opponent in plist: - diffs = [] - for index_pair, repetitions in self.interactions.items(): - if (player, opponent) == index_pair: - for interaction in repetitions: - scores = iu.compute_final_score_per_turn(interaction, - self.game) - diffs.append(scores[0] - scores[1]) - elif (opponent, player) == index_pair: - for interaction in repetitions: - scores = iu.compute_final_score_per_turn(interaction, - self.game) - diffs.append(scores[1] - scores[0]) - if diffs: - payoff_diffs_means[player][opponent] = mean(diffs) - else: - payoff_diffs_means[player][opponent] = 0 - + payoff_diffs_means = [[mean(diff) for diff in player] + for player in self.score_diffs] return payoff_diffs_means @update_progress_bar From 1eccfb0eac3746a714d711ad0271ded4f30d8981 Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Fri, 22 Jul 2016 15:06:08 +0100 Subject: [PATCH 2/3] Add test for bug. --- axelrod/tests/unit/test_resultset.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/axelrod/tests/unit/test_resultset.py b/axelrod/tests/unit/test_resultset.py index 5a81687b5..d263d6222 100644 --- a/axelrod/tests/unit/test_resultset.py +++ b/axelrod/tests/unit/test_resultset.py @@ -364,6 +364,13 @@ def test_eigenmoses_rating(self): for j, rate in enumerate(rs.eigenmoses_rating): self.assertAlmostEqual(rate, self.expected_eigenmoses_rating[j]) + def test_self_interaction_for_random_strategies(self): + # Based on /~https://github.com/Axelrod-Python/Axelrod/issues/670 + axelrod.seed(0) + players = [s() for s in axelrod.demo_strategies] + tournament = axelrod.Tournament(players, repetitions=2, turns=5) + results = tournament.play() + self.assertEqual(results.payoff_diffs_means[-1][-1], 1.0) class TestResultSetFromFile(unittest.TestCase): tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False) From 360758cf09a42361ef24556c2610cf5d2004fafe Mon Sep 17 00:00:00 2001 From: Vince Knight Date: Fri, 22 Jul 2016 15:07:55 +0100 Subject: [PATCH 3/3] PEP8 --- axelrod/tests/unit/test_resultset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/axelrod/tests/unit/test_resultset.py b/axelrod/tests/unit/test_resultset.py index d263d6222..dccd3e8f1 100644 --- a/axelrod/tests/unit/test_resultset.py +++ b/axelrod/tests/unit/test_resultset.py @@ -372,6 +372,7 @@ def test_self_interaction_for_random_strategies(self): results = tournament.play() self.assertEqual(results.payoff_diffs_means[-1][-1], 1.0) + class TestResultSetFromFile(unittest.TestCase): tmp_file = tempfile.NamedTemporaryFile(mode='w', delete=False) tournament = axelrod.Tournament(