Skip to content

Commit 160fbc7

Browse files
committed
Merge in origin
2 parents a7b92bd + 68601b5 commit 160fbc7

File tree

4 files changed

+42
-65
lines changed

4 files changed

+42
-65
lines changed

axelrod/result_set.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import csv
33
import itertools
44
from multiprocessing import cpu_count
5-
from typing import List
65
import warnings
76

87
import numpy as np
@@ -427,9 +426,7 @@ def _build_initial_cooperation_rate(self, interactions_series):
427426
with warnings.catch_warnings():
428427
warnings.simplefilter("ignore")
429428
initial_cooperation_rate = list(
430-
np.nan_to_num(
431-
np.array(self.initial_cooperation_count) / interactions_array
432-
)
429+
np.nan_to_num(np.array(self.initial_cooperation_count) / interactions_array)
433430
)
434431
return initial_cooperation_rate
435432

@@ -612,18 +609,6 @@ def __eq__(self, other):
612609
other : axelrod.ResultSet
613610
Another results set against which to check equality
614611
"""
615-
616-
def list_equal_with_nans(v1: List[float], v2: List[float]) -> bool:
617-
"""Matches lists, accounting for NaNs."""
618-
if len(v1) != len(v2):
619-
return False
620-
for i1, i2 in zip(v1, v2):
621-
if np.isnan(i1) and np.isnan(i2):
622-
continue
623-
if i1 != i2:
624-
return False
625-
return True
626-
627612
return all(
628613
[
629614
self.wins == other.wins,
@@ -643,8 +628,8 @@ def list_equal_with_nans(v1: List[float], v2: List[float]) -> bool:
643628
self.cooperating_rating == other.cooperating_rating,
644629
self.good_partner_matrix == other.good_partner_matrix,
645630
self.good_partner_rating == other.good_partner_rating,
646-
list_equal_with_nans(self.eigenmoses_rating, other.eigenmoses_rating),
647-
list_equal_with_nans(self.eigenjesus_rating, other.eigenjesus_rating),
631+
self.eigenmoses_rating == other.eigenmoses_rating,
632+
self.eigenjesus_rating == other.eigenjesus_rating,
648633
]
649634
)
650635

axelrod/strategies/zero_determinant.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,44 @@
66

77

88
class LRPlayer(MemoryOnePlayer):
9-
"""Abstraction for Linear Relation players. These players enforce a linear
10-
difference in stationary payoffs s * (S_xy - l) = S_yx - l, with 0 <= l <= R.
11-
The parameter `s` is called the slope and the parameter `l` the
12-
baseline payoff. For extortionate strategies, the extortion factor is the
13-
inverse of the slope.
14-
15-
This parameterization is Equation 14 in
16-
http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0077886.
17-
See Figure 2 of the article for a more in-depth explanation.
9+
"""
10+
Abstraction for Linear Relation players. These players enforce a linear
11+
difference in stationary payoffs :math:`s (S_{xy} - l) = S_{yx} - l.`
12+
13+
The parameter :math:`s` is called the slope and the parameter :math:`l` the
14+
baseline payoff. For extortionate strategies, the extortion factor
15+
:math:`\chi` is the inverse of the slope :math:`s`.
16+
17+
For the standard prisoner's dilemma where :math:`T > R > P > S` and
18+
:math:`R > (T + S) / 2 > P`, a pair :math:`(l, s)` is enforceable iff
19+
20+
.. math::
21+
:nowrap:
22+
23+
\\begin{eqnarray}
24+
&P &<= l <= R \\\\
25+
&s_{min} &= -\min\\left( \\frac{T - l}{l - S}, \\frac{l - S}{T - l}\\right) <= s <= 1
26+
\\end{eqnarray}
27+
28+
And also that there exists :math:`\\phi` such that
29+
30+
.. math::
31+
:nowrap:
32+
33+
\\begin{eqnarray}
34+
p_1 &= P(C|CC) &= 1 - \\phi (1 - s)(R - l) \\\\
35+
p_2 &= P(C|CD) &= 1 - \\phi (s(l - S) + (T - l)) \\\\
36+
p_3 &= P(C|DC) &= \\phi ((l - S) + s(T - l)) \\\\
37+
p_4 &= P(C|DD) &= \\phi (1 - s)(l - P)
38+
\\end{eqnarray}
39+
40+
41+
These conditions also force :math:`\\phi >= 0`. For a given pair :math:`(l, s)`
42+
there may be multiple such :math:`\\phi`.
43+
44+
This parameterization is Equation 14 in [Hilbe2013]_.
45+
See Figure 2 of the article for a more in-depth explanation. Other game
46+
parameters can alter the relations and bounds above.
1847
1948
Names:
2049

axelrod/tests/unit/test_eigen.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ def test_identity_matrices(self):
1515
self.assertAlmostEqual(evalue, 1)
1616
assert_array_almost_equal(evector, _normalise(numpy.ones(size)))
1717

18-
def test_zero_matrix(self):
19-
mat = numpy.array([[0, 0], [0, 0]])
20-
evector, evalue = principal_eigenvector(mat)
21-
self.assertTrue(numpy.isnan(evalue))
22-
self.assertTrue(numpy.isnan(evector[0]))
23-
self.assertTrue(numpy.isnan(evector[1]))
24-
2518
def test_2x2_matrix(self):
2619
mat = numpy.array([[2, 1], [1, 2]])
2720
evector, evalue = principal_eigenvector(mat)

axelrod/tests/unit/test_resultset.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pandas as pd
88
from axelrod.result_set import create_counter_dict
99
from axelrod.tests.property import prob_end_tournaments, tournaments
10-
from numpy import mean, nan, nanmedian, std
10+
from numpy import mean, nanmedian, std
1111

1212
from dask.dataframe.core import DataFrame
1313
from hypothesis import given, settings
@@ -190,36 +190,6 @@ def test_init(self):
190190
self.assertEqual(rs.players, self.players)
191191
self.assertEqual(rs.num_players, len(self.players))
192192

193-
def _clear_matrix(self, matrix):
194-
for i, row in enumerate(matrix):
195-
for j, _ in enumerate(row):
196-
matrix[i][j] = 0
197-
198-
def test_ne_vectors(self):
199-
rs_1 = axelrod.ResultSet(self.filename, self.players, self.repetitions)
200-
201-
rs_2 = axelrod.ResultSet(self.filename, self.players, self.repetitions)
202-
203-
# A different vector
204-
rs_2.eigenmoses_rating = (-1, -1, -1)
205-
206-
self.assertNotEqual(rs_1, rs_2)
207-
208-
def test_nan_vectors(self):
209-
rs_1 = axelrod.ResultSet(self.filename, self.players, self.repetitions)
210-
# Force a broken eigenmoses, by replacing vengeful_cooperation with
211-
# zeroes.
212-
self._clear_matrix(rs_1.vengeful_cooperation)
213-
rs_1.eigenmoses_rating = rs_1._build_eigenmoses_rating()
214-
215-
rs_2 = axelrod.ResultSet(self.filename, self.players, self.repetitions)
216-
# Force a broken eigenmoses, by replacing vengeful_cooperation with
217-
# zeroes.
218-
self._clear_matrix(rs_2.vengeful_cooperation)
219-
rs_2.eigenmoses_rating = rs_2._build_eigenmoses_rating()
220-
221-
self.assertEqual(rs_1, rs_2)
222-
223193
def test_init_multiprocessing(self):
224194
rs = axelrod.ResultSet(
225195
self.filename,

0 commit comments

Comments
 (0)