From 844b6692c454dbe46b08628b02ac18f96a17bdf8 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sun, 20 May 2018 14:54:26 +0900 Subject: [PATCH] EHN: Add `'interior-point'` option to `is_dominated` https://github.com/QuantEcon/QuantEcon.py/pull/327#issue-136392329 --- quantecon/game_theory/normal_form_game.py | 7 ++++--- quantecon/game_theory/tests/test_normal_form_game.py | 11 +++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index f6c8da9da..7ab4e2835 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -395,8 +395,9 @@ def is_dominated(self, action, tol=None, method=None): method : str, optional(default=None) If None, `lemke_howson` from `quantecon.game_theory` is used to solve for a Nash equilibrium of an auxiliary zero-sum - game. If `method='simplex'`, `scipy.optimize.linprog` is - used with `method='simplex'`. + game. If `method` is set to `'simplex'` or + `'interior-point'`, `scipy.optimize.linprog` is used with + the method as specified by `method`. Returns ------- @@ -425,7 +426,7 @@ def is_dominated(self, action, tol=None, method=None): g_zero_sum = NormalFormGame([Player(D), Player(-D.T)]) NE = lemke_howson(g_zero_sum) return NE[0] @ D @ NE[1] > tol - elif method in ['simplex']: + elif method in ['simplex', 'interior-point']: from scipy.optimize import linprog m, n = D.shape A = np.empty((n+2, m+1)) diff --git a/quantecon/game_theory/tests/test_normal_form_game.py b/quantecon/game_theory/tests/test_normal_form_game.py index ed3b7c464..710ad4053 100644 --- a/quantecon/game_theory/tests/test_normal_form_game.py +++ b/quantecon/game_theory/tests/test_normal_form_game.py @@ -15,6 +15,9 @@ # Player # +LP_METHODS = [None, 'simplex', 'interior-point'] + + class TestPlayer_1opponent: """Test the methods of Player with one opponent player""" @@ -69,7 +72,7 @@ def test_is_best_response_against_mixed(self): def test_is_dominated(self): for action in range(self.player.num_actions): - for method in [None, 'simplex']: + for method in LP_METHODS: eq_(self.player.is_dominated(action, method=method), False) @@ -106,7 +109,7 @@ def test_best_response_list_when_tie(self): def test_is_dominated(self): for action in range(self.player.num_actions): - for method in [None, 'simplex']: + for method in LP_METHODS: eq_(self.player.is_dominated(action, method=method), False) @@ -126,7 +129,7 @@ def test_player_corner_cases(): player = Player(np.zeros((n, m))) for action in range(n): eq_(player.is_best_response(action, [1/m]*m), True) - for method in [None, 'simplex']: + for method in LP_METHODS: eq_(player.is_dominated(action, method=method), False) e = 1e-8 @@ -134,7 +137,7 @@ def test_player_corner_cases(): action = 0 eq_(player.is_best_response(action, [1/2, 1/2], tol=e), True) eq_(player.is_best_response(action, [1/2, 1/2], tol=e/2), False) - for method in [None, 'simplex']: + for method in LP_METHODS: eq_(player.is_dominated(action, tol=e, method=method), False) eq_(player.is_dominated(action, tol=e/2, method=method), True)