Beispiel #1
0
 def test_evidence_1vs1(self):
     ta = [ttt.Rating(ttt.Gaussian(25., 1e-7))]
     tb = [ttt.Rating(ttt.Gaussian(25., 1e-7))]
     g = ttt.Game([ta, tb], [0, 0], 0.25)
     self.assertAlmostEqual(g.evidence, 0.25, 3)
     g = ttt.Game([ta, tb], [0, 1], 0.25)
     self.assertAlmostEqual(g.evidence, 0.375, 3)
    def test_1vs1vs1(self):
        [a], [b], [c] = ttt.Game(
            [[ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]],
            [1, 2, 0]).posteriors()
        self.assertAlmostEqual(a.mu, 25.000000, 5)
        self.assertAlmostEqual(a.sigma, 6.238469796, 5)
        self.assertAlmostEqual(b.mu, 31.3113582213, 5)
        self.assertAlmostEqual(b.sigma, 6.69881865, 5)
        self.assertAlmostEqual(c.mu, 18.6886417787, 5)

        [a], [b], [c] = ttt.Game(
            [[ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6,
                         25.0 / 300)]]).posteriors()
        self.assertAlmostEqual(b.mu, 25.000000, 5)
        self.assertAlmostEqual(b.sigma, 6.238469796, 5)
        self.assertAlmostEqual(a.mu, 31.3113582213, 5)
        self.assertAlmostEqual(a.sigma, 6.69881865, 5)
        self.assertAlmostEqual(c.mu, 18.6886417787, 5)

        [a], [b], [c] = ttt.Game(
            [[ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]],
            [1, 2, 0], 0.5).posteriors()
        self.assertAlmostEqual(a.mu, 25.000, 3)
        self.assertAlmostEqual(a.sigma, 6.093, 3)
        self.assertAlmostEqual(b.mu, 33.379, 3)
        self.assertAlmostEqual(b.sigma, 6.484, 3)
        self.assertAlmostEqual(c.mu, 16.621, 3)
    def test_NvsN_Draw(self):
        ta = [
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300),
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300)
        ]
        tb = [ttt.Player(ttt.Gaussian(30., 2.), 25.0 / 6, 25.0 / 300)]
        [a, b], [c] = ttt.Game([ta, tb], [0, 0], 0.25).posteriors()
        self.assertAlmostEqual(a.mu, 15.000, 3)
        self.assertAlmostEqual(a.sigma, 0.9916, 3)
        self.assertAlmostEqual(b.mu, 15.000, 3)
        self.assertAlmostEqual(b.sigma, 0.9916, 3)
        self.assertAlmostEqual(c.mu, 30.000, 3)
        self.assertAlmostEqual(c.sigma, 1.9320, 3)

        [a, b], [c] = ttt.Game([ta, tb], [1, 0], 0.0).posteriors()
        self.assertAlmostEqual(a.mu, 15.105, 3)
        self.assertAlmostEqual(a.sigma, 0.995, 3)

        ta = [
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300),
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300)
        ]
        tb = [
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300),
            ttt.Player(ttt.Gaussian(15., 1.), 25.0 / 6, 25.0 / 300)
        ]
        [a, b], [c, d] = ttt.Game([ta, tb], [1, 0], 0.0).posteriors()
        self.assertAlmostEqual(a.mu, 15.093, 3)
        self.assertAlmostEqual(a.sigma, 0.996, 3)
        self.assertAlmostEqual(c.mu, 14.907, 3)
        self.assertAlmostEqual(c.sigma, 0.996, 3)
 def test_evidence_1vs1(self):
     ta = [ttt.Player(ttt.Gaussian(25., 1e-7), 25.0 / 6, 25.0 / 300)]
     tb = [ttt.Player(ttt.Gaussian(25., 1e-7), 25.0 / 6, 25.0 / 300)]
     g = ttt.Game([ta, tb], [0, 0], 0.25)
     self.assertAlmostEqual(g.evidence, 0.25, 3)
     g = ttt.Game([ta, tb], [1, 0], 0.25)
     self.assertAlmostEqual(g.evidence, 0.375, 3)
Beispiel #5
0
 def test_1vs1_draw(self):
     [a], [b] = ttt.Game([[ttt.Rating()], [ttt.Rating()]], [0, 0],
                         0.25).posteriors
     self.assertAlmostEqual(a.mu, 25.000, 2)
     self.assertAlmostEqual(a.sigma, 6.469, 2)
     self.assertAlmostEqual(b.mu, 25.000, 2)
     self.assertAlmostEqual(b.sigma, 6.469, 2)
     ta = [ttt.Rating(ttt.Gaussian(25., 3.))]
     tb = [ttt.Rating(ttt.Gaussian(29., 2.))]
     [a], [b] = ttt.Game([ta, tb], [0, 0], 0.25).posteriors
     self.assertAlmostEqual(a.mu, 25.736, 2)
     self.assertAlmostEqual(a.sigma, 2.710, 2)
     self.assertAlmostEqual(b.mu, 28.672, 2)
     self.assertAlmostEqual(b.sigma, 1.916, 2)
Beispiel #6
0
    def test_1vs1(self):
        ta = [ttt.Rating()]
        tb = [ttt.Rating()]
        g = ttt.Game([ta, tb], [1, 0])
        [a], [b] = g.posteriors
        self.assertAlmostEqual(a.mu, 20.79477925612302, 4)
        self.assertAlmostEqual(b.mu, 29.20522074387697, 4)
        self.assertAlmostEqual(a.sigma, 7.194481422570443, places=4)

        g = ttt.Game([[ttt.Rating(ttt.Gaussian(29, 1))], [ttt.Rating()]],
                     [1, 0], 0.0)
        [a], [b] = g.posteriors
        self.assertAlmostEqual(a.mu, 28.896, places=2)
        self.assertAlmostEqual(a.sigma, 0.996, places=2)
        self.assertAlmostEqual(b.mu, 32.189, places=2)
        self.assertAlmostEqual(b.sigma, 6.062, places=2)
    def test_1vs1_draw(self):
        [a], [b] = ttt.Game(
            [[ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]],
            [0, 0], 0.25).posteriors()
        self.assertAlmostEqual(a.mu, 25.000, 2)
        self.assertAlmostEqual(a.sigma, 6.469, 2)
        self.assertAlmostEqual(b.mu, 25.000, 2)
        self.assertAlmostEqual(b.sigma, 6.469, 2)

        ta = [ttt.Player(ttt.Gaussian(25., 3.), 25.0 / 6, 25.0 / 300)]
        tb = [ttt.Player(ttt.Gaussian(29., 2.), 25.0 / 6, 25.0 / 300)]
        [a], [b] = ttt.Game([ta, tb], [0, 0], 0.25).posteriors()
        self.assertAlmostEqual(a.mu, 25.736, 4)
        self.assertAlmostEqual(a.sigma, 2.709956, 4)
        self.assertAlmostEqual(b.mu, 28.67289, 4)
        self.assertAlmostEqual(b.sigma, 1.916471, 4)
Beispiel #8
0
    def test_1vs1vs1(self):
        [a], [b], [c] = ttt.Game(
            [[ttt.Rating()], [ttt.Rating()], [ttt.Rating()]],
            [1, 0, 2]).posteriors
        self.assertAlmostEqual(a.mu, 25.000000, 5)
        self.assertAlmostEqual(a.sigma, 6.238469796, 5)
        self.assertAlmostEqual(b.mu, 31.3113582213, 5)
        self.assertAlmostEqual(b.sigma, 6.69881865, 5)
        self.assertAlmostEqual(c.mu, 18.6886417787, 5)

        [a], [b], [c] = ttt.Game(
            [[ttt.Rating()], [ttt.Rating()], [ttt.Rating()]], [1, 0, 2],
            0.5).posteriors
        self.assertAlmostEqual(a.mu, 25.000000, 4)
        self.assertAlmostEqual(a.sigma, 6.48760, 4)
        self.assertAlmostEqual(b.mu, 29.19950, 4)
        self.assertAlmostEqual(b.sigma, 7.00947, 4)
        self.assertAlmostEqual(c.mu, 20.80049, 4)
Beispiel #9
0
    def test_1vs1vs1_draw(self):
        [a], [b], [c] = ttt.Game(
            [[ttt.Rating()], [ttt.Rating()], [ttt.Rating()]], [0, 0, 0],
            0.25).posteriors
        self.assertAlmostEqual(a.mu, 25.000, 2)
        self.assertAlmostEqual(a.sigma, 5.746947, 4)
        self.assertAlmostEqual(b.mu, 25.000, 2)
        self.assertAlmostEqual(b.sigma, 5.714755, 4)

        ta = [ttt.Rating(ttt.Gaussian(25., 3.))]
        tb = [ttt.Rating(ttt.Gaussian(25., 3.))]
        tc = [ttt.Rating(ttt.Gaussian(29., 2.))]
        [a], [b], [c] = ttt.Game([ta, tb, tc], [0, 0, 0], 0.25).posteriors
        self.assertAlmostEqual(a.mu, 25.473, 2)
        self.assertAlmostEqual(a.sigma, 2.645, 2)
        self.assertAlmostEqual(b.mu, 25.505, 2)
        self.assertAlmostEqual(b.sigma, 2.631, 2)
        self.assertAlmostEqual(c.mu, 28.565, 2)
        self.assertAlmostEqual(c.sigma, 1.888, 2)
    def test_1vs1vs1_draw(self):
        [a], [b], [c] = ttt.Game(
            [[ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)],
             [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]],
            [0, 0, 0], 0.25).posteriors()
        self.assertAlmostEqual(a.mu, 25.000, 3)
        self.assertAlmostEqual(a.sigma, 5.729, 3)
        self.assertAlmostEqual(b.mu, 25.000, 3)
        self.assertAlmostEqual(b.sigma, 5.707, 3)

        ta = [ttt.Player(ttt.Gaussian(25., 3.), 25.0 / 6, 25.0 / 300)]
        tb = [ttt.Player(ttt.Gaussian(25., 3.), 25.0 / 6, 25.0 / 300)]
        tc = [ttt.Player(ttt.Gaussian(29., 2.), 25.0 / 6, 25.0 / 300)]
        [a], [b], [c] = ttt.Game([ta, tb, tc], [0, 0, 0], 0.25).posteriors()
        self.assertAlmostEqual(a.mu, 25.489, 3)
        self.assertAlmostEqual(a.sigma, 2.638, 3)
        self.assertAlmostEqual(b.mu, 25.511, 3)
        self.assertAlmostEqual(b.sigma, 2.629, 3)
        self.assertAlmostEqual(c.mu, 28.556, 3)
        self.assertAlmostEqual(c.sigma, 1.886, 3)
Beispiel #11
0
 def test_NvsN_Draw(self):
     ta = [
         ttt.Rating(ttt.Gaussian(15., 1.)),
         ttt.Rating(ttt.Gaussian(15., 1.))
     ]
     tb = [ttt.Rating(ttt.Gaussian(30., 2.))]
     [a, b], [c] = ttt.Game([ta, tb], [0, 0], 0.25).posteriors
     self.assertAlmostEqual(a.mu, 15.000, 2)
     self.assertAlmostEqual(a.sigma, 0.9916, 3)
     self.assertAlmostEqual(b.mu, 15.000, 2)
     self.assertAlmostEqual(b.sigma, 0.9916, 3)
     self.assertAlmostEqual(c.mu, 30.000, 2)
     self.assertAlmostEqual(c.sigma, 1.9320, 2)
    def test_1vs1(self):
        ta = [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]
        tb = [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6, 25.0 / 300)]
        g = ttt.Game([ta, tb], [0, 1], 0.0)
        [a], [b] = g.posteriors()
        self.assertAlmostEqual(a.mu, 20.79477925612302, 4)
        self.assertAlmostEqual(b.mu, 29.20522074387697, 4)
        self.assertAlmostEqual(a.sigma, 7.194481422570443, places=4)

        g = ttt.Game([[ttt.Player(ttt.Gaussian(29., 1.), 25.0 / 6)],
                      [ttt.Player(ttt.Gaussian(25.0, 25.0 / 3), 25.0 / 6)]],
                     [0, 1])
        [a], [b] = g.posteriors()
        self.assertAlmostEqual(a.mu, 28.89648, places=4)
        self.assertAlmostEqual(a.sigma, 0.9966043, places=4)
        self.assertAlmostEqual(b.mu, 32.18921, places=4)
        self.assertAlmostEqual(b.sigma, 6.062064, places=4)

        ta = [ttt.Player(ttt.Gaussian(1.139, 0.531), 1.0, 0.2125)]
        tb = [ttt.Player(ttt.Gaussian(15.568, 0.51), 1.0, 0.2125)]
        g = ttt.Game([ta, tb], [0, 1], 0.0)
        self.assertAlmostEqual(g.likelihoods[0][0].sigma, ttt.inf)
        self.assertAlmostEqual(g.likelihoods[1][0].sigma, ttt.inf)
        self.assertAlmostEqual(g.likelihoods[0][0].mu, 0.0)
Beispiel #13
0
    def test_history_init(self):
        events = [[["a"], ["b"]], [["a"], ["c"]], [["b"], ["c"]]]
        results = [[0, 1], [1, 0], [0, 1]]
        h = ttt.History(events, results, [1, 2, 3])

        self.assertEqual(
            not ttt.gr_tuple(h.batches[1].max_step, 1e-6)
            and not ttt.gr_tuple(h.batches[1].max_step, 1e-6), True)
        p0 = h.batches[0].posteriors()
        self.assertAlmostEqual(p0["a"].mu, 29.205, 3)
        self.assertAlmostEqual(p0["a"].sigma, 7.19448, 3)
        observed = h.batches[1].prior_forward["a"].N.sigma
        expected = math.sqrt((ttt.GAMMA * 1)**2 +
                             h.batches[0].posterior("a").sigma**2)
        self.assertAlmostEqual(observed, expected)
        observed = h.batches[1].posterior("a")
        g = ttt.Game([[h.batches[1].prior_forward["a"]],
                      [h.batches[1].prior_forward["c"]]], [1, 0])
        [expected], [c] = g.posteriors
        self.assertAlmostEqual(observed.mu, expected.mu, 3)
        self.assertAlmostEqual(observed.sigma, expected.sigma, 3)
 def test_NvsNvsN_mixt(self):
     ta = [
         ttt.Player(ttt.Gaussian(12., 3.), 25.0 / 6, 25.0 / 300),
         ttt.Player(ttt.Gaussian(18., 3.), 25.0 / 6, 25.0 / 300)
     ]
     tb = [ttt.Player(ttt.Gaussian(30., 3.), 25.0 / 6, 25.0 / 300)]
     tc = [
         ttt.Player(ttt.Gaussian(14., 3.), 25.0 / 6, 25.0 / 300),
         ttt.Player(ttt.Gaussian(16., 3.), 25.0 / 6, 25.0 / 300)
     ]
     [a, b], [c], [d, e] = ttt.Game([ta, tb, tc], [1, 0, 0],
                                    0.25).posteriors()
     self.assertAlmostEqual(a.mu, 13.051, 3)
     self.assertAlmostEqual(a.sigma, 2.864, 3)
     self.assertAlmostEqual(b.mu, 19.051, 3)
     self.assertAlmostEqual(b.sigma, 2.864, 3)
     self.assertAlmostEqual(c.mu, 29.292, 3)
     self.assertAlmostEqual(c.sigma, 2.764, 3)
     self.assertAlmostEqual(d.mu, 13.658, 3)
     self.assertAlmostEqual(d.sigma, 2.813, 3)
     self.assertAlmostEqual(e.mu, 15.658, 3)
     self.assertAlmostEqual(e.sigma, 2.813, 3)
    def test_history_init(self):
        composition = [[["aa"], ["b"]], [["aa"], ["c"]], [["b"], ["c"]]]
        results = [[1, 0], [0, 1], [1, 0]]
        priors = dict()
        for k in ["aa", "b", "c"]:
            priors[k] = ttt.Player(ttt.Gaussian(25., 25.0 / 3), 25.0 / 6,
                                   0.15 * 25.0 / 3)

        h = ttt.History(composition, results, [1, 2, 3], priors)

        p0 = h.batches[0].posteriors()
        self.assertAlmostEqual(p0["aa"].mu, 29.205, 3)
        self.assertAlmostEqual(p0["aa"].sigma, 7.19448, 3)
        observed = h.batches[1].skills["aa"].forward.sigma
        gamma = 0.15 * 25.0 / 3
        expected = math.sqrt((gamma * 1)**2 +
                             h.batches[0].posterior("aa").sigma**2)
        self.assertAlmostEqual(observed, expected)
        observed = h.batches[1].posterior("aa")
        [expected], [c] = ttt.Game(h.batches[1].within_priors(0),
                                   [0, 1]).posteriors()
        self.assertAlmostEqual(observed.mu, expected.mu, 3)
        self.assertAlmostEqual(observed.sigma, expected.sigma, 3)
Beispiel #16
0
    def test_1vs1vs1_margin_0(self):
        ta = [ttt.Rating(ttt.Gaussian(25., 1e-7))]
        tb = [ttt.Rating(ttt.Gaussian(25., 1e-7))]
        tc = [ttt.Rating(ttt.Gaussian(25., 1e-7))]

        g_abc = ttt.Game([ta, tb, tc], [1, 2, 3], 0.)
        g_acb = ttt.Game([ta, tb, tc], [1, 3, 2], 0.)
        g_bac = ttt.Game([ta, tb, tc], [2, 1, 3], 0.)
        g_bca = ttt.Game([ta, tb, tc], [3, 1, 2], 0.)
        g_cab = ttt.Game([ta, tb, tc], [2, 3, 1], 0.)
        g_cba = ttt.Game([ta, tb, tc], [3, 2, 1], 0.)

        proba = 0
        proba += g_abc.evidence
        proba += g_acb.evidence
        proba += g_bac.evidence
        proba += g_bca.evidence
        proba += g_cab.evidence
        proba += g_cba.evidence
        print("Corregir la evidencia multiequipos para que sume 1")
        self.assertAlmostEqual(proba, 1.49999991)
#!/usr/bin/env python

import src

if __name__ == '__main__':
    src.Game().run()