|
| 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`. |
0 commit comments