# Difference between revisions of "what game are we playing"

## Authors

Yuxin Wang, Evan Peters, Yifan Mou, Sangeeth Kalaichanthiran

## Introduction

Recently, there have been many different studies of methods using AI to solve large-scale, zero-sum, extensive form problems. However, most of these works operate under the assumption that the parameters of the game are known, and the objective is just finding the optimal strategy for the game. This scenario is unrealistic since most of the time parameters of the game are unknown. This paper proposes a framework for finding an optimal solution using a primal-dual Newton Method and then using back-propagation to analytically compute the gradients of all the relevant game parameters.

The approach to solving this problem is to consider quantal response equilibrium (QRE), which is a generalization of Nash equilibrium (NE) where the agents can make suboptimal decisions. It is shown that the solution to the QRE is a differentiable function of the payoff matrix. Consequently, back-propagation can be used to analytically solve for the payoff matrix (or other game parameters). This strategy has many future application areas as it allows for game-solving (both extensive and normal form) to be integrated as a module in a deep neural network.

An example of architecture is presented below:

Payoff matrix $P$ is parameterized by a domain-dependent low dimensional vector $\phi$, which $\phi$ depends on a differentiable function $M_1(x)$. Furthermore, $P$ is applied to QRE to get the equilibrium strategies $(u^∗, v^∗)$. Lastly, loss function is calculated after applying through any differentiable $M_2(u^∗, v^∗)$.

The effectiveness of this model is demonstrated using the games “Rock, Paper, Scissors”, one-card poker, and a security defense game.

## Learning and Quantal Response in Normal Form Games

The game-solving module provides all elements required in differentiable learning, which maps contextual features to payoff matrices, and computes equilibrium strategies under a set of contextual features. This paper will learn zero-sum games and start with normal form games since they have game solver and learning approach capturing much of intuition and basic methodology.

### Zero-Sum Normal Form Games

In two-player zero-sum games there is a payoff matrix $P$ that describes the rewards for two players employing specific strategies u and v respectively. The optimal strategy mixture may be found with a classic min-max formulation: $$\min_u \max_v \ u^T P v \\ subject \ to \ 1^T u =1, u \ge 0 \\ 1^T v =1, v \ge 0. \$$

Here, we consider the case where $P$ is not known a priori. The solution $(u^*, v_0)$ to this optimization and the solution $(u_0,v^*)$ to the corresponding problem with inverse player order form the Nash equilibrium $(u^*,v^*)$. At this equilibrium, the players do not have anything to gain by changing their strategy, so this point is a stable state of the system. When the payoff matrix P is not known, we observe samples of actions $a^{(i)}, i =1,...,N$ from one or both players, which depends on some external content $x$, sampled from the equilibrium strategies $(u^*,v^*)$, to recover the true underlying payoff matrix P or a function form P(x) depending on the current context.

### Quantal Response Equilibria

However, NE is poorly suited because NEs are overly strict, discontinuous with respect to P, and may not be unique. To address these issues, model the players' actions with the quantal response equilibria (QRE), where noise is added to the payoff matric. Specifically, consider the logit equilibrium for zero-sum games that obeys the fixed point: $$u^* _i = \frac {exp(-Pv)_i}{\sum_{q \in [n]} exp (-Pv)_q}, \ v^* _j= \frac {exp(P^T u)_j}{\sum_{q \in [m]} exp (P^T u)_q} .\qquad \ (1)$$ For a fixed opponent strategy, the logit equilibrium corresponding to a strategy is strictly convex, and thus the regularized best response is unique.

### End-to-End Learning

Then to integrate zero-sum solver, [1] introduced a method to solve the QRE and to differentiate through its solution.

QRE solver: To find the fixed point in (1), it is equivalent to solve the regularized min-max game: $$\min_{u \in \mathbb{R}^n} \max_{v \in \mathbb{R}^m} \ u^T P v -H(v) + H(u) \\ \text{subject to } 1^T u =1, \ 1^T v =1,$$ where H(y) is the Gibbs entropy $\sum_i y_i log y_i$. Entropy regularization guarantees the non-negative condition and makes the equilibrium continuous with respect to P, which means players are encouraged to play more randomly, and all actions have non-zero probability. Moreover, this problem has a unique saddle point corresponding to $(u^*, v^*)$.

Using a primal-dual Newton Method to solve the QRE for two-player zero-sum games, the KKT conditions for the problem are: $$Pv + \log(u) + 1 +\mu 1 = 0 \\ P^T v -\log(v) -1 +\nu 1 = 0 \\ 1^T u = 1, \ 1^T v = 1,$$ where $(\mu, \nu)$ are Lagrange multipliers for the equality constraints on u, v respectively. Then applying Newton's method gives the the update rule: $$Q \begin{bmatrix} \Delta u \\ \Delta v \\ \Delta \mu \\ \Delta \nu \\ \end{bmatrix} = - \begin{bmatrix} P v + \log u + 1 + \mu 1 \\ P^T u - \log v - 1 + \nu 1 \\ 1^T u - 1 \\ 1^T v - 1 \\ \end{bmatrix}, \qquad (2)$$ where Q is the Hessian of the Lagrangian, given by $$Q = \begin{bmatrix} diag(\frac{1}{u}) & P & 1 & 0 \\ P^T & -diag(\frac{1}{v}) & 0 & 1\\ 1^T & 0 & 0 & 0 \\ 0 & 1^T & 0 & 0 \\ \end{bmatrix}.$$

Differentiating Through QRE Solutions: The QRE solver provides a method to compute the necessary Jacobian-vector products. Specifically, we compute the gradient of the loss given the solution $(u^*,v^*)$ to the QRE, and some loss function $L(u^*,v^*)$:

1. Take differentials of the KKT conditions: $Q \begin{bmatrix} du & dv & d\mu & d\nu \\ \end{bmatrix} ^T = \begin{bmatrix} -dPv & -dP^Tu & 0 & 0 \\ \end{bmatrix}^T. \$

2. For small changes du, dv, $dL = \begin{bmatrix} v^TdP^T & u^TdP & 0 & 0 \\ \end{bmatrix} Q^{-1} \begin{bmatrix} -\nabla_u L & -\nabla_v L & 0 & 0 \\ \end{bmatrix}^T.$

3. Apply this to P, and take limits as dP is small: $\nabla_P L = y_u v^T + u y_v^T, \qquad (3)$ where $\begin{bmatrix} y_u & y_v & y_{\mu} & y_{\nu}\\ \end{bmatrix}=Q^{-1}\begin{bmatrix} -\nabla_u L & -\nabla_v L & 0 & 0 \\ \end{bmatrix}^T.$

Hence, the forward pass is given by using the expression in (2) to solve for the logit equilibrium given P, and the backward pass is given by using $\nabla_u L$ and $\nabla_v L$ to obtain $\nabla_P L$ using (3). There does not always exist a unique P which generates $u^*, v^*$ under the logit QRE, and we cannot expect to recover P when under-constrained.

## Learning Extensive form games

The normal form representation for games where players have many choices quickly becomes intractable. For example, consider a chess game: One the first turn, player 1 has 20 possible moves and then player 2 has 20 possible responses. If in the following number of turns each player is estimated to have ~30 possible moves and if a typical game is 40 moves per player, the total number of strategies is roughly $10^{120}$ per player (this is known as the Shannon number for game-tree complexity of chess) and so the payoff matrix for a typical game of chess must therefore have $O(10^{240})$ entries.

Instead, it is much more useful to represent the game graphically as an "Extensive form game" (EFG). We'll also need to consider types of games where there is imperfect information - players do not necessarily have access to the full state of the game. An example of this is one-card poker: (1) Each player draws a single card from a 13-card deck (ignore suits) (2) Player 1 decides whether to bet/hold (3) Player 2 decides whether to call/raise (4) Player 1 must either call/fold if Player 2 raised. From this description, player 1 has $2^{13}$ possible first moves (all combinations of (card, raise/hold)) and has $2^{13}$ possible second moves (whenever player 1 gets a second move) for a total of $2^{26}$ possible strategies. In addition, Player 1 never knows what cards player 2 has and vice versa. So instead of representing the game with a huge payoff matrix we can instead represent it as a simple decision tree (for a single drawn card of player 1):

where player 1 is represented by "1", a node that has two branches corresponding to the allowed moves of player 1. However there must also be a notion of information available to either player: While this tree might correspond to say, player 1 holding a "9", it contains no information on what card player 2 is holding (and is much simpler because of this). This leads to the definition of an information set: the set of all nodes belonging to a single player for which the other player cannot distinguish which node has been reached. The information set may therefore be treated as a node itself, for which actions stemming from the node must be chosen in ignorance to what the other player did immediately before arriving at the node. In the poker example, the full game tree consists of a much more complex version of the tree shown above (containing repetitions of the given tree for every possible combination of cards dealt) and the and an example of an information set for player 1 is the set of all of nodes owned by player 2 that immediately follow player 1's decision to hold. In other words, if player 1 holds there are 13 possible nodes describing the responses of player 2 (raise/hold for player 2 having card = ace, 1, ... King) and all 13 of these nodes are indistinguishable to player 1, and so form an information set for player 1.

The following is a review of important concepts for extensive form games first formalized in [2]. Let $\mathcal{I}_i$ be the set of all information sets for player i, and for each $t \in \mathcal{I}_i$ let $\sigma_t$ be the actions taken by player i to arrive at $t$ and $C_t$ be the actions that player i can take from $u$. Then the set of all possible sequences that can be taken by player i is given by

$$S_i = \{\emptyset \} \cup \{ \sigma_t c | u\in \mathcal{I}_i, c \in C_t \}$$

So for the one-card poker we would have $S_1 = \{\emptyset, \text{raise}, \text{hold}, \text{hold-call}, \text{hold-fold\} }$. From the possible sequences follows two important concepts:

1. The EFG payoff matrix $P$ of size $|S_1| \times |S_2|$ (this is all possible actions available to either player), is populated with rewards from each leaf of the tree (or "zero" for each $(s_1, s_2)$ that is an invalid pair), and the expected payoff for realization plans $(u, v)$ is given by $u^T P v$
2. A realization plan $u \in \mathbb{R}^{|S_1|}$ for player 1 ($v \in \mathbb{R}^{|S_2|}$ for player 2 ) will describe probabilities for players to carry out each possible sequence, and each realization plan must be constrained by (i) compatibility of sequences (e.g. "raise" is not compatible with "hold-call") and (ii) information sets available to the player. These constraints are linear: $$Eu = e \\ Fv = f$$ where $e = f = (1, 0, ..., 0)^T$ and $E, F$ contain entries in ${-1, 0, 1}$ describing compatibility and information sets.

The paper's main contribution is to develop a minmax problem for extensive form games:

$$\min_u \max_v u^T P v + \sum_{t\in \mathcal{I}_1} \sum_{c \in C_t} u_c \log \frac{u_c}{u_{p_t}} - \sum_{t\in \mathcal{I}_2} \sum_{c \in C_t} v_c \log \frac{v_c}{v_{p_t}}$$

where $p_t$ is the action immediately preceding information set $t$. Intuitively, each sum resembles a cross entropy over the distribution of probabilities in the realization plan comparing each probability to proceed from an information set to the probability to arrive at that information set. Importantly, these entropies are strictly convex or concave (for player 1 and player 2 respectively) [3] so that the minmax problem will have a unique solution and the objective function is continuous and continuously differentiable - this means there is a way to optimize the function. As noted in Theorem 1 of [1], the solution to this problem is equivalently a solution for the QRE of the game in reduced normal form.

Minmax can also be seen from an algorithmic perspective. Referring to the above figure containing a tree, it contains a sequence of states and action which alternates between two or more competing players. The above formulation of the minmax problem essentially measures how well a decision rule is from the perspective of a single player. To describe it in terms of the tree, if it is player 1's turn, then it is a mutual recursion of player 1 choosing to maximize its payoff and player 2 choosing to minimize player 1's payoff.

Having decided on a cost function, the method of Lagrange multipliers may be used to construct the Lagrangian that encodes the known constraints ($Eu = e \,, Fv = f$, and $u, v \geq 0$), and then optimize the Lagrangian using Newton's method (identically to the previous section). Accounting for the constraints, the Lagrangian becomes

$$\mathcal{L} = g(u, v) + \sum_i \mu_i(Eu - e)_i + \sum_i \nu_i (Fv - f)_i$$

where $g$ is the argument from the minmax statement above and $u, v \geq 0$ become KKT conditions. The general update rule for Newton's method may be written in terms of the derivatives of $\mathcal{L}$ with respect to primal variables $u, v$ and dual variables $\mu, \nu$, yielding:

$$\nabla_{u,v,\mu,\nu}^2 \mathcal{L} \cdot (\Delta u, \Delta v, \Delta \mu, \Delta \nu)^T= - \nabla_{u,v,\mu,\nu} \mathcal{L}$$ where $\nabla_{u,v,\mu,\nu}^2 \mathcal{L}$ is the Hessian of the Lagrangian and $\nabla_{u,v,\mu,\nu} \mathcal{L}$ is simply a column vector of the KKT stationarity conditions. Combined with the previous section, this completes the goal of the paper: To construct a differentiable problem for learning normal form and extensive form games.

## Experiments

The authors demonstrated learning on extensive form games in the presence of side information, with partial observations using three experiments. In all cases, the goal was to maximize the likelihood of realizing an observed sequence from the player, assuming they act in accordance to the QRE. The authors found that the best way to implement the module was to use a medium to large batch size, RMSProp, or Adam optimizers with a learning rate between $\left[0.0001,0.01\right]$

### Rock, Paper, Scissors

Rock, Paper, Scissors is a 2-player zero-sum game. For this game, the best strategy to reach a Nash equilibrium and a Quantal response equilibrium is to uniformly play each hand with equal odds. The first experiment was to learn a non-symmetric variant of Rock, Paper, Scissors with incomplete information with the following payoff matrix:

Payoff matrix of modified Rock-Paper-Scissors
Rock Paper Scissors
Rock 0 $-b_1$ $b_2$
Paper $b_1$ 0 $-b_3$
Scissors $-b_2$ $b_3$ 0

where each of the $b$ ’s are linear function of some features $x \in \mathbb{R}^{2}$ (i.e., $b_y = x^Tw_y$, $y \in$ {$1,2,3$} , where $w_y$ are to be learned by the algorithm). Using many trials of random rewards the technique produced the following results for optimal strategies[1]:

From the graphs above, we can tell the following: 1) both parameters learned and predicted strategies improve with larger dataset; and 2) with a reasonably sized dataset, >1000 here, convergence is stable and is fairly quick.

### One-Card Poker

Next they investigated extensive form games using the one-Card Poker (with imperfect information) introduced in the previous section. In the experimental setup, they used a deck stacked non-uniformly (meaning repeat cards were allowed). Their goal was to learn this distribution of cards from observations of many rounds of the play. Different from the distribution of cards dealt, the method built in the paper is more suited to learn the player’s perceived or believed distribution of cards. It may even be a function of contextual features such as demographics of players. Three experiments were run with $n=4$. Each experiment comprised 5 runs of training, with same weights but different training sets. Let $d \in \mathbb{R}^{n}, d \ge 0, \sum_{i} d_i = 1$ be the weights of the cards. The probability that the players are dealt cards $(i,j)$ is $\frac{d_i d_j}{1-d_i}$. This distribution is asymmetric between players. Matrix $P, E, F$ for the case $n=4$ are presented in [1]. With training for 2500 epochs, the mean squared error of learned parameters (card weights, $u, v$ ) are averaged over all runs of and are presented as following [1]:

### Security Resource Allocation Game

From Security Resource Allocation Game, they demonstrated the ability to learn from imperfect observations. The defender possesses $k$ indistinguishable and indivisible defensive resources which he splits among $n$ targets, { $T_1, ……, T_n$}. The attacker chooses one target. If the attack succeeds, the attacker gets $R_i$ reward and defender gets $-R_i$, otherwise zero payoff for both. If there are n defenders guarding $T_i$, probability of successful attack on $T_i$ is $\frac{1}{2^n}$. The expected payoff matrix when $n = 2, k = 3$, where the attackers are the row players is:

Payoff matrix when $n = 2, k = 3$
{#$D_1$,#$D_2$} {0, 3} {1, 2} {2, 1} {3, 0}
$T_1$ $-R_1$ $-\frac{1}{2}R_1$ $-\frac{1}{4}R_1$ $-\frac{1}{8}R_1$
$T_2$ $-\frac{1}{8}R_2$ $-\frac{1}{4}R_2$ $-\frac{1}{2}R_2$ $-R_2$

For a multi-stage game the attacker can launch $t$ attacks, one in each stage while defender can only stick with stage 1. The attacker may change target if the attack in stage 1 is failed. Three experiments are run with $n = 2, k = 5$ for games with single attack and double attack, i.e, $t = 1$ and $t = 2$. The results of simulated experiments are shown below [1]:

They learned $R_i$ only based on observations of the defender’s actions and could still recover the game setting by only observing the defender’s actions. Same as expectation, the larger dataset size improves the learned parameters. Two outliers are 1) Security Game, the green plot for when $t = 2$; and 2) RPS, when comparing between training sizes of 2000 and 5000.

## Conclusion

Unsurprisingly, the results of this study show that in general the quality of learned parameters improved as the number of observations increased. The network presented in this paper demonstrated improvement over existing methodology.

This paper presents an end-to-end framework for implementing a game solver, for both extensive and normal form, as a module in a deep neural network for zero-sum games. This method, unlike many previous works in this area, does not require the parameters of the game to be known to the agent prior to the start of the game. The two-part method analytically computes both the optimal solution and the parameters of the game. Future work involves taking advantage of the KKT matrix structure to increase computation speed, and extensions to the area of learning general-sum games.

## Critiques

The proposed method appears to suffer from two flaws. Firstly, the assumption that players behave in accordance to the QRE severely limits the space of player strategies, and is known to exhibit pathological behaviour even in one-player settings. Second, the solvers are computationally inefficient and are unable to scale.

This method of proposing that real players will follow a laid out scheme or playing strategy is almost always a drastic oversimplification of real world scenarios and severely limits the applications. In order to better fit a model to the real players, there almost always has to be some sort of stochastic implementation which accounts for the presence of irrational users in the system.

## References

[1] Ling, C. K., Fang, F., & Kolter, J. Z. (2018). What game are we playing? end-to-end learning in normal and extensive form games. arXiv preprint arXiv:1805.02777.

[2] B. von Stengel. Efficient computation of behavior strategies.Games and Economics Behavior,14(0050):220–246, 1996.

[3] Boyd, S., Boyd, S. P., & Vandenberghe, L. (2004). Convex optimization. Cambridge university press.