Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify (and correct) mean payoff diff scores #671

Merged
merged 3 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions axelrod/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a slightly more concise way to do it!!


@update_progress_bar
Expand Down
8 changes: 8 additions & 0 deletions axelrod/tests/unit/test_resultset.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,14 @@ 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)
Expand Down