Skip to content
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
11 changes: 8 additions & 3 deletions quantecon/game_theory/normal_form_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,16 @@ def best_response_2p(payoff_matrix, opponent_mixed_action, tol=1e-8):
Opponent's mixed action. Its length must be equal to
`payoff_matrix.shape[1]`.

tol : scalar(float), optional(default=None)
Tolerance level used in determining best responses.
tol : scalar(float), optional(default=1e-8)
Tolerance level used in determining best responses. Must be
nonnegative.

Returns
-------
scalar(int)
Best response action.
Best response action. -1 indicates an error condition: no
action satisfies the tolerance condition, which occurs only
if `tol` < 0.

"""
n, m = payoff_matrix.shape
Expand All @@ -932,3 +935,5 @@ def best_response_2p(payoff_matrix, opponent_mixed_action, tol=1e-8):
for a in range(n):
if payoff_vector[a] >= payoff_max - tol:
return a

return -1 # Unreachable unless tol < 0
9 changes: 9 additions & 0 deletions quantecon/game_theory/tests/test_normal_form_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,12 @@ def test_best_response_2p():
br_computed = \
best_response_2p(test_case['payoff_array'], mixed_action)
assert_(br_computed == br_expected)


def test_best_response_2p_negative_tol():
# With tol < 0 no action can satisfy the tolerance condition;
# -1 is returned rather than falling through to None
payoff_array = np.array([[4., 0.], [3., 2.]])
mixed_action = np.array([0.5, 0.5])
br_computed = best_response_2p(payoff_array, mixed_action, tol=-1e-8)
assert_(br_computed == -1)
Loading