You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/how-to/heterogeneous_matches.rst
+19-24Lines changed: 19 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
.. _heterogeneous-matches:
2
2
3
-
Heterogeneous Matches
4
-
=====================
3
+
Use custom matches
4
+
===================
5
5
6
6
Axelrod Matches are homogeneous by nature but can be extended to utilize additional attributes of heterogeneous players.
7
7
This tutorial indicates how the Axelrod :code:`Match` class can be manipulated in order to play heterogeneous tournaments and Moran processes using country mass as a score modifier.
@@ -17,20 +17,20 @@ The following lines of code creates a list of players from the available demo st
17
17
Using the :code:`setattr()` method, additional attributes can be passed to players to enable access during matches and tournaments without manual modification of individual strategies::
18
18
19
19
>>> def set_player_mass(players, masses):
20
-
>>> """Add mass attribute to player strategy classes to be accessable via self.mass"""
21
-
>>> for player, mass in zip(players, masses):
22
-
>>> setattr(player, "mass", mass)
23
-
>>>
20
+
... """Add mass attribute to player strategy classes to be accessable via self.mass"""
21
+
... for player, mass in zip(players, masses):
22
+
... setattr(player, "mass", mass)
23
+
...
24
24
>>> set_player_mass(players, masses)
25
25
26
26
The :code:`Match` class can be partially altered to enable different behaviour. Here we extend :code:`axl.Match` and overwrite its :code:`final_score_per_turn()`
27
-
function to utilize the player mass attribute als a multiplier for the final score::
27
+
function to utilize the player mass attribute as a multiplier for the final score::
28
28
29
29
>>> class MassBaseMatch(axl.Match):
30
-
>>> """Axelrod Match object with a modified final score function to enable mass to influence the final score as a multiplier"""
... return [player.mass * score for player, score in zip(self.players, base_scores)]
34
34
35
35
We can now create a tournament like we normally would and pass our custom :code:`MassBaseMatch` to the tournament with the :code:`match_class` keyword argument::
36
36
@@ -39,22 +39,17 @@ We can now create a tournament like we normally would and pass our custom :code:
39
39
>>> print(results.ranked_names)
40
40
['Defector', 'Grudger', 'Tit For Tat', 'Cooperator', 'Random: 0.5']
41
41
42
-
Additionally, Moran Processes can also be altered to incorporate heterogeneous matches. In order to
43
-
use our previously defined :code:`MassBaseMatch`, we require one additional change to the :code:`MoranProcess` class::
42
+
Similarly to [Krapohl2020] we are going to assign a mass to each individual for a Moran process.
43
+
This requires us to build a specific match class:
44
44
45
45
>>> classMassBasedMoranProcess(axl.MoranProcess):
46
-
>>> """Axelrod MoranProcess class """
47
-
>>> def __next__(self):
48
-
>>> set_player_mass(self.players, masses)
49
-
>>> super().__next__()
50
-
>>> return self
46
+
... """Axelrod MoranProcess class """
47
+
... def__next__(self):
48
+
... set_player_mass(self.players, masses)
49
+
... super().__next__()
50
+
... returnself
51
51
52
-
With this code snippet we can override the :code:`__next__()` call within the MoranProcess to include :code:`set_player_mass()`
53
-
every round. This ensures that every player has mass attributes after the Moran process is triggered.
54
-
Subsequently, with :code:`super().__next__()` the base MoranProcess :code:`__next__()` call is triggered. This method enables quick
55
-
modifications to tournaments and moran processes with minimal repetitive code.
56
-
57
-
We can now create a Moran process as we normally would, with the inclusion of the match class as a keyword argument::
52
+
In [Krapohl2020] a non standard Moran process is used where the mass of individuals is not reproduced so we will use inheritance to create a new Moran process that keeps the mass of the individuals constant.
Copy file name to clipboardExpand all lines: docs/reference/bibliography.rst
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,7 @@ documentation.
35
35
.. [Hilbe2017] Hilbe, C., Martinez-Vaquero, L. A., Chatterjee K., Nowak M. A. (2017). Memory-n strategies of direct reciprocity, Proceedings of the National Academy of Sciences May 2017, 114 (18) 4715-4720; doi: 10.1073/pnas.1621239114.
36
36
.. [Kuhn2017] Kuhn, Steven, "Prisoner's Dilemma", The Stanford Encyclopedia of Philosophy (Spring 2017 Edition), Edward N. Zalta (ed.), https://plato.stanford.edu/archives/spr2017/entries/prisoner-dilemma/
37
37
.. [Kraines1989] Kraines, David, and Vivian Kraines. "Pavlov and the prisoner's dilemma." Theory and decision 26.1 (1989): 47-79. doi:10.1007/BF00134056
38
+
.. [Krapohl2020] Krapohl, S., Ocelík, V. & Walentek, D.M. The instability of globalization: applying evolutionary game theory to global trade cooperation. Public Choice 188, 31–51 (2021). https://doi.org/10.1007/s11127-020-00799-1
38
39
.. [LessWrong2011] Zoo of Strategies (2011) LessWrong. Available at: http://lesswrong.com/lw/7f2/prisoners_dilemma_tournament_results/
39
40
.. [Li2007] Li, J, How to Design a Strategy to Win an IPD Tournament, in Kendall G., Yao X. and Chong S. (eds.) The iterated prisoner’s dilemma: 20 years on. World Scientific, chapter 4, pp. 29-40, 2007.
40
41
.. [Li2009] Li, J. & Kendall, G. (2009). A Strategy with Novel Evolutionary Features for the Iterated Prisoner’s Dilemma. Evolutionary Computation 17(2): 257–274.
0 commit comments