def test_lemke_howson_capping(): bimatrix = [[(3, 3), (3, 2)], [(2, 2), (5, 6)], [(0, 3), (6, 1)]] g = NormalFormGame(bimatrix) m, n = g.nums_actions max_iter = 10**6 # big number for k in range(m + n): NE0, res0 = lemke_howson(g, init_pivot=k, max_iter=max_iter, capping=None, full_output=True) NE1, res1 = lemke_howson(g, init_pivot=k, max_iter=max_iter, capping=max_iter, full_output=True) for action0, action1 in zip(NE0, NE1): assert_allclose(action0, action1) eq_(res0.init, res1.init) init_pivot = 1 max_iter = m + n NE, res = lemke_howson(g, init_pivot=init_pivot, max_iter=max_iter, capping=1, full_output=True) eq_(res.num_iter, max_iter) eq_(res.init, init_pivot - 1)
def test_lemke_howson(self): for d in self.game_dicts: for k in d['NEs_dict'].keys(): NE_computed = lemke_howson(d['g'], init_pivot=k) for action_computed, action in zip(NE_computed, d['NEs_dict'][k]): assert_allclose(action_computed, action)
def test_lemke_howson_degenerate(self): for d in self.game_dicts: for k in d['NEs_dict'].keys(): NE_computed, res = lemke_howson(d['g'], init_pivot=k, full_output=True) for action_computed, action in zip(NE_computed, d['NEs_dict'][k]): assert_allclose(action_computed, action) eq_(res.converged, d['converged'])
def test_lemke_howson_capping(): bimatrix = [[(3, 3), (3, 2)], [(2, 2), (5, 6)], [(0, 3), (6, 1)]] g = NormalFormGame(bimatrix) m, n = g.nums_actions max_iter = 10**6 # big number for k in range(m+n): NE0, res0 = lemke_howson(g, init_pivot=k, max_iter=max_iter, capping=None, full_output=True) NE1, res1 = lemke_howson(g, init_pivot=k, max_iter=max_iter, capping=max_iter, full_output=True) for action0, action1 in zip(NE0, NE1): assert_allclose(action0, action1) eq_(res0.init, res1.init) init_pivot = 1 max_iter = m+n NE, res = lemke_howson(g, init_pivot=init_pivot, max_iter=max_iter, capping=1, full_output=True) eq_(res.num_iter, max_iter) eq_(res.init, init_pivot-1)
def test_random_matrix(self): seed = 12345 rng = np.random.default_rng(seed) size = (10, 15) A = rng.normal(size=size) v, x, y = minmax(A) for z in [x, y]: assert_((z >= 0).all()) assert_allclose(z.sum(), 1) g = NormalFormGame((Player(A), Player(-A.T))) NE = lemke_howson(g) assert_allclose(v, NE[0] @ A @ NE[1]) assert_(g.is_nash((x, y)))
def test_lemke_howson_invalid_init_pivot_float(): bimatrix = [[(3, 3), (3, 2)], [(2, 2), (5, 6)], [(0, 3), (6, 1)]] g = NormalFormGame(bimatrix) lemke_howson(g, 1.0)
def test_lemke_howson_invalid_g(): bimatrix = [[(3, 3), (3, 2)], [(2, 2), (5, 6)], [(0, 3), (6, 1)]] lemke_howson(bimatrix)