Skip to content
Open
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
18 changes: 12 additions & 6 deletions quantecon/game_theory/repeated_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,18 @@ def _best_dev_gains(rpg):
ai and a-i, and player i deviates to the best response action.
"""
sg, delta = rpg.sg, rpg.delta

best_dev_gains = ((1-delta)/delta *
(np.max(sg.payoff_arrays[i], 0) - sg.payoff_arrays[i])
for i in range(2))

return tuple(best_dev_gains)
payoff_arrays = sg.payoff_arrays

# Precompute coefficient
coeff = (1 - delta) / delta

# For each player, rapidly compute the best deviation gain using optimal axis parameterization
# np.max() over axis=0 gives the best response for each (a-i)
# No need to build generator, directly construct tuple for efficiency
return (
coeff * (np.max(payoff_arrays[0], axis=0) - payoff_arrays[0]),
coeff * (np.max(payoff_arrays[1], axis=0) - payoff_arrays[1])
)


@njit
Expand Down