diff --git a/quantecon/game_theory/normal_form_game.py b/quantecon/game_theory/normal_form_game.py index 690e5bb3..43cf3af6 100644 --- a/quantecon/game_theory/normal_form_game.py +++ b/quantecon/game_theory/normal_form_game.py @@ -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 @@ -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 diff --git a/quantecon/game_theory/tests/test_normal_form_game.py b/quantecon/game_theory/tests/test_normal_form_game.py index 1b3bd30a..a5d6afac 100644 --- a/quantecon/game_theory/tests/test_normal_form_game.py +++ b/quantecon/game_theory/tests/test_normal_form_game.py @@ -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)