Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Player.is_dominated: Fix warnings #504

Merged
merged 3 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions quantecon/game_theory/normal_form_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,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` is set to `'simplex'` or
`'interior-point'`, `scipy.optimize.linprog` is used with
the method as specified by `method`.
game. If `method` is set to `'simplex'`, `'interior-point'`,
or `'revised simplex'`, then `scipy.optimize.linprog` is
used with the method as specified by `method`.

Returns
-------
Expand Down Expand Up @@ -469,20 +469,21 @@ 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', 'interior-point']:
elif method in ['simplex', 'interior-point', 'revised simplex']:
from scipy.optimize import linprog
m, n = D.shape
A = np.empty((n+2, m+1))
A[:n, :m] = -D.T
A[:n, -1] = 1 # Slack variable
A[n, :m], A[n+1, :m] = 1, -1 # Equality constraint
A[n:, -1] = 0
b = np.empty(n+2)
b[:n] = 0
b[n], b[n+1] = 1, -1
A_ub = np.empty((n, m+1))
A_ub[:, :m] = -D.T
A_ub[:, -1] = 1 # Slack variable
b_ub = np.zeros(n)
A_eq = np.empty((1, m+1))
A_eq[:, :m] = 1 # Equality constraint
A_eq[:, -1] = 0
b_eq = np.ones(1)
c = np.zeros(m+1)
c[-1] = -1
res = linprog(c, A_ub=A, b_ub=b, method=method)
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq,
method=method)
if res.success:
return res.x[-1] > tol
elif res.status == 2: # infeasible
Expand All @@ -507,9 +508,9 @@ def dominated_actions(self, 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` is set to `'simplex'` or
`'interior-point'`, `scipy.optimize.linprog` is used with
the method as specified by `method`.
game. If `method` is set to `'simplex'`, `'interior-point'`,
or `'revised simplex'`, then `scipy.optimize.linprog` is
used with the method as specified by `method`.

Returns
-------
Expand Down
4 changes: 2 additions & 2 deletions quantecon/game_theory/tests/test_normal_form_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Player #

LP_METHODS = [None, 'simplex', 'interior-point']
LP_METHODS = [None, 'simplex', 'interior-point', 'revised simplex']


class TestPlayer_1opponent:
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_player_corner_cases():
for method in LP_METHODS:
eq_(player.is_dominated(action, method=method), False)

e = 1e-8
e = 1e-8 * 2
player = Player([[-e, -e], [1, -1], [-1, 1]])
action = 0
eq_(player.is_best_response(action, [1/2, 1/2], tol=e), True)
Expand Down