Reinforcement Learning: Game Theory
Tags: machinelearning, reinforcement
Published: 2019-04-29 03:59:47

---
title: "Reinforcement Learning: Game Theory"
published: true
description: RL with multiple actors
tags: Machine Learning, Reinforcement
---

*This is the 19th and last in a series of class notes as I go through the [Georgia Tech/Udacity Machine Learning course](https://www.udacity.com/course/machine-learning--ud262). The class textbook is [Machine Learning by Tom Mitchell](https://www.cs.ubbcluj.ro/~gabis/ml/ml-books/McGrawHill%20-%20Machine%20Learning%20-Tom%20Mitchell.pdf).*

## Why Game Theory in Reinforcement Learning

What we know about RL so far has been entirely based on single actors in an environment. However, optimal strategies change significantly when the behavior of other actors is taken into account, which may change the expected payoffs of our own actions. This is why we incorporate Game Theory in RL.

## Minimax

We define a simple game between two players with a range of choices, with zero sum payoffs (one player's win is another's loss), deterministic results, and perfect information. 

```
           B
      L    M     R

    L 1   -3     0
A
    R 0    3    -1
```

Even in this situation it is not clear which choice B or A should take. One heuristic to adopt is for A (which wants the lowest number, for example) to always look for the maximum number, and minimize that. And vice versa for B. Each considers the worst case response from the other. So A picks L. This is called minimax.

However if B also only pays attention to itself and does minimax (it wants higher values), it will pick M, which ironically hands A the -3 it wants. So B must consider what A is likely to do in formulating it's own actions. In this case it is best to pick L where the worst case scenario isn't so bad.

## Von Neumann's theory

> In a 2 player, zero sum deterministic game of perfect information, `minimax` === `maximin` and there always exists an optimal **pure strategy** for each player.

This is to say, there is always a definite value of the game if we assume the players follow `minimax` or `maximin`, and they are the same.

More reading: https://cs.stanford.edu/people/eroberts/courses/soco/projects/1998-99/game-theory/neumann.html

as well as the [Theory of Games and Economic Behavior](https://en.wikipedia.org/wiki/Theory_of_Games_and_Economic_Behavior)

and [Andrew Moore on Zero-Sum Games](http://www.cs.cmu.edu/~./awm/tutorials/gametheory.html)

## Relaxing assumptions

If we relax the requirement of **determinism**, we get the same result under Von Neumann - just that all choices are made based on expected value.

If we relax the requirement of **perfect information**, a lot of complexity comes into the picture. Von Neumann is broken.

The reliance on a **pure** strategy is important for Von Neumann. And if each player is too consistent, they become predictable, and thus exploitable. Thus a **mixed** strategy varies strategies based on a probability distribution. However if for every `p` selected by A, a corresponding mixed strategy governed by `p'` can be chosen by B to offset it, there is still a probabilistic equilibrium where the payoffs meet:

{% youtube d2gr9VrSNTQ %}

Lastly, if we relax the assumption of a **zero-sum game**, we can get situations like the [Prisoner's Dilemma](https://en.wikipedia.org/wiki/Prisoner%27s_dilemma) where cooperation can result in better average outcomes than each can independently get, if they don't betray the other. However because the betrayal strategy dominates in each scenario independently, 

See [Andrew Moore's slides on Non Zero Sum Games](http://www.cs.cmu.edu/~./awm/tutorials/nonzerosum.html)

## Nash Equilibrium

Given `n` players with strategies, you know you are in **Nash Equilibrium** if you take any player and changed their strategy, and they would be worse off. No one person has any reason to change their strategy. [There are a few other minor results that come out of this definition](https://www.youtube.com/watch?v=rz9cuSIrwGs). 

## Repeated games

Most games discussed up til this point are finite, one-off games. What if we could play several rounds of the game, taking into account information from prior rounds? This causes a form of communication of strategy to take place as well as establishes consequences of taking selfish strategies where a positive sum result could have been possible. As such, it causes strategies to lean towards cooperating.

This can be modeled as "trust", but only makes sense if the total number of games is unknown. (By induction, if you know you are at the last round of a repeated game, then it is a one-off game, so the second last round needs to take that into consideration, and so on all the way to the first round. So `n` repeated games with a finite, known `n` simply lead to `n` repeated Nash Equilibria.).

So assuming an unknown number of games (with a probability of ending `gamma`, which looks remarkably similar to a discount factor), a great strategy to encourage collaboration is the [Tit for Tat strategy](https://en.wikipedia.org/wiki/Tit_for_tat). This establishes communication and consequences between rounds, socializing the result of the net suboptimal outcome. It turns out that TfT is best suited for gamma values above a certain level dependent on the payoffs, because if not then the benefit of being selfish outweighs the odds of consequences.

## The Folk Theorem of Repeated Games

Tit for Tat is an example of the general idea that **the possibility of retaliation opens the door for cooperation**. In game theory, the term "[folk theorem](https://en.wikipedia.org/wiki/Folk_theorem_(game_theory))" refers to a specific set of payoffs that can result from Nash strategies in repeated games.

The **Minmax profile** is a pair of payoffs, one for each player, that represent the payoffs that can be achieved by a player defending itself from a malicious adversary. ([More description](https://www.youtube.com/watch?v=Yn4zmWwy9mA))

The **feasible payoff profile** is any mix of available strategies: 

![https://vknight.org/Year_3_game_theory_course/Content/images/L10-img01.png](https://vknight.org/Year_3_game_theory_course/Content/images/L10-img01.png)

Some range of feasible payoffs is going to be better than whatever can be individually achieved (incentive for cooperation), leading to the Folk Theorem:

> Any feasible payoff profile that strictly dominates the minmax/security level profile can be realized as a Nash equilibrium payoff profile, with sufficiently large discount factor.

In other words, if you refuse to cooperate, I can push you down to the minmax profile, instead of letting you get benefits better than you can get on your own.

## Subgame Perfect

The threat cannot be too extreme as to be implausible - to the extent of harming your own interests just to punish my actions. The formal term for a plausible threat is [subgame perfect](https://en.wikipedia.org/wiki/Subgame_perfect_equilibrium) - where you are giving the best response independent of history. 

Implausible threats like the [Grim trigger](https://en.wikipedia.org/wiki/Grim_trigger) are not subgame perfect because you can always drop the strategy to improve your own interests.

The combination of TfT vs TfT is *not* subgame perfect, because instead of instant retaliation you can pick forgiveness.

There is a variant based on agreement/disagreement called the [Pavlov strategy](https://www.frozenevolution.com/pavlov-strategy) that offers more memory, that -is- subgame perfect, because disagreements lead to defections which lead to agreements which lead to cooperation. Wonderful! Now it becomes a plausible threat that is better to enforce than TfT. ([More on this](http://www.pnas.org/content/93/7/2686.short)) 

## Stochastic Games (or Markov Games)

This is a generalization of MDPs and Repeated Games that is a formal model for Multiagent Reinforcement Learning.

## Next in our series

Further notes on this topic:

- [class notes](https://www.ritchieng.com/machine-learning-game-theory/)
- Paper on [Computational Folk theorem](http://jmvidal.cse.sc.edu/library/littman03a.pdf) which shows you can construct subgame perfect Nash eq. for any game in polynomial time.
- Coco values - adding side payments to encourage nash equilibria ([paper](http://proceedings.mlr.press/v28/sodomka13.pdf))

Hopefully that was a good introduction to Game Theory. Feedback and questions are welcome. The entire series is viewable here:


- [Overview](https://dev.to/swyx/machine-learning-an-overview-216n)
- Supervised Learning
    - [Decision Trees](https://dev.to/swyx/machine-learning-classification-learning--decision-trees-1mbh)
    - [Regression](https://dev.to/swyx/supervised-learning-regression-4d17)
    - [Neural Networks](https://dev.to/swyx/supervised-learning-neural-networks-mpo)
    - [Instance Based Learning (K Nearest Neighbors)](https://dev.to/swyx/supervised-learning-instance-based-learning-and-k-nearest-neighbors-kge)
    - [Ensemble Learning (AdaBoost)](https://dev.to/swyx/supervised-learning-ensemble-learning-lim)
    - [Kernel Methods & SVMs](https://dev.to/swyx/supervised-learning-support-vector-machines-3mgk)
    - [Computational Learning Theory](https://dev.to/swyx/supervised-learning-computational-learning-theory-160h)
    - [VC Dimensions](https://dev.to/swyx/supervised-learning-vc-dimensions-10b)
    - [Bayesian Learning](https://dev.to/swyx/supervised-learning-bayesian-learning-403l)
    - [Bayesian Inference](https://dev.to/swyx/supervised-learning-bayesian-inference-4l72)
- Unsupervised Learning
    - [Randomized Optimization](https://dev.to/swyx/unsupervised-learning-randomized-optimization-4c1i)
    - [Information Theory](https://dev.to/swyx/unsupervised-learning-information-theory-recap-4iem)
    - [Clustering](https://dev.to/swyx/unsupervised-learning-clustering-42mi)
    - [Feature Selection](https://dev.to/swyx/unsupervised-learning-feature-selection-84f)
    - [Feature Transformation](https://dev.to/swyx/unsupervised-learning-feature-transformation-pcf)
- Reinforcement Learning
    - Markov Decision Processes - week of Mar 25
    - "True" RL - week of Apr 1
    - [Game Theory](https://dev.to/swyx/reinforcement-learning-game-theory-j1o)