Beispiel #1
0
    def test_objective_single_game(self):
        o = Optimizer()
        o.load_games([(1, 2, 1, 1)])
        v1 = o.create_vars({1: {1: 2200}, 2: {1: 1800}}, [0, -1.01])
        v2 = o.create_vars({1: {1: 2200}, 2: {1: 2200}}, [0, -1.01])
        v3 = o.create_vars({1: {1: 1800}, 2: {1: 2200}}, [0, -1.01])

        (total1, likelihood1, regularization1, smoothness1,
         func_hard_reg, _) = o.objective(v1, verbose=True)
        self.assertLess(likelihood1, 0)
        self.assertTrue(1E-6 < regularization1 < 1)
        self.assertEqual(smoothness1, 0)
        self.assertTrue(func_hard_reg < 1)

        (total2, likelihood2, regularization2, _, _, _) = o.objective(
            v2, verbose=True)
        self.assertLess(likelihood2, likelihood1)

        (total3, likelihood3, regularization3, _, _, _) = o.objective(
            v3, verbose=True)
        self.assertAlmostEqual(regularization1, regularization3)


        self.assertLess(total1 / total2, 0.9)
        self.assertLess(total2 / total3, 0.9)
Beispiel #2
0
    def test_objective_draw(self):
        o = Optimizer(rating_reg=0)
        o.load_games([(1, 2, 1, 2), (2, 1, 1, 2)])

        v1 = o.create_vars({1: {1: 2200}, 2: {1: 1800}}, [0, -1.01])
        v2 = o.create_vars({1: {1: 2000}, 2: {1: 2000}}, [0, -1.01])
        v3 = o.create_vars({1: {1: 1800}, 2: {1: 2200}}, [0, -1.01])

        self.assertLess(o.objective(v2), o.objective(v1))
        self.assertLess(o.objective(v2), o.objective(v3))
Beispiel #3
0
    def test_objective_symmetric_wins(self):
        o = Optimizer(rating_reg=0)
        o.load_games([(1, 2, 1, 1), (2, 1, 1, 1)])

        v1 = o.create_vars({1: {1: 2200}, 2: {1: 1800}}, [0, -1.01])
        v2 = o.create_vars({1: {1: 2000}, 2: {1: 2000}}, [0, -1.01])
        v3 = o.create_vars({1: {1: 1800}, 2: {1: 2200}}, [0, -1.01])

        self.assertLess(o.objective(v2) / o.objective(v1), 0.9)
        self.assertLess(o.objective(v2) / o.objective(v3), 0.9)
Beispiel #4
0
 def test_objective_time_reg(self):
     o = Optimizer(rand_seed=239)
     o.load_games([(1, 2, 1, 1), (1, 2, 2, 0)])
     v = o.create_vars({1: {1: 2200, 2: 1800}, 2: {1: 1800, 2: 2200}},
                       (0, -1.01))
     (total, likelihood, regularization, _, _, _) = o.objective(
          v, verbose=True)
     self.assertLess(likelihood, 0)
     self.assertTrue(1E-6 < regularization < 1)
Beispiel #5
0
    def test_gradient(self):
        o = Optimizer(func_hard_reg=0, func_soft_reg=0, time_delta=0,
                      rating_reg=0)
        o.load_games([(1, 2, 1, 1)])
        v = o.create_vars({1: {1: 2200}, 2: {1: 1800}}, (0, -1.01))

        def o0(x):
             save_x = v[0]
             v[0] = x
             res = o.objective(v)
             v[0] = save_x
             return res

        def o1(x):
             save_x = v[1]
             v[1] = x
             res = o.objective(v)
             v[1] = save_x
             return res

        self.assertAlmostEqual(derivative(o0, v[0]), o.gradient(v)[0])
        self.assertAlmostEqual(derivative(o1, v[1]), o.gradient(v)[1])