Algorithmic Game Theory · Lecture Notes
Chapter 13: Learning and Adaptation
The classical question of game theory is "what happens in equilibrium?" It assumes that the players know the game and can compute the equilibrium. In practice, players often do not know the payoff table and lack the computing power to find an equilibrium; they simply play, observe the outcome, and adjust their behavior a little the next time. This chapter studies where such simple update rules lead in the long run. Best-response dynamics and fictitious play look at the opponent's history; the Hedge algorithm minimizes regret; multi-armed bandit algorithms balance exploration against exploitation; Q-learning propagates reward backward through states; replicator dynamics models the spread of successful strategies in a population; and the repeated Prisoner's Dilemma shows how cooperation can be learned and sustained.
Learning outcomes
- Dynamics
- Run best-response dynamics and fictitious play step by step, and explain when they converge to an equilibrium.
- Regret
- Compute external regret and interpret the no-regret property of the multiplicative weights (Hedge) algorithm.
- Exploration–exploitation
- Trace and compare the ε-greedy and UCB algorithms on the multi-armed bandit problem.
- Evolution and repetition
- Explain replicator dynamics and the success of Tit-for-Tat in the repeated Prisoner's Dilemma.
13.1Introduction
Equilibrium analysis usually solves games "from the outside": the payoff matrix is given, the equilibrium is computed, and the players are assumed to play it. In this chapter the viewpoint changes. Each player is an algorithm. In every round it picks an action, observes the outcome, and updates its rule. The question is no longer "what is the equilibrium?" but "where does this update rule lead in the long run?"
13.1.1Opening game: the multi-armed bandit
The chapter's opening game is a slot machine. The machine has three arms. Each arm pays 1 point with a hidden probability and 0 otherwise. Pulling an arm reveals only that arm's outcome; what the other arms would have paid in that round stays unknown. The goal is to maximize the total reward over a fixed number of pulls. A slot machine with a single lever is called a "one-armed bandit," so the problem with several levers is called the multi-armed bandit problem.
Figure 13.1 shows the situation after eight pulls. Arm 1 has the highest observed mean, 2/3 ≈ 0.67. Arm 3 failed on its only trial. Two reasonable thoughts collide. The first says that Arm 1 looks best and the remaining pulls should go to it. The second says that almost nothing is known about Arm 3: even if its true probability is high, a single failure is not surprising. Trying Arm 3 again yields information, but that pull means giving up the current best guess.
This tension is called the exploration–exploitation dilemma. Exploration means trying little-known options to gather information. Exploitation means using the option that looks best so far. A player who only exploits may get stuck on the wrong arm; a player who only explores never uses what it has learned. For example, in a game of one hundred pulls there is no single right answer to how many pulls should be spent on exploring; the answer depends on how different the arms are and how long the game lasts. Two algorithms (ε-greedy and UCB1) give numerical answers to this question; the opening situation is resolved in 13.4.5.
13.1.2Why learning and adaptation?
First, let us separate two terms. Learning means developing a strategy from past experience. Adaptation means updating the strategy when the opponent or the environment changes. The two often go together: a bidding algorithm learns from yesterday's auctions and adapts again today when the competitors change.
Figure 13.2 shows the skeleton common to all algorithms in this chapter. They differ at only two points: what they observe and how they use the observation. Three observations explain why learning models are needed.
- Computing an equilibrium can be hard. Finding a mixed Nash equilibrium in a general game is a PPAD-complete problem. PPAD-complete is a class of problems for which no fast (polynomial-time) method is known on large games. If even computers cannot find an equilibrium quickly, it is hard to assume that players compute one in their heads. How, then, do players "find" equilibria?
- Players may not know the game. The payoff matrix is often unknown. An advertiser does not see its competitors' valuations; a driver does not see other drivers' route choices. The player only plays and sees the result.
- The real question is the power of simple rules. Do simple, local update rules lead to equilibrium in the long run, or at least to good performance? The answer depends on the rule and the game: some rules reach equilibrium in some games, some cycle, and some are "no-regret" even when they do not reach equilibrium.
The examples are familiar from daily life. Chess and poker AIs learn by playing millions of games against themselves. Bidding algorithms in ad auctions look at the results every day and adjust their bids. Navigation apps change routes according to traffic; since each driver's route affects the other drivers' traffic, this too is a game.
13.1.3Overview of learning models
Six learning models are studied in this chapter. Table 13.1 compares them along two questions: what does the player observe, and how does it update?
| Model | What does the player observe? | How does it update? |
|---|---|---|
| Best-response dynamics | The opponent's last action | Plays the best response to it |
| Fictitious play | The opponent's entire history | Best response to the frequencies |
| Regret minimization (Hedge) | The payoff of every action | Multiplicatively increases the weight of good actions |
| Multi-armed bandit (ε-greedy, UCB) | Only the reward of the chosen action | Average estimate + exploration |
| Reinforcement learning (Q-learning) | Reward and new state | Updates the Q(s, a) values |
| Replicator dynamics | Average success in the population | Successful strategies spread |
Reading the table from top to bottom reveals a trend. In the first two models the player watches the opponent: it knows what the opponent played and computes the best response accordingly. This requires the player to know its own payoff table. In Hedge the player watches not the opponent but the payoffs of its own actions; it does not need to know what the opponent did. In bandits and Q-learning the information shrinks further: only the reward of the chosen action is seen. In the last row the viewpoint moves from the individual to the population; no single player "thinks," and successful behavior simply multiplies.
Another difference among the models is between full feedback and partial feedback. With full feedback the player also learns what the actions it did not play would have paid in that round. For example, whichever stock an investor buys, in the evening the returns of all stocks are visible. With partial feedback only the outcome of the chosen action is seen. For example, a physician who gives a patient one drug never learns what the other drug would have done for that patient. Hedge is designed for full feedback and bandit algorithms for partial feedback; the need for exploration arises from this difference.
Equating the word "learning" with artificial neural networks. Most algorithms in this chapter are a few lines of counters and weight updates. What defines learning is not complexity but that behavior changes according to observed outcomes.
13.2Best response and fictitious play
The simplest learning rules follow directly from the definition of Nash equilibrium. A Nash equilibrium is a profile in which every player best-responds to the others' choices. So if players take turns best-responding, at some point they may reach a profile in which everyone is best-responding, that is, an equilibrium. This section examines when the idea works, when it falls into a cycle, and how the cycle can be broken by remembering the past.
A reminder of some background. Player i's best response to the others' choice s−i is the strategy that maximizes its payoff: BRi(s−i) = argmaxsi ui(si, s−i). In a two-player matrix game, the row player's best response is the row that gives the largest first number in the opponent's column; the column player's best response is the column that gives the largest second number in the opponent's row. A profile is a Nash equilibrium if both players best-respond to each other.
13.2.1Best-response dynamics step by step
Best-response dynamics: start from an initial profile. The players take turns changing their own action so as to best-respond to the opponents' current action. The dynamics stop when no player wants to change its action.
At the moment the dynamics stop, every player is best-responding to the others' actions; this is the definition of a Nash equilibrium. Hence if best-response dynamics stop, they stop at a pure Nash equilibrium. The real question is whether the dynamics stop at all. First, let us look at an example where they do.
| X | Y | Z | |
|---|---|---|---|
| A | (4, 3) | (0, 2) | (1, 1) |
| B | (2, 1) | (3, 3) | (0, 2) |
| C | (1, 4) | (2, 0) | (3, 2) |
In the game of Table 13.2, let the dynamics start from the profile (B, Z). Let the row player move first, then the column player.
- Row player against Z: in column Z the first numbers are A: 1, B: 0, C: 3. The largest is 3, so the row player switches to C. The profile becomes (C, Z).
- Column player against C: in row C the second numbers are X: 4, Y: 0, Z: 2. The largest is 4, so the column player switches to X. The profile becomes (C, X).
- Row player against X: in column X the first numbers are A: 4, B: 2, C: 1. The row player switches to A. The profile becomes (A, X).
- Column player against A: in row A the second numbers are X: 3, Y: 2, Z: 1. The column player is already choosing X (3 > 2, 1); it does not change.
- Row player against X again: A is already the best (4 > 2, 1). Nobody wants to change; the dynamics stop at (A, X), and (A, X) is a Nash equilibrium.
Had the same dynamics started from (C, Y), the outcome would have been different. Against Y the row player sees A: 0, B: 3, C: 2 and switches to B. Against B the column player sees X: 1, Y: 3, Z: 2 and stays at Y. The dynamics stop at the equilibrium (B, Y).
In Figure 13.3 each arrow is a change by a single player. Vertical arrows are moves of the row player (only the row changes, the column stays fixed), and horizontal arrows are moves of the column player. The example yields two important observations. First, the dynamics stopped at an equilibrium; at each step it sufficed for one player to do a local computation, and nobody "solved" for the equilibrium. Second, which equilibrium is reached depends on the starting point. In games with several equilibria the learning rule acts like an equilibrium selection mechanism: dynamics that start at (B, Z) settle at (A, X), and dynamics that start at (C, Y) settle at (B, Y).
- Updating both players at the same time: in this example the players move in turn. Had both best-responded simultaneously, a different path would have been followed; for example, at (B, Z) the row player moves to C and the column player moves to Y, the best response to B, at the same time, and (C, Y) is reached.
- Looking at the wrong number: the row player always wants to maximize the first number and the column player the second. Looking at the row player's payoff when computing the column player's move is the most common error.
13.2.2When do best-response dynamics converge?
The dynamics do not stop in every game. The simplest counterexample is the Matching Pennies game. Two players simultaneously show one face of a coin, Heads (H) or Tails (T). If the faces are the same, the Matcher wins (gets 1, the opponent −1); if they differ, the Mismatcher wins.
| Match. \ Mism. | H | T |
|---|---|---|
| H | (1, −1) | (−1, 1) |
| T | (−1, 1) | (1, −1) |
- At (H, H) the Matcher is winning and is satisfied. The Mismatcher wants a different face and switches to T: (H, T).
- At (H, T) the Mismatcher is satisfied. The Matcher wants the same face and switches to T: (T, T).
- At (T, T) the Mismatcher switches to H: (T, H).
- At (T, H) the Matcher switches to H: (H, H) again. The cycle starts over.
The sequence (H, H) → (H, T) → (T, T) → (T, H) → (H, H) → … goes on forever.
As Figure 13.4 shows, at every step one player is happy and the other is unhappy. The game has no pure Nash equilibrium; in each of the four cells the losing player wants to deviate. So the dynamics cannot stop anywhere. The game's only equilibrium is mixed: both players play H and T with probability ½. Best-response dynamics, however, only jump between pure actions; they never produce "fifty-fifty" behavior, so they cannot reach the mixed equilibrium either.
The question of in which games the dynamics are guaranteed to stop has a well-known answer: potential games.
A game is a potential game if a single function Φ common to all players can be found such that whenever any one player changes its action alone, the change in its own payoff equals the change in Φ.
ui(si′, s−i) − ui(si, s−i) = Φ(si′, s−i) − Φ(si, s−i)
The potential function gathers all the players' selfish calculations into a single "common scoreboard." A player's profitable deviation raises the common score by the same amount. Congestion games, that is, traffic games in which each driver chooses a road and a road's cost depends on the number of drivers using it, are the most important examples of potential games (Monderer and Shapley, 1996).
In a finite potential game, best-response dynamics (and, more generally, any sequence of unilateral changes that strictly increase the mover's payoff at every step) end after finitely many steps; if the sequence is continued until no profitable deviation remains, it stops at a pure Nash equilibrium.
Every step of the dynamics is a profitable deviation: the moving player's payoff strictly increases. By the definition of the potential, this increase equals the increase in Φ; so Φ strictly increases at every step. Since the game is finite, the number of strategy profiles is finite, and therefore the set of values Φ can take is finite. A strictly increasing sequence cannot continue forever in a finite set; nor can it return to the same profile twice, because on returning Φ would take its old value again. Hence the dynamics stop after finitely many steps. At the profile where they stop, no player has a profitable deviation; this profile is a pure Nash equilibrium. □
A corollary follows from the proof: Matching Pennies cannot be a potential game. If it were, each of the four steps in the cycle would increase Φ, and after four steps, when the same profile is reached again, Φ would be larger than its starting value; this is a contradiction. A dynamics that enters a cycle is proof that no potential exists.
Two friends want to use the same software. If both choose A, each gets 2; if both choose B, each gets 1; if they choose differently, they get 0. This is a coordination game, and its potential can be chosen as Φ(A, A) = 2, Φ(B, B) = 1, Φ(A, B) = Φ(B, A) = 0: in every unilateral change, the payoff difference of the player who changes equals the difference in Φ.
- Start at (A, B), Φ = 0. Against B the row player gets 0 with A and 1 with B, and switches to B: (B, B), Φ = 1.
- At (B, B) the column player gets 1 with B and 0 with A; it does not change. The row player does not change either. The dynamics stop at the equilibrium (B, B).
Φ rose from 0 to 1 and stayed there. The dynamics did not go to the equilibrium (A, A) with the higher potential: the convergence guarantee says that some equilibrium will be reached, not that the best equilibrium will be.
For games with no pure equilibrium, the remedy is to respond not only to the last action but to the opponent's entire history. This idea gives rise to fictitious play.
13.2.3Fictitious play: Matching Pennies
Fictitious play: in every round, a player counts the frequencies of the opponent's actions so far and "pretends" that the opponent is using a mixed strategy that plays with these frequencies. It then plays the best response to this mixed strategy.
The "fiction" in the name is the simplifying assumption the player makes about the opponent: the opponent is treated as if it were playing with a fixed die whose probabilities equal the past frequencies. For example, if the opponent has played T in five of seven rounds, it is assumed to play P(H) = 2/7, P(T) = 5/7. The difference from best-response dynamics is that the whole history is used instead of a single last observation. For this reason the belief in fictitious play changes slowly: a single new observation carries a small weight within a long history.
In Matching Pennies this rule takes a very simple form. Since the Matcher wants the same face, it plays whichever face is the majority in the opponent's history. Since the Mismatcher wants a different face, it plays the opposite of the majority in the opponent's history. In case of a tie, both play H. In the first round, with no history, both play H arbitrarily.
That the rule "match the majority" is a best response can be verified with expected payoffs. In round 8 the Matcher sees that the Mismatcher played H twice and T five times in the previous seven rounds; its belief is P(H) = 2/7.
- If the Matcher plays H: 2/7 · 1 + 5/7 · (−1) = −3/7.
- If the Matcher plays T: 2/7 · (−1) + 5/7 · 1 = 3/7.
- Since 3/7 > −3/7, the best response is T; T is the majority in the opponent's history.
In general, if the belief is P(H) = q, the expected payoff of H is 2q − 1 and that of T is 1 − 2q. If q > 1/2, H is better; if q < 1/2, T is better; at q = 1/2 the two are equal and the rule chooses H.
Applying the rule for ten rounds gives Table 13.4. In the table the "history" columns count the rounds before that round, while the "rate" columns include that round.
| t | Mism. history H/T | Matcher | Match. history H/T | Mismatcher | Match. H rate | Mism. H rate |
|---|---|---|---|---|---|---|
| 1 | 0 / 0 | H | 0 / 0 | H | 1.00 | 1.00 |
| 2 | 1 / 0 | H | 1 / 0 | T | 1.00 | 0.50 |
| 3 | 1 / 1 | H | 2 / 0 | T | 1.00 | 0.33 |
| 4 | 1 / 2 | T | 3 / 0 | T | 0.75 | 0.25 |
| 5 | 1 / 3 | T | 3 / 1 | T | 0.60 | 0.20 |
| 6 | 1 / 4 | T | 3 / 2 | T | 0.50 | 0.17 |
| 7 | 1 / 5 | T | 3 / 3 | H | 0.43 | 0.29 |
| 8 | 2 / 5 | T | 3 / 4 | H | 0.38 | 0.38 |
| 9 | 3 / 5 | T | 3 / 5 | H | 0.33 | 0.44 |
| 10 | 4 / 5 | T | 3 / 6 | H | 0.30 | 0.50 |
The first few rows of the table are worth reading in detail.
- t = 1: There is no history; both players play H arbitrarily.
- t = 2: The Matcher sees 1 / 0 in the opponent's history; the majority is H, so it plays H. The Mismatcher also sees 1 / 0 in the opponent's history and plays T, the opposite of the majority.
- t = 3: The Matcher sees 1 / 1 and plays H on the tie. The Mismatcher sees 2 / 0 and plays T.
- t = 4: The Matcher sees 1 / 2; the majority is now T, and the Matcher switches to T. The Mismatcher sees 3 / 0 and stays at T. The Matcher's H rate drops to 3/4 = 0.75.
- t = 7: The Mismatcher sees 3 / 3 and switches to H on the tie. It thus answers the Matcher's shift to T with a delay of three rounds.
The actions still cycle: first (H, H), then (H, T), (T, T) and (T, H). There is, however, an important difference from best-response dynamics. Each phase lasts several rounds, because for the belief to reverse, the majority in the past must change. The rates do not jump; they change gradually: at the end of ten rounds the Matcher's H rate is 0.30 and the Mismatcher's is 0.50.
- Looking at one's own history: in fictitious play a player counts the opponent's history. The Matcher does not decide by its own count of H.
- Including the current round in the history: the decision in round t is based on the rounds before round t. The action of the current round is not yet known.
- Thinking that the actions converge to equilibrium: what approaches the equilibrium is the frequencies; the action played in each round is still a pure H or T.
13.2.4Code trace: fictitious()
The following function runs fictitious play in Matching Pennies for T rounds. Actions are encoded by numbers: 0 = H, 1 = T.
def fictitious(T):
nm, nx = [0, 0], [0, 0] # H/T counters
a, b = 0, 0 # round 1: both H
for t in range(1, T + 1):
nm[a] += 1 # matcher's history
nx[b] += 1 # mismatcher's history
# matcher: match the mismatcher's majority
a = 0 if nx[0] >= nx[1] else 1
# mismatcher: avoid the matcher's majority
b = 1 if nm[0] > nm[1] else 0
return nm, nxThe parts of the code are as follows.
nmandnxare counter lists.nm[0]holds how many times the Matcher has played H so far andnm[1]how many times it has played T;nxholds the same information for the Mismatcher.aandbare the actions to be played in this round; in the first round both are initialized to 0 (H).- At the start of the loop the actions of this round are added to the counters; that is, the round has been played.
- Next, the actions of the following round are computed. The Matcher plays H if the Mismatcher's H count is not smaller than its T count (including ties):
a = 0 if nx[0] >= nx[1] else 1. - The Mismatcher plays T if the Matcher's H count is strictly greater than its T count, and H otherwise:
b = 1 if nm[0] > nm[1] else 0. On a tie the condition is false and H is chosen; this is the "H on ties" rule of the table.
Let the call be fictitious(6). Table 13.5 shows the state of the counters at the end of each round and the decision for the next round.
| Round | Played (a, b) | Winner | nm | nx | Next round |
|---|---|---|---|---|---|
| 1 | (H, H) | Matcher | 1 / 0 | 1 / 0 | (H, T) |
| 2 | (H, T) | Mismatcher | 2 / 0 | 1 / 1 | (H, T) |
| 3 | (H, T) | Mismatcher | 3 / 0 | 1 / 2 | (T, T) |
| 4 | (T, T) | Matcher | 3 / 1 | 1 / 3 | (T, T) |
| 5 | (T, T) | Matcher | 3 / 2 | 1 / 4 | (T, T) |
| 6 | (T, T) | Matcher | 3 / 3 | 1 / 5 | — |
The critical moments of the trace are rounds 2 and 3. At the end of round 2 the Mismatcher's counters are equal, 1 / 1; the Matcher keeps playing H on the tie. At the end of round 3 the Mismatcher's counters become 1 / 2 and the Matcher switches to T. The Mismatcher, on the other hand, sees an H majority in the Matcher's history until the end of round 6 and keeps playing T. The function returns nm = [3, 3], nx = [1, 5]. The H rates are 3/6 = 0.50 and 1/6 ≈ 0.17; these agree with row 6 of Table 13.4.
fictitious(6). On the left, the cell (T, T) played in round 6; on the right, the two players' H/T counters: the Matcher 3 / 3 (H rate 0.50), the Mismatcher 1 / 5 (H rate 0.17).13.2.5The long run: frequencies converge to equilibrium
When fictitious play is continued for four hundred rounds, the actions keep changing in cycles: (H, H) → (H, T) → (T, T) → (T, H) → (H, H) … But each cycle is longer than the previous one. As the history grows, more rounds are needed to reverse the majority. The frequencies, however, approach the mixed equilibrium, that is, ½: in four hundred rounds the Matcher's H rate is 0.472 and the Mismatcher's is 0.492.
In Figure 13.6 one can sense why the oscillations die out. When a player's frequency moves away from ½, the opponent's best response turns in the direction that punishes it, and the deviation is corrected after a while. For example, while the Matcher's H rate is above ½, the Mismatcher plays T; the Matcher eventually switches to T and lowers its own H rate. As the history grows, the effect of a single round on the frequency shrinks to 1/t, so the amplitude of the oscillation shrinks as well.
This behavior is not seen in every game. The convergence of frequencies to equilibrium in fictitious play has been proved for the following classes of games:
- Two-player zero-sum games (Robinson, 1951). Matching Pennies belongs to this class.
- 2×2 games, that is, games in which each of the two players has two strategies (Miyasawa, 1961).
- Potential games (Monderer and Shapley, 1996).
On the other hand, Shapley (1964) constructed a general-sum 3×3 game. In this game the actions go around in ever longer cycles and the frequencies never approach any equilibrium. Shapley's example is the classic result showing that the expectation "learning leads to equilibrium in every game" is wrong.
Concluding that "the frequencies converge to equilibrium, so the players are playing the equilibrium." The actions played in each round are pure and the cycle goes on; only the long-run average approaches (½, ½). An observer who looks only at the last rounds sees not the equilibrium but a long run of H or T.
13.3Regret and Hedge
Best-response dynamics and fictitious play assume that the player knows the payoff table and observes the opponent's actions. Here this assumption is weakened. The player does not model the opponent; after each round it only sees what its own actions earned (or would have earned). The opponent may be a human, an algorithm, or a malicious adversary. Under these conditions, what does it mean to "play well"? The answer is the concept of regret.
13.3.1External regret
In everyday language, regret means looking back and saying "I wish I had done that." The definition in learning theory is the numerical version of this feeling. After the game is over, one looks back and asks: had the same action been played from start to finish, what would the best case have earned? The difference between this number and what was actually earned is the regret.
Over T rounds, let the payoff of action i in round t be gt(i) and the action chosen by the algorithm be at. The external regret is the difference between the total of the best fixed action in hindsight and the algorithm's total:
RT = maxi Σt=1T gt(i) − Σt=1T gt(at)
If the algorithm chooses randomly, the second sum is computed with expected payoffs. If RT/T → 0 as T grows, the algorithm is no-regret.
Three details of the definition matter. First, the comparison is made with a fixed action, not with an "oracle" that picks the best action in every round after the fact. Comparing with the oracle would be a race that no algorithm could win. Second, the best fixed action is known only after the game is over; the algorithm does not know it during the game. Third, no-regret is an average-case measure. RT may grow, but it must grow more slowly than T. For example, if RT = 2√T then RT/T = 2/√T goes to zero; the per-round loss vanishes over time. If RT = T/2, the per-round loss is stuck at ½.
In a three-round game with two actions, let the payoffs be g1 = (1, 0), g2 = (0, 1), g3 = (1, 0). Let an algorithm play B, A, A in that order.
- The algorithm's total: 0 with B in round 1, 0 with A in round 2, 1 with A in round 3. Total 1.
- Totals of the fixed actions: always A gives 1 + 0 + 1 = 2, always B gives 0 + 1 + 0 = 1. The best is 2.
- The external regret is R3 = 2 − 1 = 1.
An oracle that picks the best action in every round would have earned 3; but the regret definition uses not this 3 but the 2 of the best fixed action.
13.3.2Why does "follow the leader" fail?
The first rule that comes to mind for reducing regret is this: play the action with the largest total payoff so far. This rule is called follow the leader. It closely resembles fictitious play; it is the best response to the past. Unfortunately, against a badly chosen payoff sequence this rule is a disaster. Table 13.6 is an example; on ties A is chosen.
| t | Previous total A / B | g(A) | g(B) | Follow the leader | Payoff |
|---|---|---|---|---|---|
| 1 | 0.0 / 0.0 | 0.5 | 0.0 | A | 0.5 |
| 2 | 0.5 / 0.0 | 0.0 | 1.0 | A | 0.0 |
| 3 | 0.5 / 1.0 | 1.0 | 0.0 | B | 0.0 |
| 4 | 1.5 / 1.0 | 0.0 | 1.0 | A | 0.0 |
| 5 | 1.5 / 2.0 | 1.0 | 0.0 | B | 0.0 |
| 6 | 2.5 / 2.0 | 0.0 | 1.0 | A | 0.0 |
- t = 1: The totals are equal (0 / 0); A is chosen on the tie. A pays 0.5 in that round. The algorithm's total is 0.5.
- t = 2: The leader is A (0.5 > 0). But in this round A pays 0 and B pays 1; the algorithm gets 0.
- t = 3: The totals are 0.5 / 1.0; the leader is B. In this round B pays 0 and A pays 1; the algorithm again gets 0.
- t = 4, 5, 6: The same pattern continues. The leader is exactly the loser of the round every time; the algorithm's total stays at 0.5.
- Fixed actions: always A gives 0.5 + 0 + 1 + 0 + 1 + 0 = 2.5; always B gives 0 + 1 + 0 + 1 + 0 + 1 = 3. The best fixed action is B.
- Regret: R6 = 3 − 0.5 = 2.5, that is, about T/2.
The trick of the sequence is the small 0.5 difference in the first round. This difference keeps the leader "one step behind" in every round: since the payoffs alternate between 1 and 0, the action that pulled ahead in the previous round pays 0 in this round. As the sequence is extended, the algorithm's total stays at 0.5 while the total of the best fixed action becomes about T/2. The regret grows linearly: RT/T → 1/2, it does not go to zero. Follow the leader is not no-regret.
The source of the problem is that the rule is deterministic. An adversary who knows the rule can compute in advance which action the algorithm will choose and give that action payoff 0 and the other 1. Then the algorithm gets 0 every round. Since the total payoff of the two actions is 1 in every round, over T rounds the two actions' totals add up to T, and the larger of them is at least T/2. So every deterministic algorithm has regret at least T/2 in the worst case. The only way to be no-regret is to play randomly: even if the adversary knows the probabilities, it cannot know which action will come up.
The assumption that "what was best in the past will be best in the future." If payoffs come from a fixed distribution, follow the leader works well. In games, however, the opponents determine the payoffs. If an adversary chooses the payoffs, trusting the past completely is an invitation to be exploited.
13.3.3Multiplicative weights (Hedge)
Follow the leader has two weaknesses: it chooses with certainty, and it fully trusts a small difference. The multiplicative weights algorithm, better known as Hedge, removes both weaknesses at once. The leader is chosen with high probability but not with certainty; if the difference is small, the probabilities stay close to each other.
The Hedge algorithm assigns a weight to each of n actions and uses a parameter η > 0, the learning rate:
- Initially every action gets the same weight: wi = 1.
- In every round, action i is played with probability pi = wi / Σj wj.
- At the end of the round the payoffs of all actions are observed and the weights are updated: wi ← wi · eη·gt(i).
The update rule is multiplicative: the weight of an action with payoff 1 is multiplied by eη, and the weight of an action with payoff 0 does not change. For example, if η = ln 2 is chosen, then eη = 2 and the weight of an action with payoff 1 exactly doubles. For η = 0.5 the factor is e0.5 ≈ 1.65.
When the updates are applied one after another, the weight becomes an exponential function of the action's total payoff. If Gi is the total payoff of action i so far, then wi = eη·Gi, because eη·g1 · eη·g2 · … = eη·(g1 + g2 + …). This form makes it clear that Hedge is a "soft" follow the leader. The leader has the largest Gi, so it receives the largest probability. But if the difference between the totals of two actions is Δ, the ratio of their probabilities is eη·Δ; a small difference means a small advantage. If η grows very large, the ratio goes to infinity and Hedge turns into follow the leader; if η approaches zero, all probabilities become equal and Hedge turns into random play.
If the payoffs lie in the interval [0, 1] and there are n actions, the external regret of Hedge is bounded by
RT ≤ (ln n)/η + η T
If η = √(ln n / T) is chosen, then RT ≤ 2√(T ln n); hence RT/T → 0 and Hedge is no-regret.
The ln n in the bound is the natural logarithm of n; for n = 3, ln 3 ≈ 1.1. The logarithm grows very slowly: even with a thousand actions, ln 1000 ≈ 6.9. This shows that Hedge can learn quickly even among a very large number of actions.
The two terms of the bound measure two separate effects of η. The first term, (ln n)/η, is the price of slow learning: if η is small, the algorithm notices the best action late. The second term, ηT, is the price of overreaction: if η is large, the algorithm reacts too strongly to every fluctuation and becomes exploitable like follow the leader. The best η is the value that minimizes the sum of the two terms. The derivative of the sum f(η) = (ln n)/η + ηT is f′(η) = −(ln n)/η2 + T. Setting the derivative to zero gives η2 = (ln n)/T, that is, η = √(ln n / T). When this value is substituted, both terms equal √(T ln n):
(ln n)/√(ln n / T) = √(T ln n) and √(ln n / T) · T = √(T ln n),
and their sum is 2√(T ln n).
Let us compare two games played with two actions (n = 2, ln 2 ≈ 0.693).
- T = 100: η = √(0.693/100) ≈ 0.083. The bound is 2√(100 · 0.693) = 2√69.3 ≈ 16.7. The regret per round is at most 16.7/100 ≈ 0.17.
- T = 10,000: η ≈ 0.0083. The bound is 2√6931 ≈ 166.5. The regret per round is at most 0.017.
When the number of rounds grew 100-fold, the total bound grew only 10-fold (√100 = 10); the per-round bound fell to one tenth. This is what no-regret means.
The concrete meaning of the bound becomes visible when the sequence that exploits follow the leader is fed to Hedge. Let the six-round sequence of Table 13.6 be given to Hedge with η = 0.5. In round 1 the probabilities are equal and the expected payoff is 0.5 · 0.5 = 0.25. In round 2 the weight of A is e0.25 ≈ 1.28 and that of B is 1; p(A) = 1.28/2.28 ≈ 0.56 and the expected payoff is 0.44 · 1 ≈ 0.44. In the following rounds the probabilities oscillate between 0.56 and 0.44, and about 0.44 is earned each round. After six rounds Hedge's expected total is about 2.44 and its regret is 3 − 2.44 ≈ 0.56. Follow the leader had accumulated a regret of 2.5 on the same sequence. Because Hedge does not fully trust the small difference, the adversary's trick does not work.
Three observations will come up again and again in the rest of the chapter:
- Randomization is essential. Follow the leader is deterministic, so the opponent exploits it; Hedge plays a mixed strategy.
- η is a tuning knob. A large η reacts quickly but is sensitive to noise; a small η is slow but stable.
- Equilibrium in games. If everyone plays no-regret, the empirical distribution of the profiles played approaches the set of coarse correlated equilibria (CCE); if internal regret is minimized, it approaches the set of correlated equilibria (CE); and in zero-sum games the average strategies approach the minimax strategies.
13.3.4Code trace: hedge()
The following function runs Hedge given the list G, which contains the payoff vector of each round, and the learning rate eta, and returns the algorithm's total expected payoff.
import math
def hedge(G, eta):
w = [1.0] * len(G[0])
total = 0.0
for g in G: # each round
W = sum(w)
p = [x / W for x in w]
total += sum(pi * gi for pi, gi in zip(p, g))
w = [x*math.exp(eta*gi) for x, gi in zip(w, g)]
return totalwis the weight list; it starts with 1.0 for each action.- In each round the sum of the weights
Wis computed first, and then each weight is divided byWto obtain the probabilitiesp. totalis the sum of the expected payoffs. The expected payoff of this round is Σ pi · gi;zip(p, g)pairs the two lists element by element.- The last line is the update: each weight is multiplied by eη·gi.
Let there be three experts (actions) A, B, C and let η = 0.5. In the first two rounds the payoffs are g = [1, 0, 0.5], and in the next three rounds g = [0, 1, 0.5]. So A is good in the first two rounds, B is good in the next three, and C is always in the middle. The factors used are: for payoff 1, e0.5 ≈ 1.65; for payoff 0.5, e0.25 ≈ 1.28; for payoff 0, 1.
| Round | w (A, B, C) | W | p | g | Σ p·g | total | new w |
|---|---|---|---|---|---|---|---|
| 1 | 1; 1; 1 | 3.00 | 0.33; 0.33; 0.33 | 1; 0; 0.5 | 0.50 | 0.50 | 1.65; 1.00; 1.28 |
| 2 | 1.65; 1.00; 1.28 | 3.93 | 0.42; 0.25; 0.33 | 1; 0; 0.5 | 0.58 | 1.08 | 2.72; 1.00; 1.65 |
| 3 | 2.72; 1.00; 1.65 | 5.37 | 0.51; 0.19; 0.31 | 0; 1; 0.5 | 0.34 | 1.42 | 2.72; 1.65; 2.12 |
| 4 | 2.72; 1.65; 2.12 | 6.48 | 0.42; 0.25; 0.33 | 0; 1; 0.5 | 0.42 | 1.84 | 2.72; 2.72; 2.72 |
| 5 | 2.72; 2.72; 2.72 | 8.15 | 0.33; 0.33; 0.33 | 0; 1; 0.5 | 0.50 | 2.34 | 2.72; 4.48; 3.49 |
- Round 1: W = 3, probabilities equal (0.33). Expected payoff ⅓ · 1 + ⅓ · 0 + ⅓ · 0.5 = 0.50. Update: A 1 · 1.65, B unchanged, C 1 · 1.28.
- Round 2: W = 1.65 + 1 + 1.28 = 3.93. p(A) = 1.65/3.93 ≈ 0.42: A's share has grown. Expected payoff 0.42 · 1 + 0.33 · 0.5 ≈ 0.58;
totalbecomes 1.08. A's weight rises to 1.65 · 1.65 ≈ 2.72 = e1. - Round 3: W = 5.37, p(A) ≈ 0.51. But in this round B wins: expected payoff 0.19 · 1 + 0.31 · 0.5 ≈ 0.34. Because the algorithm adapts to the past, it is one round late.
- Round 4: The weights of B and C have grown; p ≈ (0.42, 0.25, 0.33). Expected payoff 0.42. At the end of the round all three weights are equal to e ≈ 2.72, because each action's total payoff is 2.
- Round 5: The probabilities are equal again; expected payoff 0.50,
total2.34. The final weights are (2.72, 4.48, 3.49) = (e1, e1.5, e1.25).
The totals of the fixed actions are A: 2, B: 3, C: 2.5. The best fixed action is B and the regret is 3 − 2.34 = 0.66.
hedge() trace. After five rounds the weights are A: 2.72, B: 4.48, C: 3.49; the probabilities of the next round would be 0.25, 0.42 and 0.33.Figure 13.7 shows how Hedge "remembers" through its weights. The final weights depend only on the total payoffs: wi = e0.5 · Gi. The ordering is also the same as the ordering of the totals: B (3) > C (2.5) > A (2). The order in which the payoffs arrived does not change the weights; it changes only what the algorithm earned along the way.
- Mistaking a weight for a probability: a weight such as 2.72 is not a probability; the probability is found by dividing the weight by the total W.
- Adding the payoff to the weight: in Hedge the update is multiplicative (w · eηg), not additive (w + ηg).
- Mistaking the expected payoff for the realized payoff:
totalis the sum of expected payoffs. In a real game one action is drawn in each round and the realized payoff fluctuates around this value.
13.3.5When the opponent learns too
So far the payoff sequence was given from outside. In games, however, the opponent's behavior determines the payoffs, and the opponent can learn too. To see this difference, let us compare two scenarios in Rock-Paper-Scissors. The winner gets 1, a tie gets ½, and the loser gets 0; thus the payoffs lie in [0, 1]. Player 1 learns with Hedge and η = 0.1. (With a fixed η the bound in the theorem does not go to zero; the results below are the values observed for this duration and starting point.) The learning player updates in each round with the expected payoff of its actions.
Scenario 1: a fixed opponent. The opponent plays Rock with probability 0.5, Paper with 0.3 and Scissors with 0.2 in every round. The expected payoff of each of Player 1's actions can be computed.
- Rock: ties against Rock (½), loses to Paper (0), wins against Scissors (1). Expected payoff 0.5 · ½ + 0.3 · 0 + 0.2 · 1 = 0.25 + 0.20 = 0.45.
- Paper: beats Rock, ties with Paper, loses to Scissors: 0.5 · 1 + 0.3 · ½ + 0 = 0.65.
- Scissors: loses to Rock, beats Paper, ties with Scissors: 0 + 0.3 · 1 + 0.2 · ½ = 0.40.
- The best response is Paper. In each round the weight of Paper grows by a factor e0.1 · 0.20 more than that of Rock and e0.1 · 0.25 more than that of Scissors. In Hedge started with equal weights, after n updates p(Paper) = 1 / (1 + e−0.02 n + e−0.025 n).
- At round 100 this probability is about 0.82, and at round 300 it is 0.997.
Against a fixed opponent, Hedge converges to the best response. This is a natural consequence of no-regret: if the opponent does not change, the best fixed action is the best response, and the only way to keep regret small is to play it more and more often.
Scenario 2: a learning opponent. Now the opponent also uses Hedge, and the two players update at the same time. Player 1 starts with probabilities (0.5, 0.3, 0.2) and Player 2 with equal probabilities. As Player 1 drifts toward Paper, Scissors becomes more valuable for Player 2; as Player 2 drifts toward Scissors, Rock becomes more valuable for Player 1. The cycle goes on like this and the target keeps moving.
| round | 100 | 200 | 800 | 1000 |
|---|---|---|---|---|
| P(Rock) in that round | 0.19 | 0.46 | 0.14 | 0.19 |
| average P(Rock) | 0.35 | 0.31 | 0.33 | 0.34 |
Table 13.8 shows two different behaviors. The probability in that round (the last iterate) keeps rotating: it rises from 0.19 to 0.46 and falls to 0.14. Even after a thousand rounds it does not settle. The time average, on the other hand, approaches ⅓, the Rock component of (⅓, ⅓, ⅓), the game's only Nash equilibrium. Against a learning opponent, "reaching the target" is meaningless, because the target moves together with the opponent's behavior. What is stable is the average.
13.3.6Hedge against itself
The same phenomenon is seen more clearly in a game with two actions. In Matching Pennies, let both players use Hedge (η = 0.1). The Matcher's initial weights are (H, T) = (0.8, 0.2), that is, P(H) = 0.8; the Mismatcher's are (0.5, 0.5). The winner gets 1 and the loser 0, and in every round both players update simultaneously with the expected payoffs of their actions.
In Figure 13.8 the blue curve does not settle at the equilibrium; it makes oscillations that grow steadily between 0.1 and 0.9. The mechanism is similar to that in fictitious play. When the Matcher puts weight on H, T becomes more valuable for the Mismatcher; when the Mismatcher drifts to T, T becomes more valuable for the Matcher, and the cycle goes on. The red curve, which is the average of the P(H) values since the start, approaches ½, the minimax strategy: it is 0.498 at round 600.
This observation has a theoretical counterpart. In a two-player zero-sum game, if both players use a no-regret algorithm, their average strategies approach the minimax strategies and the average payoff approaches the value of the game. The learning-based proof of von Neumann's minimax theorem, that is, the equality "max-min = min-max" in zero-sum games, rests on this observation. The idea of the proof is this: if the regret of both players goes to zero, then on average each earns as much as the best fixed action against the opponent's average strategy; when these two statements are combined, the gap between max-min and min-max is squeezed to zero.
Reading the sentence "no-regret algorithms converge to equilibrium" as a statement about the last iterate. The theory gives convergence only for the time average. In Figure 13.8 the last iterate is far from the equilibrium value even after 600 rounds.
13.3.7From regret to equilibrium
Outside zero-sum games, where does the time average of no-regret learning go? The answer is two equilibrium concepts that are broader than Nash equilibrium. The easiest way to explain these concepts is to imagine a recommendation device. In each round the device draws an action profile from a probability distribution and tells each player only its own action. A traffic light at an intersection is such a device: it tells one driver "go" and the other "stop."
A distribution σ over action profiles is
- a correlated equilibrium (CE) if, for every player, following the recommendation is no worse than deviating, after seeing its recommendation;
- a coarse correlated equilibrium (CCE) if, for every player, committing before seeing the recommendation to "I will always play a′, whatever the recommendation is" does not increase its expected payoff.
The difference between the two definitions lies in the moment of deviation. In a CE the player decides after seeing the recommendation; so deviations that depend on the recommendation, such as "play Straight when the recommendation is Swerve," are also taken into account. In a CCE the player, before seeing the recommendation, considers leaving the device altogether and switching to a fixed action. Since the conditions of a CE hold separately for each recommendation, they hold on average as well; so every CE is a CCE. The converse is not true: CCE is the weaker, that is, the broader concept.
The nested structure in Figure 13.9 is read as follows. Every pure Nash equilibrium is a mixed Nash equilibrium (one with probabilities 0 or 1). Every mixed Nash equilibrium is a CE: when the players throw independent dice, the player who sees its recommendation learns nothing new about the others and is already best-responding in equilibrium. Every CE is also a CCE. Going outward, the concepts get broader but easier to compute: CE and CCE are found quickly by linear programming, whereas a mixed Nash equilibrium is PPAD-complete.
If the external regret of all players repeatedly playing a game satisfies RT/T ≤ ε, then the time-average distribution of the profiles played over T rounds (the fraction of rounds in which each profile was played) is an ε-CCE. For algorithms that minimize a stronger kind of regret, internal regret, the time average of the play approaches the set of CE, that is, it becomes an ε-CE as T grows (Foster and Vohra, 1997; Hart and Mas-Colell, 2000; Blum and Mansour, 2007).
Let the profiles played be s1, …, sT and let σ be their time-average distribution: drawing a profile from σ means choosing a random round among 1, …, T and taking that round's profile. Player i's payoff in round t is gt(a) = ui(a, s−it). The regret condition says that for every fixed a′
Σt ui(a′, s−it) − Σt ui(st) ≤ RT ≤ εT
Dividing both sides by T turns the sums into averages. The average is the expected value under σ: Es∼σ[ui(a′, s−i)] − Es∼σ[ui(s)] ≤ ε. This inequality says that the deviation "always play a′ without seeing the recommendation" gains at most ε; it is the CCE definition satisfied up to a margin of ε. □
Internal (swap) regret asks, separately for each pair (a, a′), "what would I have earned if, in every round in which I played a, I had played a′ instead?" This is the learning-theoretic counterpart of a deviation that depends on the recommendation: "play a′ when the device says a." External regret compares all rounds with a single fixed action, so it is a coarser measure and leads to a coarser equilibrium.
Consider the game of Chicken between two drivers at an intersection. The actions are Swerve (stop) and Straight (go); the payoffs are (Swerve, Swerve) = (0, 0), (Swerve, Straight) = (−1, 1), (Straight, Swerve) = (1, −1), (Straight, Straight) = (−10, −10). The traffic light recommends (Swerve, Straight) or (Straight, Swerve) with probability one half each.
- The driver who receives the recommendation "Swerve" knows that the other has been told "Straight" for certain. Obeying gives −1; deviating to Straight gives −10. Obeying is better.
- The driver who receives the recommendation "Straight" knows that the other has been told "Swerve" for certain. Obeying gives 1; deviating to Swerve gives 0. Obeying is better.
- Obeying is best in both recommendations: the light is a correlated equilibrium. Each driver's expected payoff is ½ · (−1) + ½ · 1 = 0.
- The CCE condition holds automatically as well. For example, the deviation "always Straight" gives ½ · 1 + ½ · (−10) = −4.5, since the other is told Swerve and Straight with probability one half each; this is worse than 0. The deviation "always Swerve" gives ½ · 0 + ½ · (−1) = −0.5, which is also worse than 0.
Disobeying the light gains nobody anything. No-regret learning finds equilibria of this kind without a central computer, simply by the players minimizing their own regrets.
- Confusing CE with CCE: Hedge minimizes only external regret and leads to CCE; reaching CE requires algorithms that minimize internal regret.
- Mistaking the average distribution for each player's mixed strategy: a CCE is a joint distribution over profiles; the players' actions may be linked (correlated). This distribution cannot always be written as a product of two independent mixed strategies.
13.4The multi-armed bandit
Hedge sees the payoffs of all actions after every round. In the opening slot machine, however, only the result of the pulled arm is seen. This small difference has a big consequence: information is no longer free. The only way to gather information about an arm is to pull it; if that arm is bad, the pull is a loss of reward. The multi-armed bandit problem is the simplest model of this trade-off between information and reward.
13.4.1The problem, regret, and the exploration–exploitation dilemma
Multi-armed bandit: in a slot machine with K arms, arm i gives a random reward from a distribution with mean μi that is unknown to the player. In each round one arm is pulled and only its reward is seen (partial feedback). With the best arm's mean μ* = maxi μi, the regret over T rounds is measured by
RT = T · μ* − Σt=1T μat
where at is the arm pulled in round t.
This definition of regret carries the same idea as external regret in Hedge: comparison with the best fixed option (here, the best arm). The difference is that means are used rather than realized rewards. This filters out luck: pulling a bad arm and getting 1 by chance does not reduce the regret, because the calculation uses that arm's mean. Each round adds regret equal to how far the pulled arm falls behind the best arm, that is, μ* − μat.
All the difficulty of the problem is concentrated in the exploration–exploitation dilemma. Exploration gathers information about new or little-tried arms. Exploitation uses what looks best so far. An algorithm that only exploits may get stuck on the wrong arm after an unlucky start and never escape. An algorithm that only explores pulls all arms equally and never uses what it has learned; it wastes reward.
Bandit algorithms keep two numbers for each arm: the number of times the arm has been pulled, Ni, and the average of the observed rewards, Qi. The average is not recomputed from scratch each time a new reward arrives; it is updated with the incremental mean formula:
Q ← Q + (r − Q)/N
Here N is the number of pulls after the new reward has been counted. The correctness of the formula is seen with a short calculation. If the average of the previous N − 1 rewards is Q, their sum is (N − 1)Q. When the new reward is added, the new average is ((N − 1)Q + r)/N = (NQ − Q + r)/N = Q + (r − Q)/N. The interpretation of the formula is also clear: the estimate moves by 1/N in the direction of the "surprise" r − Q. The estimate of an arm that has been pulled many times changes little with a single observation.
Let an arm's rewards be, in order, 1, 1, 1, 0, 1.
- N = 1: Q = 0 + (1 − 0)/1 = 1.
- N = 2: Q = 1 + (1 − 1)/2 = 1. N = 3: again 1.
- N = 4: Q = 1 + (0 − 1)/4 = 0.75.
- N = 5: Q = 0.75 + (1 − 0.75)/5 = 0.75 + 0.05 = 0.80.
The result is the same as the direct average of the five rewards (4/5 = 0.80).
Figure 13.10 shows the basic idea of the UCB1 algorithm (13.4.3). The estimate of a rarely tried arm is uncertain, so its confidence interval is wide. The upper end of the interval, that is, "the best value this arm could have," makes the arm worth trying again. Even though its estimate is low, arm 1's upper end is 1.09, close to arm 2's 1.18.
The application area of the bandit problem extends far beyond game theory: recommender systems that decide which ad or news item to show, A/B tests that compare two designs on websites, clinical trials in which the allocation of patients to the better treatment is adjusted during the trial, and price experiments in which a product is tried at different prices.
13.4.2Code trace: ε-greedy
The simplest bandit algorithm is ε-greedy. In each round, with a small probability ε it pulls a random arm (exploration); with the remaining probability 1 − ε it pulls the arm with the largest Q (exploitation). The name "greedy" comes from the exploitation step blindly trusting the current best estimate.
def egreedy(mu, T, eps, rng):
N, Q = [0] * len(mu), [0.0] * len(mu)
for t in range(1, T + 1):
if rng.random() < eps: # explore
a = rng.randrange(len(mu))
else: # exploit
a = Q.index(max(Q))
r = 1 if rng.random() < mu[a] else 0
N[a] += 1
Q[a] += (r - Q[a]) / N[a]
return N, Qmuholds the true means of the arms. The algorithm uses this list only to generate rewards; it does not look atmuwhen deciding.rng.random()produces a random number between 0 and 1. If the number is smaller thaneps, the algorithm explores and picks a random arm withrng.randrange(len(mu)).- When exploiting,
Q.index(max(Q))finds the arm with the largest estimate. In case of a tie, the first arm in the list is chosen. - The reward is a coin flip determined by the arm's mean: if a new random number is smaller than
mu[a]the reward is 1, otherwise 0. - The last two lines are the counter and the incremental mean update.
Let the call be egreedy([0.3, 0.5, 0.7], 8, 0.2, random.Random(11)). In the code the arms are numbered from 0: arms 0, 1, 2 correspond to Arms 1, 2, 3 in the opening game. Since the random number generator is initialized with seed 11, the call gives the same result every time it is run; the trace below is therefore reproducible.
| t | Random number | Decision | Arm | r | N | Q |
|---|---|---|---|---|---|---|
| 1 | 0.452 | exploit (first on tie) | 0 | 0 | [1, 0, 0] | [0.00, 0.00, 0.00] |
| 2 | 0.924 | exploit (first on tie) | 0 | 0 | [2, 0, 0] | [0.00, 0.00, 0.00] |
| 3 | 0.508 | exploit (first on tie) | 0 | 0 | [3, 0, 0] | [0.00, 0.00, 0.00] |
| 4 | 0.185 | explore | 2 | 1 | [3, 0, 1] | [0.00, 0.00, 1.00] |
| 5 | 0.614 | exploit | 2 | 1 | [3, 0, 2] | [0.00, 0.00, 1.00] |
| 6 | 0.447 | exploit | 2 | 1 | [3, 0, 3] | [0.00, 0.00, 1.00] |
| 7 | 0.539 | exploit | 2 | 0 | [3, 0, 4] | [0.00, 0.00, 0.75] |
| 8 | 0.634 | exploit | 2 | 1 | [3, 0, 5] | [0.00, 0.00, 0.80] |
- t = 1–3: The random numbers are larger than 0.2; all three are exploitation. Since all estimates are 0, the first arm on the tie, arm 0, is chosen. Arm 0 gives 0 all three times; its estimate stays at 0 and the tie is never broken.
- t = 4: The random number 0.185 < 0.2: exploration. The randomly chosen arm is 2 and it gives 1. N[2] = 1, Q[2] = 1.00.
- t = 5–6: Exploitation; the largest estimate is now at arm 2. Both pulls give 1; Q[2] stays at 1.
- t = 7: Arm 2 gives 0 this time: Q[2] = 1 + (0 − 1)/4 = 0.75.
- t = 8: Arm 2 gives 1: Q[2] = 0.75 + (1 − 0.75)/5 = 0.80.
The function returns N = [3, 0, 5]. The regret over the eight rounds is 8 · 0.7 − (3 · 0.3 + 5 · 0.7) = 5.6 − 4.4 = 1.2; all of it comes from the first three rounds spent on arm 0.
The trace shows both faces of ε-greedy at once. The negative face: for the first three rounds it was stuck on arm 0, because all pulls gave 0 and the tie rule chose the first arm. Without exploration the algorithm could have stayed on arm 0 forever; even if arm 0 gave 1 once, its estimate would exceed the 0 of the other arms and exploitation would keep choosing it. The positive face: a single exploration found the best arm. Figure 13.11 also shows a shortcoming: arm 1 was never tried. In eight rounds this does not matter, but the exploration of ε-greedy is blind randomness; it does not specifically look for little-known arms.
13.4.3Code trace: UCB1
The exploration of ε-greedy is "blind": in an exploration round every arm is chosen with equal probability, both the arm already known to be best and an arm never tried. UCB1 (Upper Confidence Bound) directs exploration. Each arm has a score:
UCBi = Qi + √(2 ln t / Ni)
Here t is the current round number and Ni is the number of times the arm has been pulled. In each round the arm with the largest score is pulled. The score of an arm that has never been pulled is taken to be infinite; so in the first rounds every arm is tried once.
The score has two terms. The first term, Qi, is exploitation: an arm that looks good gets a high score. The second term, √(2 ln t / Ni), is the confidence bonus and represents exploration. The bonus shrinks as Ni grows: the estimate of a much-pulled arm can be trusted. The bonus grows very slowly (logarithmically) as t grows: the bonus of an arm that has not been pulled for a long time slowly increases, and eventually the arm is tried again. This idea is called optimism in the face of uncertainty: each arm is evaluated at the most optimistic value that does not contradict the data. If a bad arm is chosen on an optimistic evaluation, it soon shows its true face and its bonus shrinks; a good arm, on the other hand, deserves the optimistic evaluation.
import math
def ucb(mu, T, rng):
K = len(mu)
N, Q = [0] * K, [0.0] * K
for t in range(1, T + 1):
b = [math.inf if n == 0 else
math.sqrt(2*math.log(t)/n) for n in N]
a = max(range(K), key=lambda i: Q[i] + b[i])
r = 1 if rng.random() < mu[a] else 0
N[a] += 1
Q[a] += (r - Q[a]) / N[a]
return N, Qbholds each arm's confidence bonus.math.infis the infinite bonus of an arm that has never been pulled.max(range(K), key=lambda i: Q[i] + b[i])chooses the arm with the largest score Q + b; on a tie the arm with the smaller index wins.- The reward and the update are as in ε-greedy.
Let the call be ucb([0.3, 0.5, 0.7], 8, random.Random(3)). Table 13.10 gives the bonuses, scores and choice in each round.
| t | bonus b | UCB = Q + b | Arm | r | Q (after) | N (after) |
|---|---|---|---|---|---|---|
| 1 | ∞, ∞, ∞ | ∞, ∞, ∞ | 0 | 1 | 1.00; 0; 0 | 1, 0, 0 |
| 2 | 1.18; ∞; ∞ | 2.18; ∞; ∞ | 1 | 0 | 1.00; 0.00; 0 | 1, 1, 0 |
| 3 | 1.48; 1.48; ∞ | 2.48; 1.48; ∞ | 2 | 1 | 1.00; 0.00; 1.00 | 1, 1, 1 |
| 4 | 1.67; 1.67; 1.67 | 2.67; 1.67; 2.67 | 0 | 0 | 0.50; 0.00; 1.00 | 2, 1, 1 |
| 5 | 1.27; 1.79; 1.79 | 1.77; 1.79; 2.79 | 2 | 1 | 0.50; 0.00; 1.00 | 2, 1, 2 |
| 6 | 1.34; 1.89; 1.34 | 1.84; 1.89; 2.34 | 2 | 1 | 0.50; 0.00; 1.00 | 2, 1, 3 |
| 7 | 1.39; 1.97; 1.14 | 1.89; 1.97; 2.14 | 2 | 1 | 0.50; 0.00; 1.00 | 2, 1, 4 |
| 8 | 1.44; 2.04; 1.02 | 1.94; 2.04; 2.02 | 1 | 0 | 0.50; 0.00; 1.00 | 2, 2, 4 |
- t = 1, 2, 3: The bonus of arms never tried is infinite; the arms are pulled once each in order. The rewards are 1, 0, 1.
- t = 4: Every arm has been pulled once: the bonus is √(2 ln 4 / 1) = √2.77 ≈ 1.67, the same for all three arms. The scores are 1 + 1.67 = 2.67, 0 + 1.67 = 1.67, 2.67. Arms 0 and 2 tie; the smaller index, arm 0, is chosen and gives 0. Q[0] = 0.50.
- t = 5: Arm 0 has been pulled twice: its bonus is √(2 ln 5 / 2) = √1.61 ≈ 1.27. The others' bonus is √(2 ln 5) ≈ 1.79. The scores are 1.77, 1.79, 2.79. Arm 2 is chosen and gives 1.
- t = 6, 7: Arm 2 keeps winning. But its bonus shrinks with each pull (1.34 → 1.14), while arm 1's bonus grows (1.89 → 1.97).
- t = 8: Arm 1's bonus has reached √(2 ln 8 / 1) = √4.16 ≈ 2.04; its score is 2.04. Arm 2's score is 1 + √(4.16/4) = 1 + 1.02 = 2.02. Arm 1 edges ahead and is tried again.
The function returns N = [2, 2, 4]. Arm 1's single trial gave 0 and its estimate is 0; it is nevertheless tried again in round 8. Exploration arises from the uncertainty itself, without the need for a separate parameter.
Comparing the two traces is instructive. ε-greedy never tried arm 1; UCB1 tried every arm and revisited even the arm with a low estimate once it had not been pulled for a long time. Because UCB1 explored more in eight rounds, it pulled non-best arms more often (four rounds against three). But since two of those rounds went to the middle arm (arm 1), its regret is again 8 · 0.7 − (2 · 0.3 + 2 · 0.5 + 4 · 0.7) = 5.6 − 4.4 = 1.2. In the short run the two algorithms are in the same place; the difference appears in the long run.
- Computing the bonus with the wrong t: t is the current round number (starting from 1), not the number of times the arm has been pulled. At t = 8, ln 8 is used in the bonus of all arms.
- Choosing the largest Q: UCB1 chooses not the largest estimate but the largest upper bound. In round 8 the largest estimate is at arm 2 (1.00) but the chosen arm is arm 1.
- Using log₁₀ instead of ln: the ln in the formula is the natural logarithm; ln 8 ≈ 2.08, log10 8 ≈ 0.90.
13.4.4Comparison: 5000 rounds, 100 repetitions
The eight-round traces show how the algorithms work, but not which is better. Since the rewards are random, a single experiment is misleading. The comparison is done as follows: the arms are again μ = (0.3, 0.5, 0.7); each algorithm is run for 5000 rounds; the experiment is repeated with 100 different seeds from 0 to 99, and the cumulative regrets are averaged. In this comparison ε-greedy runs with ε = 0.1.
Figure 13.13 shows three different growth rates.
- Pure exploitation (ε = 0): since all estimates start at 0, the first round pulls arm 0. If arm 0 gives 1 once, its estimate becomes positive and the other arms are never tried; if it always gives 0, the tie again chooses arm 0. In every case the algorithm gets stuck on arm 0. Each round adds 0.7 − 0.3 = 0.4 regret: RT = 0.4 · T, linear.
- ε-greedy: even after finding the best arm, it explores in 10% of the rounds. In an exploration round the arms are chosen with equal probability and the average loss is (0.4 + 0.2 + 0)/3 = 0.2. So each round adds about 0.1 · 0.2 = 0.02 regret; over 5000 rounds this comes to about 100. Together with the initial learning losses the average is 118. The regret grows linearly, but with a small slope.
- UCB1: it explores more at the start. Its regret is higher than ε-greedy's between about rounds 270 and 2,370. After that it stays lower, because UCB1's regret is logarithmic, that is, it grows very slowly (Auer, Cesa-Bianchi and Fischer, 2002). Since the confidence bonus of a bad arm is √(2 ln t / N), for that arm to be tried again N only has to grow in proportion to ln t; the number of pulls spent on bad arms therefore grows only like ln t.
How slowly logarithmic growth proceeds can be seen from numbers: ln 1000 ≈ 6.9, ln 1,000,000 ≈ 13.8. When the number of rounds grows a thousandfold, the logarithm only doubles. With linear regret, a thousandfold increase in the number of rounds raises the regret a thousandfold. In long games this difference is decisive.
ε is a tuning parameter, and three different values are used in this chapter: 0.2 so that exploration is visible in the short trace, 0.1 in the long comparison, and 0.15 in the Multi-Armed Bandit game. A small ε means less exploration but slower correction after a wrong start. Logarithmic regret cannot be obtained with a fixed ε; for that, ε has to be decreased over time.
Seeing in the chart that ε-greedy has less regret at round 1000 and concluding that "ε-greedy is better." The answer to the comparison depends on the length of the game. In short games a simple ε-greedy can do well; in long games an algorithm with logarithmic regret is bound to overtake one with linear regret.
13.4.5Back to the game: the price of exploration
We can return to the opening game with the theory's answer. For arms μ = (0.3, 0.5, 0.7), the expected reward and regret of different strategies over 100 rounds are given in Table 13.11.
| Strategy | Reward | Regret |
|---|---|---|
| always random (exploration only) | 50 | 20 |
| sticking to the 0.5 arm | 50 | 20 |
| ε-greedy, ε = 0.15 (after finding the best arm) | 67 | 3 |
| always the best arm | 70 | 0 |
- Always random: in each round the arms are chosen with equal probability; the expected reward per round is (0.3 + 0.5 + 0.7)/3 = 0.5. Over 100 rounds, 50; regret 70 − 50 = 20.
- Sticking to the 0.5 arm: 0.5 per round; again 50 and 20.
- ε-greedy (ε = 0.15), after finding the best arm: per round 0.85 · 0.7 + 0.15 · 0.5 = 0.595 + 0.075 = 0.67. Over 100 rounds, 67; regret 3. Here 0.5 is the expected reward of the arm chosen at random in an exploration round.
- Always the best arm: 70; this is the limit that someone who knows the true means can reach.
The table clearly shows that exploration has a price. Knowing the best arm is worth 3 points; ε-greedy loses these 3 points because it keeps exploring even after finding the best arm. UCB1 directs exploration toward little-tried arms, so it reduces this price over time; its regret grows logarithmically.
The opening question. In the situation of Figure 13.1, Arm 3's single failed pull gives very little information. The next round is t = 9 and 2 ln 9 ≈ 4.39. The UCB1 scores are:
- Arm 1 (Q = 0.67, N = 3): 0.67 + √(4.39/3) = 0.67 + 1.21 ≈ 1.88.
- Arm 2 (Q = 0.25, N = 4): 0.25 + √(4.39/4) = 0.25 + 1.05 ≈ 1.30.
- Arm 3 (Q = 0, N = 1): 0 + √4.39 ≈ 2.10.
UCB1 chooses Arm 3. A single failure is not enough evidence to set an arm aside.
How do humans decide? In a four-armed bandit experiment, the choices of human subjects were explained better by probabilistic choice according to value differences than by UCB-like exploration that gives a bonus to uncertainty (Daw et al., 2006). This choice rule is called softmax choice: the probability of choosing an arm is proportional to an exponential function of its estimated value. This rule has the same form as pi ∝ eη·Gi in Hedge.
Ranking algorithms from a single experiment. The rewards are random; with a lucky seed ε-greedy can easily beat UCB1, and with an unlucky seed UCB1 can beat ε-greedy. Comparisons are always made by averaging many experiments.
13.5Reinforcement learning
In the bandit problem each round is independent of the others: whichever arm is pulled today, tomorrow the machine is the same machine. In many real problems, however, today's action changes tomorrow's situation. In chess a move changes the board; a robot's step changes its position. This section treats learning problems in which actions also affect the future state.
13.5.1From bandits to reinforcement learning: Q-learning
The bandit is a single-state problem. In reinforcement learning (RL), by contrast, an action determines the next state as well as the reward. The state is where the agent is: the arrangement on a board, a cell in a maze, or the joint angles of a robot. The value of an action can no longer be measured only by the reward it gets immediately; the rewards that the state it reaches will provide in the future must also be counted. A state one step away from the goal is valuable even if it gives no reward.
Q-learning (Watkins, 1989) keeps a value estimate for each state–action pair: Q(s, a) answers the question "if action a is taken in state s and play continues optimally afterward, what is the total payoff?" When the agent takes action a in state s, receives reward r and moves to state s′, it updates the estimate as follows:
Q(s, a) ← Q(s, a) + α [ r + γ · maxa′ Q(s′, a′) − Q(s, a) ]
α is the learning rate: it determines how much the new information is trusted. γ is the discount factor: it determines the present value of future reward (0 ≤ γ < 1). The first two terms inside the square brackets, r + γ · max Q(s′, ·), are the target of the update.
The structure of the formula is the same as the bandit's incremental mean: "new estimate = old estimate + step × (target − old estimate)." The difference is in the target. In the bandit the target was just the observed reward. In Q-learning the target is the discounted sum of the observed reward and the best value of the state reached. The term maxa′ Q(s′, a′) carries the assumption that the best action will be taken after reaching s′. This means that Q-learning learns by using its own estimates: part of the target is itself an estimate.
The meaning of γ becomes clear with an example. If γ = 0.9, 1 point arriving one step later is worth 0.9 today, and 1 point arriving two steps later is worth 0.92 = 0.81. If γ is near zero the agent looks only at the immediate reward (it is myopic); if it is near 1 it cares about the distant future as well.
Let Q(s, a) = 2, r = 1, γ = 0.9, max Q(s′, ·) = 4, α = 0.5.
- Target: r + γ · max Q(s′, ·) = 1 + 0.9 · 4 = 1 + 3.6 = 4.6.
- Difference (error): 4.6 − 2 = 2.6. The estimate has fallen short of the target.
- Update: Q ← 2 + 0.5 · 2.6 = 2 + 1.3 = 3.3.
The estimate moved halfway (α = 0.5) toward the target. With α = 1 the estimate would jump straight to the target (4.6); with α = 0.1 it would rise only to 2.26.
In a multi-agent setting an important weakness of Q-learning appears. The convergence proof of single-agent Q-learning assumes an environment in which transitions and rewards do not change over time, that is, a stationary environment. In a multi-agent setting, the outcomes an agent sees depend on the behavior of the other agents. As the other agents learn too, the rules of the game keep changing in the agent's eyes: an action that was good yesterday may be bad today. The environment is non-stationary, and the single-agent convergence guarantees no longer hold. One way to manage this problem is self-play (AlphaZero): the agent plays against copies of itself, so the opponent improves together with the agent.
13.5.2Code trace: q_learn()
The environment is a corridor with four cells: s0, s1, s2, s3. In every cell there are two actions: left and right. s3 is the goal; the transition that reaches it gives reward 1 and the episode (one attempt) ends. The reward of the other transitions is 0. The function processes pre-recorded episodes (each a list of (s, a, r, s′) quadruples) in order.
def q_learn(episodes, alpha, gamma):
Q = [[0.0, 0.0] for s in range(4)] # [left, right]
for ep in episodes:
for s, a, r, s2 in ep:
best = 0 if s2 == 3 else max(Q[s2])
target = r + gamma * best
Q[s][a] += alpha * (target - Q[s][a])
return QQis a table with four rows; each row holds the values of the actions [left, right]. Action 0 is left, 1 is right.bestis the best value of the state reached. If the goal has been reached (s2 == 3), the episode ends and there is no future; the value is taken as 0.targetis r + γ · best; the last line is the Q-learning update.
Let the call be q_learn(ep, 0.5, 0.9). ep consists of three episodes. In the first two the agent starts at s0 and goes right three times. In the third, at s1 it goes left once, then proceeds right again.
| Episode | Transition | r | best | target | Update |
|---|---|---|---|---|---|
| 1 | s0 → right → s1 | 0 | 0.000 | 0.000 | Q(s0,right) = 0 + 0.5·(0 − 0) = 0.000 |
| 1 | s1 → right → s2 | 0 | 0.000 | 0.000 | Q(s1,right) = 0.000 |
| 1 | s2 → right → s3 | 1 | 0 (goal) | 1.000 | Q(s2,right) = 0 + 0.5·(1 − 0) = 0.500 |
| 2 | s0 → right → s1 | 0 | 0.000 | 0.000 | Q(s0,right) = 0.000 |
| 2 | s1 → right → s2 | 0 | 0.500 | 0.450 | Q(s1,right) = 0 + 0.5·(0.450 − 0) = 0.225 |
| 2 | s2 → right → s3 | 1 | 0 (goal) | 1.000 | Q(s2,right) = 0.5 + 0.5·(1 − 0.5) = 0.750 |
| 3 | s0 → right → s1 | 0 | 0.225 | 0.203 | Q(s0,right) = 0 + 0.5·(0.203 − 0) = 0.101 |
| 3 | s1 → left → s0 | 0 | 0.101 | 0.091 | Q(s1,left) = 0 + 0.5·(0.091 − 0) = 0.046 |
| 3 | s0 → right → s1 | 0 | 0.225 | 0.203 | Q(s0,right) = 0.101 + 0.5·(0.203 − 0.101) = 0.152 |
| 3 | s1 → right → s2 | 0 | 0.750 | 0.675 | Q(s1,right) = 0.225 + 0.5·(0.675 − 0.225) = 0.450 |
| 3 | s2 → right → s3 | 1 | 0 (goal) | 1.000 | Q(s2,right) = 0.75 + 0.5·(1 − 0.75) = 0.875 |
- Episode 1: In the first two transitions the reward is 0 and the values of the states reached are 0; nothing is learned. Only the last transition brings reward 1, and Q(s2,right) = 0.5. For now, the reward information has reached only one step before the goal.
- Episode 2: In the transition from s1 to s2, best = max Q(s2, ·) = 0.5. The target is 0 + 0.9 · 0.5 = 0.45 and the update is 0.5 · 0.45 = 0.225. The reward has propagated one step further back. s0 is still 0, because its update was made before Q(s1, ·) increased.
- Episode 3, first transition: best = 0.225, the target is 0.9 · 0.225 ≈ 0.203, and Q(s0,right) ≈ 0.101. The reward information has reached the starting cell.
- The deviation to the left: when the agent goes left from s1, best = max Q(s0, ·) = 0.101, the target is 0.091, and Q(s1,left) ≈ 0.046. Going left also gained a little value, because left leads to s0, whose value is no longer zero.
- The remaining transitions: The agent proceeds right again and each update raises the values a little more: Q(s0,right) ≈ 0.152, Q(s1,right) = 0.450, Q(s2,right) = 0.875.
Figure 13.14 summarizes the basic behavior of Q-learning: reward propagates backward from the goal. Q(s2,right) = 0.875 → Q(s1,right) = 0.450 → Q(s0,right) = 0.152. Since Q(right) > Q(left) in every cell, the greedy policy, which chooses the action with the largest Q in every state, says "always go right." The agent has learned this policy although it sees reward only at the last step.
Where would the values go if the same episodes were repeated forever? When the agent always goes right, the target of Q(s2,right) is 1 every time, so Q(s2,right) → 1. The target of Q(s1,right) is 0.9 · Q(s2,right), and it goes to 0.9. Q(s0,right) goes to 0.92 = 0.81. The values decrease with distance from the goal as powers of γ: distant reward is discounted.
- Using max Q in the goal state: the episode ends at the goal; the goal has no future, so best = 0.
- Mixing up the order of updates: within an episode the updates are made in the order of the transitions. When s0 is updated, Q(s1, ·) still has its old value from before that episode; this is why the reward propagates only one step back per episode.
- Adding the target instead of the difference: Q ← Q + α · target is wrong; what is added is α · (target − Q).
13.5.3Beyond Q-learning: methods and milestones
The algorithms so far are the simplest members of a broad family. Some of the family's other important members are the following:
- Thompson sampling (Thompson, 1933): a Bayesian method for bandits. For each arm it keeps a probability distribution of the form "its mean could be this"; this distribution is a posterior updated with the observations. In each round a sample is drawn from each arm's distribution and the arm with the largest sample is played. An uncertain arm is explored automatically because it sometimes gives a high sample; it is a probabilistic counterpart of the optimism in UCB1.
- Win-Stay Lose-Shift (WSLS; Nowak and Sigmund, 1993): a rule for the Prisoner's Dilemma. If 3 or 5 points were received, the same move is repeated; if 0 or 1 were received, the move is changed. After a single mistake it returns to cooperation in two rounds.
- EXP3: Hedge that sees only the reward of the pulled arm; it is designed for the adversarial bandit. Even if a malicious opponent chooses the rewards, its regret grows more slowly than T (Auer, Cesa-Bianchi, Freund and Schapire, 2002).
- SARSA and DQN: relatives of Q-learning. DQN uses a neural network instead of a Q table; this lets it work on problems with too many states to fit in a table (for example, Atari games from screen images) (Mnih et al., 2015).
- CFR (counterfactual regret minimization): a regret-based method for poker. It keeps a separate regret at each decision point of the game and minimizes them (Zinkevich et al., 2007).
| Year | System | Method |
|---|---|---|
| 1992 | TD-Gammon (backgammon) | self-play |
| 2017–19 | Libratus, Pluribus (poker) | CFR (regret) |
| 2018 | AlphaZero (chess, Go) | self-play |
Games are a good laboratory for reinforcement learning: the rules are explicit, the reward is clear (winning or losing), and the game can be repeated millions of times. Table 13.13 shows that two approaches stand out. In games of perfect information (backgammon, chess, Go), self-play succeeded. In games of imperfect information, especially poker, regret-based methods came to the fore because the opponent's cards are not visible. The success in poker is directly connected to the theory of this chapter: because CFR minimizes regret in a two-player zero-sum game, its time average approaches the minimax strategy.
13.6Evolutionary dynamics
In all the models so far there was a learning individual: a player that keeps counters, updates weights, makes estimates. In evolutionary game theory the individual learns nothing. Each individual is born with a single strategy and plays it for its whole life. What changes is the composition of the population: individuals carrying the successful strategy leave more offspring, and that strategy spreads. There is no rationality, there is selection. The surprising thing is that this "mindless" process often arrives where the Nash equilibrium predicts.
13.6.1Replicator dynamics and the ESS
The model is as follows. In a large population, individuals are randomly paired and play a game against each other. Each individual plays a single strategy and passes it on to its offspring. The success of a strategy is measured by the average payoff of an individual playing it against an opponent drawn at random from the population.
Let xi be the share of strategy i in the population. Let fi be the average payoff of strategy i, called its fitness, and let f̄ = Σj xj fj be the population's average payoff. The discrete replicator dynamics updates the shares in each generation as follows:
new share = old share × fi / f̄, that is, xi′ = xi · fi / f̄
The formula follows from the assumption that the number of offspring is proportional to fitness. Let ni individuals in the population play strategy i, and let each leave fi offspring. In the new generation ni fi individuals play i. The new share is the ratio of this to the total number of offspring: ni fi / Σj nj fj. Dividing numerator and denominator by the total population n gives xi fi / Σj xj fj = xi fi / f̄.
The formula's interpretation is a single sentence: a strategy that earns above the average spreads. If fi > f̄ then fi/f̄ > 1 and the share grows; if fi < f̄ the share shrinks. The shares always remain a distribution that sums to 1. For the formula to make sense, the fitnesses must be positive: a negative fitness would mean a negative number of offspring. For this reason a constant baseline (3) is added to every payoff here. Adding a baseline does not change the ranking of the strategies or the rest points; it only affects the speed of the dynamics. (In the continuous-time version one writes ẋi = xi(fi − f̄); the discrete form suffices here.)
The equilibrium concept of the evolutionary viewpoint is the evolutionarily stable strategy (ESS; Maynard Smith and Price, 1973).
A strategy x is evolutionarily stable if, when the whole population plays x, a small group of mutants playing another strategy y cannot invade the population. Formally, for every y ≠ x
u(x, x) > u(y, x) or [u(x, x) = u(y, x) and u(x, y) > u(y, y)]
must hold, where u(a, b) is the payoff of an individual playing a against an opponent playing b.
The two parts of the condition explain why the mutant cannot spread. When mutants are few, almost all their pairings are with resident x-players. The first condition says that in these pairings the mutant earns less than the residents; the mutant quickly recedes. If the first condition holds with equality, what decides is the rare mutant–mutant pairings: the second condition says that when meeting a mutant, the resident earns more than the mutant. Every ESS is a symmetric Nash equilibrium (the inequality of the first condition always holds as ≥); but not every Nash equilibrium is an ESS.
The example game is Hawk–Dove. Individuals meet over a resource of value V = 4. The Hawk always fights; the Dove makes a display but retreats if a fight starts. The cost of fighting is C = 6.
- Two hawks fight: one wins (V), one is injured (−C); the average is (V − C)/2 = (4 − 6)/2 = −1.
- A hawk against a dove takes the resource: V = 4; the dove gets 0.
- Two doves share the resource: V/2 = 2.
In the game of Figure 13.15 no pure strategy is an ESS. If the whole population is dove, a hawk mutant gets 4 in every pairing while doves get 2; hawks spread. If the whole population is hawk, a dove mutant gets 0 while hawks get −1; doves spread. At both extremes the minority strategy has the advantage. So the population must settle at a mixture.
13.6.2Hawk–Dove step by step
Let the hawk share be x and the dove share 1 − x. A hawk enters a pairing in which its opponent is a hawk with probability x and a dove with probability 1 − x. The fitnesses with the baseline 3 added:
fH = 3 + (−1) · x + 4 · (1 − x) = 7 − 5x, fD = 3 + 0 · x + 2 · (1 − x) = 5 − 2x
The population average is f̄ = x · fH + (1 − x) · fD, and the new hawk share is x′ = x · fH / f̄.
Let hawks initially be 10% of the population (x = 0.100).
- Fitnesses: fH = 7 − 5 · 0.1 = 6.50, fD = 5 − 2 · 0.1 = 4.80.
- Average: f̄ = 0.1 · 6.50 + 0.9 · 4.80 = 0.65 + 4.32 = 4.97.
- New share: x′ = 0.1 · 6.50 / 4.97 = 0.65 / 4.97 ≈ 0.131.
- Since fH > f̄, hawks increased. In the next generation the same calculation is made with x = 0.131: fH = 6.35, fD = 4.74, f̄ ≈ 4.95, x′ ≈ 0.168.
| generation | x (hawk share) | fH | fD | f̄ | new x = x·fH/f̄ |
|---|---|---|---|---|---|
| 0 | 0.100 | 6.50 | 4.80 | 4.97 | 0.131 |
| 1 | 0.131 | 6.35 | 4.74 | 4.95 | 0.168 |
| 2 | 0.168 | 6.16 | 4.66 | 4.92 | 0.210 |
| 3 | 0.210 | 5.95 | 4.58 | 4.87 | 0.257 |
| 4 | 0.257 | 5.72 | 4.49 | 4.80 | 0.306 |
| 5 | 0.306 | 5.47 | 4.39 | 4.72 | 0.354 |
| 6 | 0.354 | 5.23 | 4.29 | 4.62 | 0.401 |
| 7 | 0.401 | 5.00 | 4.20 | 4.52 | 0.443 |
Table 13.14 shows two trends together. The hawk share rises every generation, because fH > f̄ in every row. But the hawks' advantage steadily shrinks: fH falls from 6.50 to 5.00, and the difference fH − fD from 1.70 to 0.80. As hawks multiply, they meet each other more often and get into costly fights. The increase slows down; the population approaches a rest point.
13.6.3From every starting point to the ESS
The rest point is the share at which the two strategies earn equally; at that point fH = fD = f̄ and the share does not change:
7 − 5x = 5 − 2x ⇒ 2 = 3x ⇒ x* = 2/3
In general (without the baseline) the equation (V − C)/2 · x + V(1 − x) = (V/2)(1 − x) gives x* = V/C; here 4/6 = 2/3. This value is the same as the game's symmetric mixed Nash equilibrium: in a mixed equilibrium a player must be indifferent between its two strategies, and this is exactly the condition fH = fD.
The rest point is stable. When x < 2/3, 7 − 5x > 5 − 2x, that is, hawks earn above the average and increase. When x > 2/3 the inequality reverses and hawks decrease. From both directions the population is pushed to 2/3.
Let us verify that the mixture x* = 2/3 satisfies the ESS condition, using the payoffs without the baseline.
- First condition: against x* a hawk earns ⅔ · (−1) + ⅓ · 4 = 2/3 and a dove earns ⅔ · 0 + ⅓ · 2 = 2/3. In a mixed equilibrium every mutant gets the same payoff against x*: u(y, x*) = u(x*, x*) = 2/3. There is equality; the second condition is examined.
- Hawk mutant: u(x*, H) = ⅔ · (−1) + ⅓ · 0 = −2/3, u(H, H) = −1. −2/3 > −1: satisfied.
- Dove mutant: u(x*, D) = ⅔ · 4 + ⅓ · 2 = 10/3, u(D, D) = 2. 10/3 > 2: satisfied.
The condition holds against both mutants; x* = 2/3 is an ESS.
Figure 13.16 shows that in this game every interior starting point goes to the ESS. Not every game is so well behaved. In Rock-Paper-Scissors the replicator dynamics circles around the equilibrium: when rocks multiply, papers gain the advantage; when papers multiply, scissors do; when scissors multiply, rocks do; the population never settles. In the Stag Hunt, the dynamics go to one of the two pure equilibria depending on the start: if cooperators (stag hunters) are sufficiently numerous at the start, the stag equilibrium results; if they are few, the hare equilibrium does.
- Forgetting to multiply the share by fitness and divide: x · fH alone is not the new share; without division by f̄ the shares do not sum to 1.
- Mistaking f̄ for the simple average of the two fitnesses: f̄ = x · fH + (1 − x) · fD is a weighted average, not (fH + fD)/2.
- Saying "the hawk wins every pairing, so everyone becomes a hawk": a hawk wins against a dove, but as hawks multiply, hawk–hawk fights pull the average down. Fitness depends on the composition of the population.
13.7Repeated games
As a one-shot game, the Prisoner's Dilemma gives one of the bleakest results in game theory: both players defect and both end up worse off than under cooperation. In real life, however, we meet the same people, the same firms, the same neighbors again and again. This section examines how repetition makes cooperation possible, which strategies succeed, and how cooperation spreads in a learning population.
13.7.1The repeated Prisoner's Dilemma and the grim trigger
Here the Prisoner's Dilemma is written with points; a high score is good. C (staying silent) is cooperation and D is defection.
The four numbers in Figure 13.17 have names: the temptation 5 (defecting while the opponent cooperates), mutual cooperation 3, mutual defection 1, and the sucker's payoff 0 (cooperating while the opponent defects). The ordering is temptation 5 > mutual cooperation 3 > mutual defection 1 > sucker's payoff 0. Defection is the dominant strategy: if the opponent plays C, D gives 5 and C gives 3; if the opponent plays D, D gives 1 and C gives 0.
A finite and known number of repetitions does not change the outcome. If both players know that the game will last exactly 10 rounds, the last round is a one-shot game and both sides defect. In round 9 the players know what the last round will be; behavior in round 9 does not affect round 10, so round 9 is also like a one-shot game and they defect. This backward induction continues to the first round: defection in every round.
The situation changes when it is not known when the game will end. Let the game continue for one more round after each round with probability δ (and end with probability 1 − δ). δ is called the discount factor; it measures the present value of the next round. This situation is also called the shadow of the future: the more probable the future, the longer the shadow it casts over today's behavior. The expected length of the game is 1/(1 − δ) rounds; for example, for δ = 0.9, 10 rounds on average.
The grim trigger strategy (Grim): cooperate in the first round; if the opponent defects even once, defect forever from that moment on.
Let us compute whether a deviation by one player is profitable when both players play the grim trigger. The calculation uses a geometric series. In the sum S = a + aδ + aδ2 + … each term is δ times the previous one; therefore one can write S = a + δS and find S = a/(1 − δ) (for 0 ≤ δ < 1).
With payoffs temptation 5, mutual cooperation 3 and mutual defection 1, both players playing the grim trigger is an equilibrium if and only if δ ≥ 1/2. In general, if the temptation is c, the threshold is δ* = (c − 3)/(c − 1).
Complying: if both sides stick to the grim trigger, mutual cooperation is played every round and the player gets 3 per round. The expected total is 3 + 3δ + 3δ2 + … = 3/(1 − δ).
Deviating: if the player defects in this round it gets the temptation 5. Since the opponent plays the grim trigger, it defects in every later round; in those rounds the player's best response is also defection, and it gets 1 from mutual defection. The total is 5 + δ + δ2 + … = 5 + δ · 1/(1 − δ) = 5 + δ/(1 − δ). (Deviating in a later round starts the same calculation from that round; the result does not change.)
Comparison: the condition complying ≥ deviating is 3/(1 − δ) ≥ 5 + δ/(1 − δ). Multiplying both sides by the positive (1 − δ) does not reverse the inequality: 3 ≥ 5(1 − δ) + δ = 5 − 4δ. From this, 4δ ≥ 2, that is, δ ≥ 1/2 = (5 − 3)/(5 − 1). With temptation c the same steps give 3 ≥ c(1 − δ) + δ, that is, δ(c − 1) ≥ c − 3.
The punishment itself: after a deviation, both sides defecting forever is the repetition of (D, D), the Nash equilibrium of the one-shot game. In the punishment phase it is not profitable for any player to return to C alone (it would get 0 instead of 1); so the threat of punishment is credible. □
- δ = 0.9: complying 3/0.1 = 30; deviating 5 + 0.9/0.1 = 5 + 9 = 14. 30 > 14: cooperation survives.
- δ = 0.3: complying 3/0.7 ≈ 4.29; deviating 5 + 0.3/0.7 ≈ 5 + 0.43 = 5.43. Deviating is better: defection.
- At the threshold, δ = 0.5: complying 3/0.5 = 6; deviating 5 + 0.5/0.5 = 6. The two options are equal.
This result is a special case of a much more general fact. The folk theorem says: if δ is large enough, many average payoffs that give every player more than it can guarantee by defecting (here, more than 1) can be sustained in an equilibrium of the repeated game. The name comes from the fact that nobody knows who first proved the result and that the result circulated among experts like "folk knowledge." The theorem has a good and a bad face. The good face: cooperation is possible. The bad face: there are very many equilibria and the theory does not say which one will be played.
13.7.2For which δ does cooperation survive?
How the threshold depends on the temptation can be seen by changing the temptation. Complying is worth 3/(1 − δ) and deviating temptation + δ/(1 − δ); complying ≥ deviating if and only if δ ≥ δ* = (temptation − 3)/(temptation − 1).
In the chart of Figure 13.18 the two curves start at δ = 0 from 3 and from the temptation value. The deviation curve starts higher but rises more slowly, because a deviating player gets 1 instead of 3 in every future round. The more valuable the future is (the larger δ), the more deterrent the grim trigger threat is. As the temptation grows, the threshold needed for cooperation also rises: with temptation 4, δ* = 1/3; with temptation 9, δ* = 6/8 = 0.75. The larger the immediate gain from defection, the more probable the future must be to deter it.
13.7.3Ten-round matches
The grim trigger preserves cooperation but is very harsh: a single defection is punished forever. A milder and very famous strategy is Tit-for-Tat (TFT): it cooperates in the first round and afterward repeats the opponent's last move. For comparison, let us define five strategies:
- Always Cooperate (All-C) and Always Defect (All-D): always the same move, regardless of the opponent.
- Tit-for-Tat (TFT): starts with C, then copies the opponent's last move.
- Grim: starts with C; if the opponent defects once, it plays D forever.
- Suspicious TFT (STFT): starts with D, then copies the opponent's last move.
The scores of the matches in Figure 13.19 arise as follows:
- TFT – Always Cooperate: TFT answers cooperation with cooperation. Every round is (C, C): both get 10 · 3 = 30.
- TFT – Always Defect: In round 1 TFT plays C and the opponent D: TFT 0, opponent 5. In the next nine rounds TFT copies the opponent's D and (D, D) continues: 1 each per round. TFT gets 0 + 9 = 9, the opponent 5 + 9 = 14. TFT is exploited in the first round and defects afterward.
- TFT – Suspicious TFT: Suspicious TFT starts with defection. The two TFTs "echo" each other: TFT copies the opponent's D while the opponent copies TFT's C; C/D continues alternately. Each player gets 5 in five rounds and 0 in five rounds: both 25.
- Grim – Suspicious TFT: In round 1 Grim plays C and STFT plays D: 0 – 5. In round 2 Grim does not forgive and plays D, while STFT copies Grim's C: 5 – 0. In the next eight rounds both play D: 8 each. Total 13 – 13.
- Always Defect – Always Cooperate: The pure cooperator is completely exploited: 10 · 5 = 50 to 0.
A remarkable property follows from these matches: TFT can never win a match. TFT never defects first and answers each of the opponent's defections with at most one defection; so in a match it cannot collect more points than its opponent. At best it ties. Yet it wins the tournament (13.7.5).
13.7.4Code trace: match()
The code that plays the matches is short. The PAY dictionary maps the combination of two moves (for example "CD") to the two players' scores. The strategies are small functions that take their own history and the opponent's history.
PAY = {"CC": (3, 3), "CD": (0, 5),
"DC": (5, 0), "DD": (1, 1)}
tft = lambda me, opp: opp[-1] if opp else "C"
stft = lambda me, opp: opp[-1] if opp else "D"
def match(s1, s2, T):
h1, h2, p1, p2 = [], [], 0, 0
for t in range(T):
a, b = s1(h1, h2), s2(h2, h1)
u, v = PAY[a + b]
h1.append(a); h2.append(b)
p1, p2 = p1 + u, p2 + v
return p1, p2tft: if the opponent's history is not empty it returns the opponent's last move (opp[-1]), and"C"if it is empty.stftis the same rule but returns"D"on an empty history.match: in each round the two strategies are called from their own viewpoints. The first player is called withs1(h1, h2)and the second withs2(h2, h1); thus each strategy receives its own history first and then the opponent's.PAY[a + b]joins the two move letters and finds the score pair. The moves are appended to the histories and the scores are summed.
| t | TFT | STFT | Reason | PAY | Scores |
|---|---|---|---|---|---|
| 0 | C | D | empty history: TFT opens with C, STFT with D | CD = (0, 5) | 0 – 5 |
| 1 | D | C | both copy the opponent's last move | DC = (5, 0) | 5 – 5 |
| 2 | C | D | copying | CD = (0, 5) | 5 – 10 |
| 3 | D | C | copying | DC = (5, 0) | 10 – 10 |
| 4 | C | D | copying | CD = (0, 5) | 10 – 15 |
| 5 | D | C | copying | DC = (5, 0) | 15 – 15 |
match(tft, stft, 6): TFT C D C D C D, Suspicious TFT D C D C D C; scores 15 – 15.The function returns (15, 15). Figure 13.20 shows an echo cycle: a single initial defection starts a "CD / DC" alternation that goes on forever between two copying strategies. The average score per round is (0 + 5)/2 = 2.5; under mutual cooperation it would be 3. The only thing that could break the cycle is one of the two strategies "forgiving" once; TFT and STFT do not do this.
13.7.5A mini Axelrod tournament
Let the five strategies play a ten-round match against everyone, including their own twin. Table 13.16 gives the score that the strategy in each row collects in ten rounds against the opponent in each column.
| Strategy \ opponent | All-C | All-D | TFT | Grim | STFT | Total | Rank |
|---|---|---|---|---|---|---|---|
| Always Cooperate | 30 | 0 | 30 | 30 | 27 | 117 | 2 |
| Always Defect | 50 | 10 | 14 | 14 | 10 | 98 | 4 |
| Tit-for-Tat | 30 | 9 | 30 | 30 | 25 | 124 | 1 |
| Grim Trigger | 30 | 9 | 30 | 30 | 13 | 112 | 3 |
| Suspicious TFT | 32 | 10 | 25 | 13 | 10 | 90 | 5 |
Let us compute two cells of the table in detail.
- Always Cooperate – Suspicious TFT = 27: in round 1 All-C plays C and STFT plays D: All-C gets 0. From round 2 on, STFT copies All-C's C and nine rounds of (C, C) are played: 9 · 3 = 27. The total is 0 + 27 = 27. In the same match STFT gets 5 + 27 = 32; this is the first cell of the STFT row.
- Always Defect – TFT = 14: in round 1 All-D gets 5; then nine rounds of (D, D): 9. The total is 14. The same holds against Grim.
- Totals: TFT 30 + 9 + 30 + 30 + 25 = 124; Always Defect 50 + 10 + 14 + 14 + 10 = 98.
Ranking: Tit-for-Tat (124), Always Cooperate (117), Grim (112), Always Defect (98), Suspicious TFT (90). TFT comes first without winning a single match. Always Defect, in contrast, wins or ties every match but comes second to last. The explanation lies in where the points come from. Always Defect wins individual matches but collects few points in the matches it wins: against cooperators it exploits once, then falls into mutual defection and gets 1 per round. TFT, on the other hand, establishes long mutual cooperation with cooperators and collects 3 per round. The tournament rewards not beating the opponent but the total score.
The tournament table can also be turned into an evolutionary story. Let each strategy initially make up one fifth of the population, and let each strategy's fitness be its average score against an opponent drawn at random from the population: TFT 124/5 = 24.8, All-C 23.4, Grim 22.4, All-D 19.6, STFT 18.0. The population average is f̄ = 541/25 = 21.64. With the replicator rule, one generation later the shares are TFT 0.2 · 24.8/21.64 ≈ 0.229, All-C ≈ 0.216, Grim ≈ 0.207, All-D ≈ 0.181, STFT ≈ 0.166. The three "nice" strategies that earn above the average spread; those that start with defection decline.
13.7.6Axelrod's tournaments and their lessons
The mini tournament is a small copy of a real experiment. The political scientist Robert Axelrod organized two computer tournaments in 1980. Game theorists, mathematicians and computer programmers submitted programs for the repeated Prisoner's Dilemma: 14 programs entered the first tournament and 62 the second. Anatol Rapoport's four-line Tit-for-Tat program won both. The participants in the second tournament knew the results of the first and tried to beat TFT; they still failed (Axelrod, 1984).
Axelrod listed four properties common to successful strategies:
- Nice: it never defects first. In the mini tournament the three nice strategies (TFT, All-C, Grim) took the first three places.
- Retaliatory: it does not let defection go unpunished. Because Always Cooperate does not retaliate, it got 0 against Always Defect.
- Forgiving: if the opponent returns to cooperation, it returns too. Because Grim does not forgive, it got only 13 against Suspicious TFT; TFT got 25.
- Clear: the opponent can easily figure out its rule. TFT's rule is understood in a few rounds; the opponent quickly learns that cooperation is best against it.
TFT's weak point is noise, that is, the probability that a player mistakenly makes a move it did not intend. In a noisy environment two TFTs enter an endless cycle of retaliation after a single mistake.
In the match of Figure 13.21 the first three rounds are (C, C): 9 points each. In round 4 A mistakenly plays D: A gets 5, B gets 0. In round 5 B copies A's D, while A copies B's C: A gets 0, B gets 5. From then on the two players defect against each other in turn. In the seven rounds from 4 to 10, A gets 5 four times (4, 6, 8, 10) and B three times (5, 7, 9). The totals are 9 + 20 = 29 and 9 + 15 = 24; the two players' combined total falls from 60 to 53. Even A, who made the mistake, loses out: in the echo cycle it gets 2.5 per round on average, which is less than the 3 of mutual cooperation. As a remedy, generous Tit-for-Tat is proposed: it sometimes (with a certain probability) forgives the opponent's defection and breaks the echo cycle; in a noisy environment it does better than TFT. Win-Stay Lose-Shift (WSLS) also returns to cooperation within two rounds after a single mistake.
One last lesson: success depends on the environment. No strategy is best in every pool of opponents. If the pool of opponents changes, the ranking changes. For example, if the pool consisted only of Always Defect players, the best strategy would be Always Defect; TFT would be exploited in the first round of every match. This is why Axelrod also organized evolutionary tournaments: in each generation the strategies multiply in proportion to their success in the previous tournament (replicator dynamics). In these tournaments aggressive strategies multiply first, while there are naive cooperators to exploit; once their victims decline they decline too, and nice, retaliatory strategies such as TFT settle into the population.
- Saying "TFT wins matches": TFT cannot win any match; at best it ties. It wins the tournament with a high total score.
- Forgetting the match against one's own twin: in the mini tournament every strategy also plays its own twin; the 10 points of Always Defect and the 10 points of STFT come from these matches.
- Expecting cooperation under finite, known repetition: the 10 rounds in the tournament are a limit the strategies "do not know"; the programs do not change behavior toward the end. If the number of rounds were known to the players, backward induction would recommend defection in every round.
13.8Discussion: learning, humans, and ethics
The results of the chapter can be gathered around three discussion questions.
Does learning always lead to the optimum? No. Many counterexamples were seen throughout the chapter. Best-response dynamics cycle in Matching Pennies; fictitious play does not converge in Shapley's 3×3 example; the last iterate of two Hedge players keeps oscillating. The environment and the opponents change too: a learning opponent moves the target. A wrong model also leads to bad convergence: a bandit algorithm that only exploits gets stuck on the wrong arm. For this reason the reliable goal in learning theory is often not "reaching equilibrium" but no-regret: the guarantee that, whatever the opponent does, looking back, no fixed strategy would have done much better.
Do humans learn like algorithms? Partly. The similarities are clear: humans also learn by trial and error and change their behavior according to past experience. There are differences too: humans act with risk perception, emotions and social norms, while algorithms follow a defined reward. The finding in the bandit experiment (Daw et al., 2006) showed that humans' exploration behavior resembles softmax choice more than an algorithm such as UCB.
What are the ethical risks in adaptive systems? Learning systems learn the data as it is. Bias in the data is carried into the system's decisions (data bias). A recommender system that learns to maximize click counts may promote content that manipulates the user (clickbait). Learning from user behavior raises privacy problems. A subtler risk is algorithmic price coordination: learning bots that set prices in the same market may reach a "tacit agreement" at high prices without any explicit agreement. This is a form of cooperation in the repeated Prisoner's Dilemma that works against consumers: bots that learn punishment strategies similar to the grim trigger keep the price high by punishing a competitor's discount with a price war.
13.9Summary
- In best-response dynamics the players take turns best-responding to the opponent's last action. If the dynamics stop, they stop at a pure Nash equilibrium; which equilibrium is reached depends on the starting point. In finite potential games the dynamics must stop, since every profitable deviation increases the common potential. In games with no pure equilibrium, such as Matching Pennies, they cycle.
- In fictitious play the player best-responds to the frequencies of the opponent's entire history. In Matching Pennies the actions go around in ever longer cycles while the frequencies approach (½, ½) (0.472 and 0.492 at 400 rounds). Convergence is guaranteed in zero-sum (Robinson), 2×2 (Miyasawa) and potential games; it fails in Shapley's 3×3 example.
- External regret is the total difference between the best fixed action in hindsight and the algorithm: RT = maxi Σ gt(i) − Σ gt(at). If RT/T → 0 the algorithm is no-regret. Deterministic rules such as follow the leader are exploited (regret ≈ T/2).
- Hedge updates the weights by wi ← wi · eη·gt(i) and plays with probability proportional to the weights. RT ≤ (ln n)/η + ηT; with η = √(ln n / T), RT ≤ 2√(T ln n).
- Against a fixed opponent Hedge goes to the best response; against a learning opponent the last iterate cycles but the time average approaches equilibrium. If everyone plays no-regret, the empirical distribution of the profiles played approaches the set of coarse correlated equilibria (CCE); if internal regret is minimized, it approaches the set of correlated equilibria (CE); in zero-sum games the average strategies approach the minimax.
- In the multi-armed bandit only the reward of the pulled arm is seen and the exploration–exploitation dilemma arises. ε-greedy explores randomly with probability ε; with a fixed ε its regret grows linearly. UCB1 chooses the arm with the largest score Q + √(2 ln t / N); it directs exploration toward little-tried arms and its regret grows logarithmically (84 against 118 at 5000 rounds).
- Q-learning updates state–action values with Q(s, a) ← Q(s, a) + α[r + γ · max Q(s′, ·) − Q(s, a)]; reward propagates backward from the goal. In multi-agent settings the environment is non-stationary, so single-agent guarantees no longer hold.
- In replicator dynamics a strategy that earns above the average spreads: xi′ = xi fi / f̄. In Hawk–Dove every interior starting point goes to the ESS x* = V/C; this is the symmetric mixed Nash equilibrium.
- In the repeated Prisoner's Dilemma the grim trigger preserves cooperation when δ ≥ (temptation − 3)/(temptation − 1) (δ ≥ 1/2 with payoffs 5, 3, 1, 0). In the mini Axelrod tournament Tit-for-Tat comes first without winning a single match; successful strategies are nice, retaliatory, forgiving and clear. Under noise, generous TFT and WSLS do better.
| Method | Description | Result |
|---|---|---|
| Best-response dynamics | Best response to the last action | Equilibrium in potential games; otherwise cycles |
| Fictitious play | Best response to past frequencies | Frequencies converge to equilibrium in zero-sum games |
| Hedge | w ← w · eηg | RT = O(√(T ln n)); time average → CCE |
| ε-greedy / UCB | Exploration–exploitation balance | UCB: logarithmic regret |
| Q-learning | Q ← Q + α(r + γ · max Q′ − Q) | Reward propagates backward from the goal |
| Replicator | Successful strategies spread | Hawk–Dove: x* = V/C |
| Repeated PD | The shadow of the future | Cooperation if δ ≥ 1/2; TFT is strong |
13.10Key terms
- best-response dynamics
- potential game
- fictitious play
- external regret
- internal / swap regret
- follow the leader
- multiplicative weights
- learning rate
- correlated equilibrium
- coarse correlated equilibrium
- multi-armed bandit
- exploration–exploitation
- ε-greedy
- upper confidence bound
- Thompson sampling
- adversarial bandit
- reinforcement learning
- Q-learning
- discount factor
- non-stationary
- counterfactual regret minimization
- replicator dynamics
- fitness
- evolutionarily stable strategy
- grim trigger strategy
- folk theorem
- Tit-for-Tat
- suspicious / generous Tit-for-Tat
- win-stay lose-shift
13.11Test Yourself
In the cells (u1, u2): (Top, Left) = (2, 1), (Top, Right) = (0, 0), (Bottom, Left) = (0, 0), (Bottom, Right) = (1, 2). Where do best-response dynamics, in which the row player moves first and then the column player, stop if they start at (Top, Right)? If they start at (Bottom, Left)? Is this game a potential game?
Answer
From (Top, Right): against Right the row player sees Top 0, Bottom 1 and switches to Bottom: (Bottom, Right). Against Bottom the column player sees Left 0, Right 2; it stays at Right. The dynamics stop at (Bottom, Right). From (Bottom, Left): against Left the row player sees Top 2, Bottom 0 and switches to Top: (Top, Left). Against Top the column player sees Left 1, Right 0; it stays. The dynamics stop at (Top, Left). The equilibrium reached depends on the start. The game is a potential game: if we choose Φ(Top, Left) = 2, Φ(Top, Right) = 1, Φ(Bottom, Left) = 0, Φ(Bottom, Right) = 2, then in every unilateral change the payoff difference of the player who changes equals the difference in Φ. For example, in the Right column, when the row player moves from Top to Bottom its payoff rises from 0 to 1 and Φ rises from 1 to 2; in the Top row, when the column player moves from Right to Left its payoff rises from 0 to 1 and Φ rises from 1 to 2.
In Hedge with two actions, η = ln 3 and the initial weights are 1. The payoffs of the three rounds are (1, 0), (0, 1), (1, 0). What are the probabilities in each round, the algorithm's total expected payoff, and the external regret?
Answer
eln 3 = 3: the weight of an action with payoff 1 triples. Round 1: w = (1, 1), p = (½, ½), expected payoff 0.5; update w = (3, 1). Round 2: p = (3/4, 1/4), payoff ¼ · 1 = 0.25; w = (3, 3). Round 3: p = (½, ½), payoff 0.5; final weights (9, 3). Total 0.5 + 0.25 + 0.5 = 1.25. Fixed actions: A = 2, B = 1. Regret 2 − 1.25 = 0.75. In round 2 A was trusted too much and B turned out to win.
In a problem with four actions (n = 4), Hedge will be played for 400 rounds. What are the η that minimizes the bound, the regret bound, and the per-round regret bound? How do these numbers change if the number of rounds is multiplied by four (1600 rounds)?
Answer
ln 4 ≈ 1.386. η = √(1.386/400) ≈ 0.059. The bound is 2√(400 · 1.386) = 2√554.5 ≈ 47.1; per round 47.1/400 ≈ 0.118. At 1600 rounds η is halved (≈ 0.029), the total bound is multiplied by √4 = 2 (≈ 94.2), and the per-round bound is halved (≈ 0.059).
In a two-armed bandit the true means are μ = (0.6, 0.4). In the first five rounds arm 0 has been pulled four times (Q = 0.8) and arm 1 once (Q = 0.5). (a) Which arm does UCB1 choose at t = 6? (b) If after the choice the pull counts are N = (4, 2), what is the regret over six rounds?
Answer
(a) 2 ln 6 ≈ 3.58. Arm 0: 0.8 + √(3.58/4) = 0.8 + 0.95 ≈ 1.75. Arm 1: 0.5 + √3.58 = 0.5 + 1.89 ≈ 2.39. UCB1 chooses arm 1: its estimate is lower but its uncertainty is large. (b) R = 6 · 0.6 − (4 · 0.6 + 2 · 0.4) = 3.6 − 3.2 = 0.4. Regret is computed with the true means; the observed Q values are not used.
In Q-learning, Q(s, a) = 0.5, r = 2, γ = 0.5, max Q(s′, ·) = 3, α = 0.2. What are the target and the new Q(s, a)? What would the result be if s′ were a goal state (the episode ended)?
Answer
The target is 2 + 0.5 · 3 = 3.5. The new value is 0.5 + 0.2 · (3.5 − 0.5) = 0.5 + 0.6 = 1.1. If s′ were a goal, the future value would be taken as 0: the target is 2 and the new value 0.5 + 0.2 · 1.5 = 0.8.
In Hawk–Dove, V = 2, C = 8, and the baseline is 3. What are the fitnesses when the hawk share is x? What is the ESS? What is the hawk share one generation after x = 0.5?
Answer
Payoffs: HH (2 − 8)/2 = −3, HD 2, DH 0, DD 1. fH = 3 − 3x + 2(1 − x) = 5 − 5x, fD = 3 + 1 · (1 − x) = 4 − x. The rest point is 5 − 5x = 4 − x ⇒ x* = 1/4 = V/C. At x = 0.5, fH = 2.5, fD = 3.5, f̄ = 3; x′ = 0.5 · 2.5/3 ≈ 0.417. Since hawks earn below the average they decrease, falling toward 0.25. When fighting is costly, the hawk share is small.
In a repeated Prisoner's Dilemma the payoffs are temptation 7, mutual cooperation 4, mutual defection 2, sucker's payoff 0. What is the smallest δ for which cooperation with the grim trigger survives?
Answer
Complying 4/(1 − δ), deviating 7 + 2δ/(1 − δ). Multiplying by (1 − δ) gives 4 ≥ 7(1 − δ) + 2δ = 7 − 5δ, that is, 5δ ≥ 3 and δ ≥ 3/5. The general rule: δ* = (temptation − cooperation)/(temptation − defection) = (7 − 4)/(7 − 2). Because the payoff of mutual defection is higher, the punishment is milder; the threshold adjusts accordingly.
Win-Stay Lose-Shift (WSLS; it plays C in the first round, repeats the same move if it got 3 or 5, and changes its move if it got 0 or 1) plays against Always Defect for six rounds. What are the sequence of moves and the scores? What would TFT get in the same match?
Answer
Round 1: WSLS C, opponent D: 0 – 5; since WSLS got 0 it changes. Round 2: D – D: 1 – 1; since it got 1 it changes again. The sequence is C D C D C D: WSLS gets 0 + 1 + 0 + 1 + 0 + 1 = 3, Always Defect gets 5 + 1 + 5 + 1 + 5 + 1 = 18. After the first round TFT would defect every round: 0 + 5 · 1 = 5 against 5 + 5 = 10. WSLS is more robust to noise than TFT, but against an unconditional defector it is exploited every other round.
13.12Further reading
- T. Roughgarden, Twenty Lectures on Algorithmic Game Theory (2016), Lectures 16–18: no-regret learning, the proof of Hedge's regret bound, correlated equilibria, and the learning-based proof of the minimax theorem, presented from a computer science viewpoint.
- T. Lattimore and C. Szepesvári, Bandit Algorithms (2020): a comprehensive source giving detailed analyses of ε-greedy, UCB, Thompson sampling and EXP3.
- R. Axelrod, The Evolution of Cooperation (1984): tells the story of the computer tournaments, the success of Tit-for-Tat and the evolutionary tournaments without requiring mathematical background.
- D. Easley and J. Kleinberg, Networks, Crowds, and Markets (2010), Chapter 7: presents evolutionary game theory, the ESS and Hawk–Dove-like examples at an introductory level.
13.13References
- P. Auer, N. Cesa-Bianchi, P. Fischer, “Finite-time analysis of the multiarmed bandit problem”, Machine Learning 47, 2002.
- P. Auer, N. Cesa-Bianchi, Y. Freund, R. E. Schapire, “The nonstochastic multiarmed bandit problem”, SIAM Journal on Computing 32(1), 2002.
- R. Axelrod, The Evolution of Cooperation, Basic Books, 1984.
- A. Blum, Y. Mansour, “From external to internal regret”, JMLR 8, 2007.
- N. Cesa-Bianchi, G. Lugosi, Prediction, Learning, and Games, Cambridge, 2006.
- N. D. Daw, J. P. O’Doherty, P. Dayan, B. Seymour, R. J. Dolan, “Cortical substrates for exploratory decisions in humans”, Nature 441, 2006.
- D. Easley, J. Kleinberg, Networks, Crowds, and Markets, Cambridge, 2010 (Chapter 7: evolutionary game theory).
- D. Foster, R. Vohra, “Calibrated learning and correlated equilibrium”, Games and Economic Behavior 21, 1997.
- D. Fudenberg, D. Levine, The Theory of Learning in Games, MIT Press, 1998.
- S. Hart, A. Mas-Colell, “A simple adaptive procedure leading to correlated equilibrium”, Econometrica 68(5), 2000.
- J. Hofbauer, K. Sigmund, Evolutionary Games and Population Dynamics, Cambridge, 1998.
- A. R. Karlin, Y. Peres, Game Theory, Alive, AMS, 2017 (Chapter 7: evolutionary equilibrium; Chapter 18: adaptive decision making).
- T. Lattimore, C. Szepesvári, Bandit Algorithms, Cambridge, 2020.
- J. Maynard Smith, G. R. Price, “The logic of animal conflict”, Nature 246, 1973.
- K. Miyasawa, “On the convergence of the learning process in a 2×2 non-zero-sum two-person game”, Princeton Research Memo 33, 1961.
- V. Mnih et al., “Human-level control through deep reinforcement learning”, Nature 518, 2015.
- D. Monderer, L. S. Shapley, “Potential games”, Games and Economic Behavior 14(1), 1996.
- N. Nisan, T. Roughgarden, É. Tardos, V. Vazirani (eds.), Algorithmic Game Theory, Cambridge, 2007 (Chapter 4: learning, regret, and equilibria).
- M. Nowak, K. Sigmund, “A strategy of win-stay, lose-shift that outperforms tit-for-tat in the Prisoner’s Dilemma game”, Nature 364, 1993.
- J. Robinson, “An iterative method of solving a game”, Annals of Mathematics 54(2), 1951.
- T. Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge, 2016 (Lectures 16–18).
- L. S. Shapley, “Some topics in two-person games”, Advances in Game Theory, 1964.
- W. R. Thompson, “On the likelihood that one unknown probability exceeds another in view of the evidence of two samples”, Biometrika 25, 1933.
- C. Watkins, Learning from Delayed Rewards, PhD thesis, University of Cambridge, 1989.
- C. Watkins, P. Dayan, “Q-learning”, Machine Learning 8, 1992.
- M. Zinkevich, M. Johanson, M. Bowling, C. Piccione, “Regret minimization in games with incomplete information”, NeurIPS, 2007.
Related pages: Chapter 13 slides · Roughgarden CS364A course page · Tool: Nashpy (fictitious play, replicator dynamics) · © Sercan Külcü. All rights reserved.