Ejemplo n.º 1
0
    def test_tft_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {Point(x=0.0, y=0.0): 3.0,
                     Point(x=0.0, y=0.25): 1.1,
                     Point(x=0.0, y=0.5): 1.08,
                     Point(x=0.0, y=0.75): 1.04,
                     Point(x=0.0, y=1.0): 0.98,
                     Point(x=0.25, y=0.0): 3.0,
                     Point(x=0.25, y=0.25): 2.26,
                     Point(x=0.25, y=0.5): 2.1,
                     Point(x=0.25, y=0.75): 1.66,
                     Point(x=0.25, y=1.0): 1.64,
                     Point(x=0.5, y=0.0): 3.0,
                     Point(x=0.5, y=0.25): 2.5,
                     Point(x=0.5, y=0.5): 2.12,
                     Point(x=0.5, y=0.75): 1.86,
                     Point(x=0.5, y=1.0): 1.88,
                     Point(x=0.75, y=0.0): 3.0,
                     Point(x=0.75, y=0.25): 2.84,
                     Point(x=0.75, y=0.5): 2.36,
                     Point(x=0.75, y=0.75): 2.28,
                     Point(x=0.75, y=1.0): 1.98,
                     Point(x=1.0, y=0.0): 3.0,
                     Point(x=1.0, y=0.25): 2.78,
                     Point(x=1.0, y=0.5): 2.56,
                     Point(x=1.0, y=0.75): 2.44,
                     Point(x=1.0, y=1.0): 2.18}
        af = axl.AshlockFingerprint(axl.TitForTat, self.probe)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key])
Ejemplo n.º 2
0
    def test_majority_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {Point(x=0.0, y=0.0): 3.0,
                     Point(x=0.0, y=0.25): 1.18,
                     Point(x=0.0, y=0.5): 1.98,
                     Point(x=0.0, y=0.75): 1.04,
                     Point(x=0.0, y=1.0): 0.98,
                     Point(x=0.25, y=0.0): 3.0,
                     Point(x=0.25, y=0.25): 2.16,
                     Point(x=0.25, y=0.5): 1.74,
                     Point(x=0.25, y=0.75): 1.96,
                     Point(x=0.25, y=1.0): 2.24,
                     Point(x=0.5, y=0.0): 3.0,
                     Point(x=0.5, y=0.25): 2.46,
                     Point(x=0.5, y=0.5): 2.44,
                     Point(x=0.5, y=0.75): 2.24,
                     Point(x=0.5, y=1.0): 2.74,
                     Point(x=0.75, y=0.0): 3.0,
                     Point(x=0.75, y=0.25): 2.52,
                     Point(x=0.75, y=0.5): 2.16,
                     Point(x=0.75, y=0.75): 2.1,
                     Point(x=0.75, y=1.0): 2.44,
                     Point(x=1.0, y=0.0): 3.0,
                     Point(x=1.0, y=0.25): 2.22,
                     Point(x=1.0, y=0.5): 1.64,
                     Point(x=1.0, y=0.75): 2.08,
                     Point(x=1.0, y=1.0): 2.26}
        af = axl.AshlockFingerprint(axl.GoByMajority, self.probe)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key])
Ejemplo n.º 3
0
    def test_majority_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process.
        test_data = {
            Point(x=0.0, y=0.0): 3.000,
            Point(x=0.0, y=0.25): 1.940,
            Point(x=0.0, y=0.5): 1.130,
            Point(x=0.0, y=0.75): 1.030,
            Point(x=0.0, y=1.0): 0.980,
            Point(x=0.25, y=0.0): 3.000,
            Point(x=0.25, y=0.25): 2.130,
            Point(x=0.25, y=0.5): 1.940,
            Point(x=0.25, y=0.75): 2.060,
            Point(x=0.25, y=1.0): 1.940,
            Point(x=0.5, y=0.0): 3.000,
            Point(x=0.5, y=0.25): 2.300,
            Point(x=0.5, y=0.5): 2.250,
            Point(x=0.5, y=0.75): 2.420,
            Point(x=0.5, y=1.0): 2.690,
            Point(x=0.75, y=0.0): 3.000,
            Point(x=0.75, y=0.25): 2.400,
            Point(x=0.75, y=0.5): 2.010,
            Point(x=0.75, y=0.75): 2.390,
            Point(x=0.75, y=1.0): 2.520,
            Point(x=1.0, y=0.0): 3.000,
            Point(x=1.0, y=0.25): 2.360,
            Point(x=1.0, y=0.5): 1.740,
            Point(x=1.0, y=0.75): 2.260,
            Point(x=1.0, y=1.0): 2.260,
        }

        af = axl.AshlockFingerprint(axl.GoByMajority, axl.TitForTat)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25, progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 4
0
    def test_wsls_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {Point(x=0.0, y=0.0): 3.0,
                     Point(x=0.0, y=0.25): 1.46,
                     Point(x=0.0, y=0.5): 1.54,
                     Point(x=0.0, y=0.75): 1.12,
                     Point(x=0.0, y=1.0): 0.5,
                     Point(x=0.25, y=0.0): 3.0,
                     Point(x=0.25, y=0.25): 2.04,
                     Point(x=0.25, y=0.5): 2.0,
                     Point(x=0.25, y=0.75): 1.34,
                     Point(x=0.25, y=1.0): 0.9,
                     Point(x=0.5, y=0.0): 3.0,
                     Point(x=0.5, y=0.25): 3.0,
                     Point(x=0.5, y=0.5): 2.06,
                     Point(x=0.5, y=0.75): 1.36,
                     Point(x=0.5, y=1.0): 1.0,
                     Point(x=0.75, y=0.0): 3.0,
                     Point(x=0.75, y=0.25): 3.56,
                     Point(x=0.75, y=0.5): 2.06,
                     Point(x=0.75, y=0.75): 3.0,
                     Point(x=0.75, y=1.0): 1.04,
                     Point(x=1.0, y=0.0): 3.0,
                     Point(x=1.0, y=0.25): 4.86,
                     Point(x=1.0, y=0.5): 4.9,
                     Point(x=1.0, y=0.75): 4.9,
                     Point(x=1.0, y=1.0): 1.3}

        af = axl.AshlockFingerprint(self.strategy, self.probe)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key])
Ejemplo n.º 5
0
    def test_tft_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process.
        test_data = {
            Point(x=0.0, y=0.0): 3.000,
            Point(x=0.0, y=0.25): 1.820,
            Point(x=0.0, y=0.5): 1.130,
            Point(x=0.0, y=0.75): 1.050,
            Point(x=0.0, y=1.0): 0.980,
            Point(x=0.25, y=0.0): 3.000,
            Point(x=0.25, y=0.25): 2.440,
            Point(x=0.25, y=0.5): 1.770,
            Point(x=0.25, y=0.75): 1.700,
            Point(x=0.25, y=1.0): 1.490,
            Point(x=0.5, y=0.0): 3.000,
            Point(x=0.5, y=0.25): 2.580,
            Point(x=0.5, y=0.5): 2.220,
            Point(x=0.5, y=0.75): 2.000,
            Point(x=0.5, y=1.0): 1.940,
            Point(x=0.75, y=0.0): 3.000,
            Point(x=0.75, y=0.25): 2.730,
            Point(x=0.75, y=0.5): 2.290,
            Point(x=0.75, y=0.75): 2.310,
            Point(x=0.75, y=1.0): 2.130,
            Point(x=1.0, y=0.0): 3.000,
            Point(x=1.0, y=0.25): 2.790,
            Point(x=1.0, y=0.5): 2.480,
            Point(x=1.0, y=0.75): 2.310,
            Point(x=1.0, y=1.0): 2.180,
        }

        af = axl.AshlockFingerprint(axl.TitForTat(), axl.TitForTat)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25, progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 6
0
    def test_wsls_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process.
        test_data = {
            Point(x=0.0, y=0.0): 3.000,
            Point(x=0.0, y=0.25): 1.710,
            Point(x=0.0, y=0.5): 1.440,
            Point(x=0.0, y=0.75): 1.080,
            Point(x=0.0, y=1.0): 0.500,
            Point(x=0.25, y=0.0): 3.000,
            Point(x=0.25, y=0.25): 2.280,
            Point(x=0.25, y=0.5): 1.670,
            Point(x=0.25, y=0.75): 1.490,
            Point(x=0.25, y=1.0): 0.770,
            Point(x=0.5, y=0.0): 3.000,
            Point(x=0.5, y=0.25): 2.740,
            Point(x=0.5, y=0.5): 2.240,
            Point(x=0.5, y=0.75): 1.730,
            Point(x=0.5, y=1.0): 1.000,
            Point(x=0.75, y=0.0): 3.000,
            Point(x=0.75, y=0.25): 3.520,
            Point(x=0.75, y=0.5): 2.830,
            Point(x=0.75, y=0.75): 1.750,
            Point(x=0.75, y=1.0): 1.250,
            Point(x=1.0, y=0.0): 3.000,
            Point(x=1.0, y=0.25): 4.440,
            Point(x=1.0, y=0.5): 4.410,
            Point(x=1.0, y=0.75): 4.440,
            Point(x=1.0, y=1.0): 1.300,
        }
        af = axl.AshlockFingerprint(axl.WinStayLoseShift(), axl.TitForTat)
        data = af.fingerprint(turns=50, repetitions=2, step=0.25, progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 7
0
def obtain_fingerprint(strategy, turns, repetitions, probe=axl.TitForTat):
    """
	Obtain the fingerprint for a given strategy and save the figure to the
    assets dir
    """
    fp = axl.AshlockFingerprint(strategy, probe)
    fp.fingerprint(turns=turns,
                   repetitions=repetitions,
                   progress_bar=False,
                   processes=0)
    plot = fp.plot()
    plot.savefig("assets/{}.png".format(format_filename(strategy.name)))
    write_data_to_file(fp,
                       "assets/{}.csv".format(format_filename(strategy.name)))
Ejemplo n.º 8
0
    def test_majority_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {
            Point(x=0.25, y=1.0): 2.179,
            Point(x=0.25, y=0.5): 1.9,
            Point(x=0.75, y=0.5): 1.81,
            Point(x=0.25, y=0.25): 2.31,
            Point(x=0.0, y=0.75): 1.03,
            Point(x=0.75, y=1.0): 2.58,
            Point(x=0.5, y=0.25): 2.34,
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 2.4,
            Point(x=1.0, y=0.75): 2.0,
            Point(x=1.0, y=0.5): 1.74,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 2.219,
            Point(x=0.0, y=1.0): 0.98,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.94,
            Point(x=0.0, y=0.5): 1.13,
            Point(x=0.5, y=0.75): 2.6,
            Point(x=0.5, y=0.5): 1.89,
            Point(x=0.75, y=0.75): 2.13,
            Point(x=0.5, y=1.0): 2.7,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.25, y=0.75): 1.859,
            Point(x=1.0, y=1.0): 2.26
        }

        af = axl.AshlockFingerprint(axl.GoByMajority, self.probe)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 9
0
    def test_tft_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {
            Point(x=0.25, y=1.0): 1.63,
            Point(x=0.25, y=0.5): 1.92,
            Point(x=0.75, y=0.5): 2.33,
            Point(x=0.25, y=0.25): 2.31,
            Point(x=0.0, y=0.75): 1.05,
            Point(x=0.75, y=1.0): 2.07,
            Point(x=0.5, y=0.25): 2.6,
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 2.76,
            Point(x=1.0, y=0.75): 2.38,
            Point(x=1.0, y=0.5): 2.58,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 2.72,
            Point(x=0.0, y=1.0): 0.98,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.82,
            Point(x=0.0, y=0.5): 1.13,
            Point(x=0.5, y=0.75): 1.93,
            Point(x=0.5, y=0.5): 2.46,
            Point(x=0.75, y=0.75): 2.3,
            Point(x=0.5, y=1.0): 1.91,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.25, y=0.75): 1.62,
            Point(x=1.0, y=1.0): 2.18
        }

        af = axl.AshlockFingerprint(axl.TitForTat, self.probe)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 10
0
    def test_wsls_fingerprint(self):
        axl.seed(0)  # Fingerprinting is a random process
        test_data = {
            Point(x=0.25, y=1.0): 0.84,
            Point(x=0.25, y=0.5): 1.85,
            Point(x=0.75, y=0.5): 3.01,
            Point(x=0.25, y=0.25): 2.23,
            Point(x=0.0, y=0.75): 1.08,
            Point(x=0.75, y=1.0): 1.14,
            Point(x=0.5, y=0.25): 2.66,
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 3.12,
            Point(x=1.0, y=0.75): 3.57,
            Point(x=1.0, y=0.5): 3.94,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 4.78,
            Point(x=0.0, y=1.0): 0.5,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.71,
            Point(x=0.0, y=0.5): 1.44,
            Point(x=0.5, y=0.75): 1.62,
            Point(x=0.5, y=0.5): 2.77,
            Point(x=0.75, y=0.75): 2.27,
            Point(x=0.5, y=1.0): 1.02,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.25, y=0.75): 1.27,
            Point(x=1.0, y=1.0): 1.3
        }

        af = axl.AshlockFingerprint(self.strategy, self.probe)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 11
0
    def test_majority_fingerprint(self):
        test_data = {
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.6,
            Point(x=0.0, y=0.5): 1.01,
            Point(x=0.0, y=0.75): 1.04,
            Point(x=0.0, y=1.0): 0.98,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.25, y=0.25): 2.12,
            Point(x=0.25, y=0.5): 1.81,
            Point(x=0.25, y=0.75): 2.06,
            Point(x=0.25, y=1.0): 1.86,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.5, y=0.25): 2.4299999999999997,
            Point(x=0.5, y=0.5): 2.37,
            Point(x=0.5, y=0.75): 2.74,
            Point(x=0.5, y=1.0): 2.68,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 2.4299999999999997,
            Point(x=0.75, y=0.5): 1.8399999999999999,
            Point(x=0.75, y=0.75): 2.34,
            Point(x=0.75, y=1.0): 2.46,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 2.12,
            Point(x=1.0, y=0.5): 1.8599999999999999,
            Point(x=1.0, y=0.75): 2.0300000000000002,
            Point(x=1.0, y=1.0): 2.26
        }

        af = axl.AshlockFingerprint(axl.GoByMajority, axl.TitForTat)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False,
                              seed=0)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 12
0
    def test_tft_fingerprint(self):
        test_data = {
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.21,
            Point(x=0.0, y=0.5): 1.01,
            Point(x=0.0, y=0.75): 1.04,
            Point(x=0.0, y=1.0): 0.98,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.25, y=0.25): 2.01,
            Point(x=0.25, y=0.5): 2.05,
            Point(x=0.25, y=0.75): 1.71,
            Point(x=0.25, y=1.0): 1.52,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.5, y=0.25): 2.6500000000000004,
            Point(x=0.5, y=0.5): 2.36,
            Point(x=0.5, y=0.75): 2.1100000000000003,
            Point(x=0.5, y=1.0): 1.8900000000000001,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 2.57,
            Point(x=0.75, y=0.5): 2.51,
            Point(x=0.75, y=0.75): 2.13,
            Point(x=0.75, y=1.0): 2.12,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 2.68,
            Point(x=1.0, y=0.5): 2.51,
            Point(x=1.0, y=0.75): 2.41,
            Point(x=1.0, y=1.0): 2.18
        }

        af = axl.AshlockFingerprint(axl.TitForTat(), axl.TitForTat)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False,
                              seed=0)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 13
0
    def test_wsls_fingerprint(self):
        test_data = {
            Point(x=0.0, y=0.0): 3.0,
            Point(x=0.0, y=0.25): 1.83,
            Point(x=0.0, y=0.5): 1.12,
            Point(x=0.0, y=0.75): 1.04,
            Point(x=0.0, y=1.0): 0.5,
            Point(x=0.25, y=0.0): 3.0,
            Point(x=0.25, y=0.25): 2.12,
            Point(x=0.25, y=0.5): 2.17,
            Point(x=0.25, y=0.75): 1.33,
            Point(x=0.25, y=1.0): 0.77,
            Point(x=0.5, y=0.0): 3.0,
            Point(x=0.5, y=0.25): 2.9299999999999997,
            Point(x=0.5, y=0.5): 2.3600000000000003,
            Point(x=0.5, y=0.75): 1.74,
            Point(x=0.5, y=1.0): 1.05,
            Point(x=0.75, y=0.0): 3.0,
            Point(x=0.75, y=0.25): 2.52,
            Point(x=0.75, y=0.5): 2.79,
            Point(x=0.75, y=0.75): 2.41,
            Point(x=0.75, y=1.0): 1.2,
            Point(x=1.0, y=0.0): 3.0,
            Point(x=1.0, y=0.25): 4.86,
            Point(x=1.0, y=0.5): 4.36,
            Point(x=1.0, y=0.75): 4.05,
            Point(x=1.0, y=1.0): 1.3
        }

        af = axl.AshlockFingerprint(axl.WinStayLoseShift(), axl.TitForTat)
        data = af.fingerprint(turns=50,
                              repetitions=2,
                              step=0.25,
                              progress_bar=False,
                              seed=0)

        for key, value in data.items():
            self.assertAlmostEqual(value, test_data[key], places=2)
Ejemplo n.º 14
0
import axelrod as axl
strats = [axl.TitForTat, axl.WinStayLoseShift, axl.AntiTitForTat, axl.Cooperator, axl.Defector, axl.Cycler('CD'), axl.GoByMajority(75)]
for s in strats:
    probe = axl.TitForTat
    af = axl.AshlockFingerprint(s, probe)
    data = af.fingerprint(turns=500, repetitions=200, step=0.01, processes=0)
    p = af.plot()
    p.savefig('/scratch/c1304586/img/{}-Numerical.pdf'.format(s.name))