Skip to content

Commit d80465f

Browse files
Merge pull request #660 from Axelrod-Python/652
Adding documentation for result set
2 parents f38cfad + 162ee01 commit d80465f

File tree

8 files changed

+249
-39
lines changed

8 files changed

+249
-39
lines changed

axelrod/result_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def build_cooperating_rating(self):
590590
Returns:
591591
--------
592592
593-
The list of cooperation counts
593+
The list of cooperation ratings
594594
List of the form:
595595
596596
[ML1, ML2, ML3..., MLn]

docs/tutorials/further_topics/morality_metrics.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _morality-metrics:
2+
13
Morality Metrics
24
================
35

docs/tutorials/further_topics/probabilistict_end_tournaments.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ probability::
1111
>>> tournament = axl.ProbEndTournament(players, prob_end=0.5)
1212

1313

14-
We can view the results in a similar way as for described in
15-
:ref:`payoff-matrix`::
14+
We can view the results in a similar way as described in
15+
:ref:`tournament-results`::
1616

1717
>>> results = tournament.play()
1818
>>> m = results.payoff_matrix

docs/tutorials/getting_started/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Contents:
1212
installation.rst
1313
match.rst
1414
tournament.rst
15-
payoff_matrix.rst
15+
tournament_results.rst
1616
interactions.rst
1717
visualising_results.rst
1818
moran.rst

docs/tutorials/getting_started/interactions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To access the detailed interaction results we create a tournament as usual
1414
>>> tournament = axl.Tournament(players, turns=3, repetitions=1)
1515
>>> results = tournament.play()
1616

17-
The tournament object has an 'interactions' attribute which contains all the
17+
The result set object has an 'interactions' attribute which contains all the
1818
interactions between the players.
1919
(Actually, it's a list of lists: one list for each repetition which, in
2020
turn, has a list of Match objects). These can be used to view the history of the

docs/tutorials/getting_started/payoff_matrix.rst

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
.. _tournament-results:
2+
3+
Accessing tournament results
4+
============================
5+
6+
This tutorial will show you how to access the various results of a tournament:
7+
8+
- Wins: the number of matches won by each player
9+
- Match lengths: the number of turns of each match played by each player
10+
(relevant for tournaments like probabilistic ending tournaments).
11+
- Scores: the total scores of each player.
12+
- Normalised scores: the scores normalised by matches played and turns.
13+
- Ranking: ranking of players based on median score.
14+
- Ranked names: names of players in ranked order.
15+
- Payoffs: average payoff per turn of each player.
16+
- Payoff matrix: the payoff matrix showing the payoffs of each row player
17+
against each column player.
18+
- Payoff standard deviation: the standard deviation of the payoffs matrix.
19+
- Score differences: the score difference between each player.
20+
- Payoff difference means: the mean score differences.
21+
- Cooperation counts: the number of times each player cooperated.
22+
- Normalised cooperation: cooperation count per turn.
23+
- Cooperation rating: cooperation rating of each player
24+
- Vengeful cooperation: a morality metric from the literature (see
25+
:ref:`morality-metrics`).
26+
- Good partner matrix: a morality metric from the literature.
27+
- Good partner rating: a morality metric from the literature.
28+
- Eigenmoses rating: a morality metric from the literature.
29+
- Eigenjesus rating: a morality metric from the literature.
30+
31+
As shown in :ref:`creating_tournaments` let us create a tournament::
32+
33+
>>> import axelrod as axl
34+
>>> players = [axl.Cooperator(), axl.Defector(),
35+
... axl.TitForTat(), axl.Grudger()]
36+
>>> tournament = axl.Tournament(players, turns=10, repetitions=3)
37+
>>> results = tournament.play()
38+
39+
Wins
40+
----
41+
42+
This gives the number of wins obtained by each player::
43+
44+
>>> results.wins
45+
[[0, 0, 0], [3, 3, 3], [0, 0, 0], [0, 0, 0]]
46+
47+
48+
The :code:`Defector` is the only player to win any matches (all other matches
49+
are ties).
50+
51+
Match lengths
52+
-------------
53+
54+
This gives the length of the matches played by each player::
55+
56+
>>> import pprint # Nicer formatting of output
57+
>>> pprint.pprint(results.match_lengths)
58+
[[[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]],
59+
[[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]],
60+
[[10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10], [10, 10, 10, 10]]]
61+
62+
Every player plays 200 turns against every other player for every repetition of
63+
the tournament.
64+
65+
Scores
66+
------
67+
68+
This gives all the total tournament scores (per player and per repetition)::
69+
70+
>>> results.scores
71+
[[60, 60, 60], [78, 78, 78], [69, 69, 69], [69, 69, 69]]
72+
73+
Normalised scores
74+
-----------------
75+
76+
This gives the scores, averaged per opponent and turns::
77+
78+
>>> results.normalised_scores # doctest: +SKIP
79+
[[2.0, 2.0, 2.0], [2.6, 2.6, 2.6], [2.3, 2.3, 2.3], [2.3, 2.3, 2.3]]
80+
81+
We see that Cooperator got on average a score of 2 per turn per opponent.
82+
Note: Here using string representation to deal with floating point numbers::
83+
84+
>>> results.normalised_scores[0]
85+
[2.0, 2.0, 2.0]
86+
87+
Ranking
88+
-------
89+
90+
This gives the ranked index of each player::
91+
92+
>>> results.ranking
93+
[1, 2, 3, 0]
94+
95+
The first player has index 1 (:code:`Defector`) and the last has index 0
96+
(:code:`Cooperator`).
97+
98+
Ranked names
99+
------------
100+
101+
This gives the player names in ranked order::
102+
103+
>>> results.ranked_names
104+
['Defector', 'Tit For Tat', 'Grudger', 'Cooperator']
105+
106+
107+
Payoffs
108+
-------
109+
110+
This gives for each player, against each opponent every payoff received for
111+
each repetition::
112+
113+
>>> pprint.pprint(results.payoffs)
114+
[[[3.0, 3.0, 3.0], [0.0, 0.0, 0.0], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]],
115+
[[5.0, 5.0, 5.0], [1.0, 1.0, 1.0], [1.4, 1.4, 1.4], [1.4, 1.4, 1.4]],
116+
[[3.0, 3.0, 3.0], [0.9, 0.9, 0.9], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]],
117+
[[3.0, 3.0, 3.0], [0.9, 0.9, 0.9], [3.0, 3.0, 3.0], [3.0, 3.0, 3.0]]]
118+
119+
120+
Payoff matrix
121+
-------------
122+
123+
This gives the mean payoff of each player against every opponent::
124+
125+
>>> pprint.pprint(results.payoff_matrix) # doctest: +SKIP
126+
[[3.0, 0.0, 3.0, 3.0],
127+
[5.0, 1.0, 1.4, 1.4],
128+
[3.0, 0.9, 3.0, 3.0],
129+
[3.0, 0.9, 3.0, 3.0]]
130+
131+
We see that the :code:`Cooperator` gets a mean score of 3 against all players
132+
except the :code:`Defector`::
133+
134+
>>> results.payoff_matrix[0]
135+
[3.0, 0.0, 3.0, 3.0]
136+
137+
Payoff standard deviation
138+
-------------------------
139+
140+
This gives the standard deviation of the payoff of each player against
141+
every opponent::
142+
143+
>>> pprint.pprint(results.payoff_stddevs) # doctest: +SKIP
144+
[[0.0, 0.0, 0.0, 0.0],
145+
[0.0, 0.0, 2.2, 2.2],
146+
[0.0, 0.0, 0.0, 0.0],
147+
[0.0, 0.0, 0.0, 0.0]]
148+
149+
We see that there is no variation for the payoff for :code:`Cooperator`::
150+
151+
>>> results.payoff_stddevs[0]
152+
[0.0, 0.0, 0.0, 0.0]
153+
154+
Score differences
155+
-----------------
156+
157+
This gives the score difference for each player against each opponent for every
158+
repetition::
159+
160+
>>> pprint.pprint(results.score_diffs) # doctest: +SKIP
161+
[[[0.0, 0.0, 0.0], [-5.0, -5.0, -5.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
162+
[[5.0, 5.0, 5.0], [0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]],
163+
[[0.0, 0.0, 0.0], [-0.5, -0.5, -0.5], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],
164+
[[0.0, 0.0, 0.0], [-0.5, -0.5, -0.5], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]
165+
166+
We see that :code:`Cooperator` has no difference in score with all players
167+
except against the :code:`Defector`::
168+
169+
>>> results.score_diffs[0]
170+
[[0.0, 0.0, 0.0], [-5.0, -5.0, -5.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
171+
172+
Payoff difference means
173+
-----------------------
174+
175+
This gives the mean payoff differences over each repetition::
176+
177+
>>> pprint.pprint(results.payoff_diffs_means) # doctest: +SKIP
178+
[[0.0, -5.0, 0.0, 0.0],
179+
[5.0, 0.0, 0.49999999999999983, 0.49999999999999983],
180+
[0.0, -0.49999999999999983, 0.0, 0.0],
181+
[0.0, -0.49999999999999983, 0.0, 0.0]]
182+
183+
Here is the mean payoff difference for the :code:`Cooperator` strategy, shows
184+
that it has no difference with all players except against the
185+
:code:`Defector`::
186+
187+
>>> results.payoff_diffs_means[0]
188+
[0.0, -5.0, 0.0, 0.0]
189+
190+
Cooperation counts
191+
------------------
192+
193+
This gives a total count of cooperation for each player against each opponent::
194+
195+
>>> results.cooperation
196+
[[0, 30, 30, 30], [0, 0, 0, 0], [30, 3, 0, 30], [30, 3, 30, 0]]
197+
198+
Normalised cooperation
199+
----------------------
200+
201+
This gives the average rate of cooperation against each opponent::
202+
203+
>>> pprint.pprint(results.normalised_cooperation) # doctest: +SKIP
204+
[[1.0, 1.0, 1.0, 1.0],
205+
[0.0, 0.0, 0.0, 0.0],
206+
[1.0, 0.1, 1.0, 1.0],
207+
[1.0, 0.1, 1.0, 1.0]]
208+
209+
We see that :code:`Cooperator` for all the rounds (as expected)::
210+
211+
>>> results.normalised_cooperation[0]
212+
[1.0, 1.0, 1.0, 1.0]
213+
214+
Morality Metrics
215+
----------------
216+
217+
The following morality metrics are available, they are calculated as a function
218+
of the cooperation rating::
219+
220+
>>> results.cooperating_rating
221+
[1.0, 0.0, 0.7, 0.7]
222+
>>> pprint.pprint(results.vengeful_cooperation) # doctest: +SKIP
223+
[[1.0, 1.0, 1.0, 1.0],
224+
[-1.0, -1.0, -1.0, -1.0],
225+
[1.0, -0.8, 1.0, 1.0],
226+
[1.0, -0.78 1.0, 1.0]]
227+
>>> pprint.pprint(results.good_partner_matrix)
228+
[[0, 3, 3, 3], [0, 0, 0, 0], [3, 3, 0, 3], [3, 3, 3, 0]]
229+
>>> pprint.pprint(results.good_partner_rating)
230+
[1.0, 0.0, 1.0, 1.0]
231+
>>> pprint.pprint(results.eigenmoses_rating) # doctest: +SKIP
232+
[0.37956816961269385,
233+
-0.37956816961269385,
234+
0.5965970202882925,
235+
0.5965970202882925]
236+
>>> pprint.pprint(results.eigenjesus_rating) # doctest: +SKIP
237+
[0.5773502691896258, 0.0, 0.5773502691896258, 0.5773502691896258]
238+
239+
For more information about these see :ref:`morality-metrics`.

docs/tutorials/getting_started/visualising_results.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ We can view the distributions of wins for each strategy::
4343
Visualising the payoff matrix
4444
-----------------------------
4545

46-
We can also easily view the payoff matrix described in :doc:`payoff_matrix`, this
47-
becomes particularly useful when viewing the outputs of tournaments with a large
48-
number of strategies::
46+
We can also easily view the payoff matrix described in
47+
:ref:`tournament-results`, this becomes particularly useful when viewing the
48+
outputs of tournaments with a large number of strategies::
4949

5050
>>> p = plot.payoff()
5151
>>> p.show()

0 commit comments

Comments
 (0)