Algorithmresearch
Optimistic hedge
Also called optimistic multiplicative weights, OMWU.
Multiplicative weights that count the last loss twice as a prediction of the next. In games it reaches regret polylog(T) for every player.
- Time
- O(k T) worst
- Space
- O(k) extra
- Where
- T = the number of rounds; k = the number of actions
- Model
- Real RAM
- Properties
- deterministicnot exactonlineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Vasilis Syrgkanis, Alekh Agarwal, Haipeng Luo, Robert E. Schapire, Constantinos Daskalakis, Maxwell Fishelson, Noah Golowich, 2015
Optimistic Hedge is a variant of multiplicative weights for the expert problem. Plain Hedge weights each action by , where is the total past loss. Optimistic Hedge adds the last loss once more, as a guess that the next loss will look like the last one. Against an arbitrary adversary it keeps the regret of Hedge. When the losses change slowly, its regret is much smaller, and in a game where every player uses it, the losses of each player change slowly because the others' strategies do. Daskalakis, Fishelson and Golowich (2021) proved that each of players then has regret , against for plain Hedge. By no-regret convergence to coarse correlated equilibria, the empirical distribution of play is then an coarse correlated equilibrium. The general framework is no-regret dynamics; for two-player zero-sum games see no-regret convergence in zero-sum games.
In plain words
A learner picks among several actions every day and then learns what each action would have cost. The usual method keeps a score for each action and favours the actions that have cost little so far. The optimistic method also bets that tomorrow will look like today: it counts today's cost twice when it sets tomorrow's chances. If the costs really change slowly, this bet pays off, and the learner reacts a step earlier. If the bet fails, the extra term only costs a bounded amount per round. In a game where every player learns this way, each player's choices change slowly, so the costs that the others see also change slowly, and the bet is almost always right.
The problem
There are actions and rounds. In round the learner chooses a distribution on the actions, an adversary who may know chooses a loss vector , and the learner pays . The regret is
The goal is small regret against every adversary, and much smaller regret when the loss vectors change slowly, as they do in a game in which all players learn.
The algorithm
OPTIMISTIC-HEDGE(k, eta, T) ▷ eta > 0 is the step size- 1
x ← the uniform distribution on the k actions - 2
m ← the zero vector ▷ the loss vector of the previous round - 3
for t ← 1 to T - 4
play x and observe the loss vector l - 5
for each action a - 6
x(a) ← x(a) · exp(-eta (2 l(a) - m(a))) - 7
divide each x(a) by the sum of all x(a) - 8
m ← l
After line L8 of round , the distribution is
because the factors of line L6 telescope: the sum of over is . Plain Hedge uses alone. So optimistic Hedge is Hedge run on the cumulative loss plus a prediction of the next loss. It is the entropy case of optimistic mirror descent and of optimistic follow the regularized leader, in the frame of online convex optimization. In code, the weights are better kept as logarithms, so that they do not underflow.
Example
Take actions, , and the losses , , , . The table shows the distribution of optimistic Hedge, the exponent that defines it, and the distribution of plain Hedge, rounded to four places.
| round | loss | exponent | optimistic | it pays | Hedge | it pays |
|---|---|---|---|---|---|---|
| 1 | (1, 0) | (0, 0) | (0.5, 0.5) | 0.5 | (0.5, 0.5) | 0.5 |
| 2 | (1, 0) | (-2, 0) | (0.1192, 0.8808) | 0.1192 | (0.2689, 0.7311) | 0.2689 |
| 3 | (0, 1) | (-3, 0) | (0.0474, 0.9526) | 0.9526 | (0.1192, 0.8808) | 0.8808 |
| 4 | (0, 1) | (-2, -2) | (0.5, 0.5) | 0.5 | (0.2689, 0.7311) | 0.7311 |
Each fixed action loses 2 in total. Optimistic Hedge loses 2.0718 and plain Hedge loses 2.3808. The optimistic learner moves away from action 1 faster in round 2, loses more in round 3 when the losses switch, and then returns to the middle in round 4, while Hedge is still behind.
Correctness
RVU bound. With , for every and every adversary,
Syrgkanis, Agarwal, Luo and Schapire (2015) called a bound of this form, regret bounded by variation in utilities, the RVU property. The proof compares with the iterate of plain Hedge and uses that the negative entropy is 1-strongly convex in the norm (Pinsker's inequality). Since , the regret is at most against any adversary, which is for .
Games. Let players each run optimistic Hedge with the same on their expected losses, scaled to . A change of one opponent's distribution by in the norm changes a player's loss vector by at most in the norm, so . Summing the RVU bounds over the players, the variation terms are cancelled by the movement terms, and
for every . In a two-player zero-sum game the sum of the two regrets is times the duality gap of the average strategies, so the averages are an equilibrium. The full proofs are in the proof file.
The bound on the sum does not bound each regret in a general game. Syrgkanis et al. (2015) showed that each regret is with a suitable step size, and Daskalakis, Fishelson and Golowich (2021, Theorem 3.1) showed that with , for a suitable constant , each player has regret . Their proof is long; it bounds the higher-order differences of the loss sequence and is not reproduced here.
Proof: Optimistic Hedge satisfies the RVU bound, and in self-play the sum of the regrets is at most n ln k / eta + n etafull
There are actions and loss vectors , and . Write and . Let be the simplex of distributions on the actions and the negative entropy, with . For a vector , let be the distribution with .
Claim 1 (closed form). The distribution played in round is .
Proof. By induction on . For , line L1 gives the uniform distribution, which is . Line L6 multiplies the weight of by (line L8 makes ), and line L7 rescales all weights by the same factor, which does not change . The exponent becomes .
Claim 2 (softmax is the regularized minimizer). For every vector , is the unique minimizer over of , and for every , .
Proof. Let , so with , and . Then for ,
and . So by Pinsker's inequality, and the difference is 0 only for .
Define the Hedge iterates , and the functions and . By Claims 1 and 2, minimizes and minimizes . Note and .
Claim 3 (one step). For every ,
Proof. By Claim 2 applied to with minimizer , and to with minimizer ,
Combine the two lines and rearrange; is the left side divided by .
Claim 4 (the RVU bound). For every and every action ,
and also the regret is at most .
Proof. Split . Sum Claim 3 over ; the right side telescopes to , where is the point mass on , , and . Since ,
By Hoelder, . With this gives the second bound at once. With instead, the regret is at most
For , , and summing over uses each term of the last sum at most once. So the last sum is at least , which gives the RVU bound.
Claim 5 (adversarial losses). Against every adversary, the regret is at most ; for it is at most .
Proof. The losses are in , so . Use the second bound of Claim 4.
Claim 6 (self-play). Let players of a finite game, each with at most strategies, run optimistic Hedge with the same , where player gets the loss vector , with the largest utility, the range of , and the product of the other players' distributions. Then for every , .
Proof. The losses are in . For a function with values in and two distributions , . Change the opponents' distributions one at a time from round to round : each change of a product in one coordinate changes by at most . So for , and by the Cauchy-Schwarz inequality its square is at most . For , . Sum Claim 4 over the players:
since each appears for players . For the bracket is at most 0.
Claim 7 (zero-sum games). In a two-player game with , the sum of the two regrets equals times the duality gap of the average distributions , where is the range of . So the averages form a equilibrium.
Proof. Write , with largest value and smallest value . Player 2 has . So , and , by linearity of in each distribution. Add the two lines, and use Claim 6 with . The duality gap is at least 0, because .
Conclusion. Lines L1 to L8 play (Claim 1), the RVU bound holds after every round (Claim 4), the regret is against any adversary (Claim 5), and in self-play with the sum of the regrets stays bounded by for all (Claim 6).
Complexity
Each round of lines L5 to L8 takes time, so rounds take , the same as plain Hedge. The memory is : the distribution and the last loss vector. In a game, computing the expected loss vectors usually dominates, at per round for a game in normal form. For an -coarse correlated equilibrium, the number of rounds drops from for plain Hedge to , where the tilde hides factors polylogarithmic in .
Properties
- Robust. Against an arbitrary adversary the regret is , the same order as Hedge.
- Adaptive to slow change. The regret depends on the total squared variation of the losses, not on . For a constant loss sequence it is at most .
- Uncoupled. Each player uses only its own loss vectors; it does not need the payoffs of the others.
- Last iterate. In two-player zero-sum games with a unique equilibrium, the distributions themselves converge to it for a small enough step size (Daskalakis and Panageas, 2019), while those of Hedge spiral away. In general games the last iterate need not converge.
Variants and improvements
- Optimistic mirror descent and follow the regularized leader. Any strongly convex regularizer gives an RVU bound; the entropy gives Hedge, and the Euclidean norm gives optimistic online gradient descent.
- Swap regret. Optimistic Hedge inside the copies of the Blum-Mansour reduction gives polylogarithmic swap regret in games, and so fast convergence to correlated equilibria (Anagnostides, Daskalakis, Farina, Fishelson, Golowich and Sandholm, 2022).
- Other predictions. Line L6 uses as the guess of . Any other predictable guess fits the same analysis, with in place of .
- Bandit feedback. With only the loss of the chosen action, as in the multi-armed bandit and Exp3, the variation of the losses cannot be observed directly, and these fast rates do not carry over in the same form.
When to use it
Use it in place of Hedge when all players of a game run the same kind of learner, for example to compute approximate coarse correlated equilibria, or zero-sum equilibria with an rate, by self-play. It costs nothing extra per round and keeps the worst-case guarantee. When the losses come from an adversary with no structure, it gives no gain over Hedge.
Pitfalls
- Factor 2 in line L6. Using gives plain Hedge, and using without the gives Hedge with step . The prediction must be added for the next round and removed in the round after, which is what does.
- Forgetting line L8. If stays zero, the exponents grow by , again plain Hedge with step .
- Step size too large in games. The cancellation in the sum of regrets needs in the form proved here. With a larger step, the variation terms of line L6 may not be absorbed, and the dynamics can oscillate.
- Underflow in lines L6 and L7. After many rounds the weights become tiny and can underflow to 0, after which line L6 can never raise them again. Keep the logarithms of the weights and normalize against the largest one.
Implementations
The Python code keeps the logarithms of the weights and implements lines L1 to L8 in floating point. The tests check the closed form , the RVU bound and the simpler bound after many prefixes against random, adaptive, alternating and slowly drifting adversaries, the bound on the sum of regrets in self-play in chicken, rock-paper-scissors and a random three-player game, the identity between the sum of regrets and the duality gap in random zero-sum games, and that in matching pennies the last iterate approaches the equilibrium while that of Hedge moves away.
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Shared helper of the algorithmic game theory pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Finite games in normal form, with exact payoffs and exact equilibrium checks.
A game is a pair (sizes, pay). sizes is a tuple (k_1, ..., k_n) of the numbers of pure
strategies of the n players; the pure strategies of player i are 0, ..., k_i - 1. pay is a
dict that maps each profile, a tuple s = (s_1, ..., s_n), to a tuple of n Fraction
utilities, which each player maximizes. A cost game passes the utilities u = -c.
A mixed profile sigma is a list of n lists; sigma[i][a] is the probability, a Fraction,
that player i plays a. A distribution on profiles (for correlated and coarse correlated
equilibria) is a dict from profiles to Fraction; missing profiles have probability 0.
All checks are exact: there is no tolerance anywhere. There is no LP and no equilibrium
algorithm in this module.
"""
from fractions import Fraction
from itertools import product
def profiles(sizes):
"""Return the list of all pure profiles, in lexicographic order."""
return list(product(*(range(k) for k in sizes)))
def from_bimatrix(A, B):
"""Return the game of the bimatrix (A, B): the row player gets A[r][c], the column player B[r][c]."""
m, n = len(A), len(A[0])
if len(B) != m or any(len(row) != n for row in A) or any(len(row) != n for row in B):
raise ValueError("A and B must be m by n matrices of the same shape")
pay = {(r, c): (Fraction(A[r][c]), Fraction(B[r][c])) for r in range(m) for c in range(n)}
return (m, n), pay
def random_game(rng, sizes, lo, hi):
"""Return a game with integer utilities drawn uniformly from lo to hi (inclusive), as Fraction."""
sizes = tuple(sizes)
pay = {s: tuple(Fraction(rng.randint(lo, hi)) for _ in sizes) for s in profiles(sizes)}
return sizes, pay
def _replace(s, i, a):
return s[:i] + (a,) + s[i + 1:]
def _weight(sigma, s, skip=None):
w = Fraction(1)
for k, a in enumerate(s):
if k != skip:
w *= sigma[k][a]
if w == 0:
return w
return w
def expected_utility(game, i, sigma):
"""Return u_i(sigma), the expected utility of player i when the players draw independently."""
sizes, pay = game
return sum((_weight(sigma, s) * pay[s][i] for s in profiles(sizes)), Fraction(0))
def deviation_payoffs(game, i, sigma):
"""Return the list of u_i(a, sigma_-i) for every pure strategy a of player i."""
sizes, pay = game
out = [Fraction(0)] * sizes[i]
for s in profiles(sizes):
w = _weight(sigma, s, skip=i)
if w:
out[s[i]] += w * pay[s][i]
return out
def pure_best_responses(game, i, sigma):
"""Return the sorted list of the pure strategies of player i that maximize u_i(a, sigma_-i)."""
d = deviation_payoffs(game, i, sigma)
best = max(d)
return [a for a, v in enumerate(d) if v == best]
def max_gain(game, sigma):
"""Return the largest gain of any player from a pure deviation: max_i (max_a u_i(a, sigma_-i) - u_i(sigma)).
The result is never negative, because u_i(sigma) is an average of the deviation payoffs.
"""
sizes, _ = game
gain = Fraction(0)
for i in range(len(sizes)):
d = deviation_payoffs(game, i, sigma)
u = sum((p * v for p, v in zip(sigma[i], d)), Fraction(0))
gain = max(gain, max(d) - u)
return gain
def is_distribution(p):
"""Return True if p (a sequence, or a dict of probabilities) is nonnegative and sums to exactly 1."""
vals = list(p.values()) if isinstance(p, dict) else list(p)
return all(v >= 0 for v in vals) and sum(vals, Fraction(0)) == 1
def _is_mixed_profile(game, sigma):
sizes, _ = game
return len(sigma) == len(sizes) and all(
len(sigma[i]) == k and is_distribution(sigma[i]) for i, k in enumerate(sizes))
def is_nash(game, sigma):
"""Return True if sigma is a mixed Nash equilibrium: no pure deviation gains for any player."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) == 0
def is_epsilon_nash(game, sigma, eps):
"""Return True if no player gains more than eps by a pure deviation (the additive form)."""
return _is_mixed_profile(game, sigma) and max_gain(game, sigma) <= eps
def _check_dist(game, dist):
sizes, _ = game
allowed = set(profiles(sizes))
return all(s in allowed for s in dist) and is_distribution(dist)
def is_correlated(game, dist):
"""Return True if dist is a correlated equilibrium.
For every player i and every pair a, b of its pure strategies, the sum over the profiles s
with s_i = a of dist(s) (u_i(s) - u_i(b, s_-i)) is at least 0.
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
for a in range(k):
rows = [(q, s) for s, q in dist.items() if s[i] == a and q]
for b in range(k):
if b != a and sum((q * (pay[s][i] - pay[_replace(s, i, b)][i]) for q, s in rows), Fraction(0)) < 0:
return False
return True
def is_coarse_correlated(game, dist):
"""Return True if dist is a coarse correlated equilibrium.
For every player i and every pure strategy b, E_{s ~ dist} u_i(s) >= E_{s ~ dist} u_i(b, s_-i).
"""
sizes, pay = game
if not _check_dist(game, dist):
return False
for i, k in enumerate(sizes):
here = sum((q * pay[s][i] for s, q in dist.items()), Fraction(0))
for b in range(k):
if sum((q * pay[_replace(s, i, b)][i] for s, q in dist.items()), Fraction(0)) > here:
return False
return True
def pure_nash_brute(game):
"""Return the list of all pure Nash equilibria, found by checking every profile."""
sizes, pay = game
out = []
for s in profiles(sizes):
if all(pay[s][i] >= pay[_replace(s, i, b)][i] for i in range(len(sizes)) for b in range(sizes[i])):
out.append(s)
return out
optimistic_hedge.py 103 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/optimistic-hedge/. The authors are listed in prov/259HJ8.jsonl.
"""Optimistic Hedge (optimistic multiplicative weights) on k actions with losses in [0, 1].
After it sees the loss vector l of a round, the learner multiplies the weight of action a by
exp(-eta (2 l(a) - m(a))), where m is the loss vector of the round before (0 before the
first round), and normalizes. This is Hedge on the cumulative losses plus one extra copy of
the last loss, used as a prediction of the next one. Arithmetic is in float.
"""
import math
class OptimisticHedge:
"""An online learner. Call distribution() to get the current x, then update(loss)."""
def __init__(self, k, eta):
if k < 1 or eta <= 0:
raise ValueError("need k >= 1 and eta > 0")
self.eta = eta
self.x = [1.0 / k] * k # @line L1
self.z = [0.0] * k
self.m = [0.0] * k # @line L2
def distribution(self):
return list(self.x)
def update(self, loss):
eta = self.eta
# The weights are kept as logarithms z(a), so that no weight underflows; x is the softmax of z.
for a in range(len(self.z)): # @line L5
self.z[a] -= eta * (2 * loss[a] - self.m[a]) # @line L6
top = max(self.z)
w = [math.exp(e - top) for e in self.z]
total = sum(w)
self.x = [v / total for v in w] # @line L7
self.m = list(loss) # @line L8
def play(k, T, eta, adversary):
"""Run optimistic Hedge for T rounds against adversary(t, x), which returns the loss vector
of round t and may look at the current distribution x. Return the distributions and losses."""
learner = OptimisticHedge(k, eta)
xs, losses = [], []
for t in range(T): # @line L3
x = learner.distribution()
loss = adversary(t, x) # @line L4
learner.update(loss)
xs.append(x)
losses.append(list(loss))
return xs, losses
def regret(xs, losses):
"""Return sum_t x_t . l_t minus the least total loss of a fixed action."""
if not xs:
return 0.0
k = len(xs[0])
mine = sum(sum(a * b for a, b in zip(x, l)) for x, l in zip(xs, losses))
return mine - min(sum(l[a] for l in losses) for a in range(k))
def rvu_bound(xs, losses, eta):
"""Return ln k / eta + eta sum_t |l_t - l_{t-1}|_inf^2 - (1 / (8 eta)) sum_{t >= 2} |x_t - x_{t-1}|_1^2,
with l_0 = 0: the RVU bound on the regret of optimistic Hedge."""
k = len(xs[0])
prev = [0.0] * k
var = 0.0
for l in losses:
var += max(abs(a - b) for a, b in zip(l, prev)) ** 2
prev = l
move = sum(sum(abs(a - b) for a, b in zip(x, y)) ** 2 for x, y in zip(xs[1:], xs))
return math.log(k) / eta + eta * var - move / (8 * eta)
def self_play(game, T, eta):
"""Let every player of a finite game (sizes, pay), as in the helper agtgame, run optimistic
Hedge on its expected losses (max u_i - u_i(a, x_-i)) / range_i. Return the list of the
profiles of distributions and the list of the loss vectors of each player."""
sizes, pay = game
n = len(sizes)
hi = [float(max(pay[s][i] for s in pay)) for i in range(n)]
span = [hi[i] - float(min(pay[s][i] for s in pay)) or 1.0 for i in range(n)]
learners = [OptimisticHedge(k, eta) for k in sizes]
payf = {s: [float(v) for v in u] for s, u in pay.items()}
hist_x, hist_l = [], []
for _ in range(T):
xs = [L.distribution() for L in learners]
losses = []
for i in range(n):
d = [0.0] * sizes[i]
for s, u in payf.items():
w = 1.0
for j, a in enumerate(s):
if j != i:
w *= xs[j][a]
d[s[i]] += w * u[i]
losses.append([(hi[i] - v) / span[i] for v in d])
for L, l in zip(learners, losses):
L.update(l)
hist_x.append(xs)
hist_l.append(losses)
return hist_x, hist_l
test_optimistic_hedge.py 128 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/optimistic-hedge/. The authors are listed in prov/259HJ8.jsonl.
"""Tests of optimistic Hedge: the closed form, the RVU bound at every round, the bound on the
sum of the regrets in self-play, the duality gap in zero-sum games, and the last iterate."""
import math
import random
import pytest
from agtgame import from_bimatrix, random_game
from optimistic_hedge import OptimisticHedge, play, regret, rvu_bound, self_play
CHICKEN = from_bimatrix([[0, 7], [2, 6]], [[0, 2], [7, 6]])
RPS = from_bimatrix([[0, -1, 1], [1, 0, -1], [-1, 1, 0]], [[0, 1, -1], [-1, 0, 1], [1, -1, 0]])
def softmax(v):
top = max(v)
w = [math.exp(a - top) for a in v]
s = sum(w)
return [a / s for a in w]
def test_closed_form_and_validation():
"""x_{t+1} is proportional to exp(-eta (L_t + l_t)), with L_t the cumulative loss."""
rng = random.Random(4)
k, eta = 4, 0.7
learner = OptimisticHedge(k, eta)
cum = [0.0] * k
assert learner.distribution() == [0.25] * 4
for _ in range(60):
loss = [rng.random() for _ in range(k)]
learner.update(loss)
cum = [c + v for c, v in zip(cum, loss)]
want = softmax([-eta * (c + v) for c, v in zip(cum, loss)])
assert all(abs(a - b) < 1e-12 for a, b in zip(learner.distribution(), want))
with pytest.raises(ValueError):
OptimisticHedge(0, 1.0)
with pytest.raises(ValueError):
OptimisticHedge(3, -1.0)
def test_no_underflow_on_long_runs():
xs, _ = play(3, 2000, 5.0, lambda t, x: [0.0, 1.0, 1.0])
assert abs(sum(xs[-1]) - 1) < 1e-12 and xs[-1][0] > 0.999999
def adversaries(rng, k):
yield "random", lambda t, x: [rng.random() for _ in range(k)]
yield "adaptive", lambda t, x: [1.0 if a == max(range(k), key=lambda b: x[b]) else 0.0 for a in range(k)]
yield "alternating", lambda t, x: [float((a + t) % 2) for a in range(k)]
yield "slow drift", lambda t, x: [0.5 + 0.5 * math.sin(t / 50 + a) for a in range(k)]
def test_rvu_bound_at_every_round():
rng = random.Random(99)
for k in (1, 2, 3, 5):
for eta in (0.05, 0.3, 1.0):
for _, adv in adversaries(rng, k):
xs, losses = play(k, 250, eta, adv)
for T in range(1, 251, 17):
r = regret(xs[:T], losses[:T])
assert r <= rvu_bound(xs[:T], losses[:T], eta) + 1e-9
var = sum(max(abs(a - b) for a, b in zip(l, p)) ** 2
for l, p in zip(losses[:T], [[0.0] * k] + losses[:T - 1]))
assert r <= math.log(k) / eta + eta / 2 * var + 1e-9
def test_slowly_changing_losses_give_small_regret():
"""When the losses change slowly, the regret stays far below the sqrt(T) of plain Hedge."""
xs, losses = play(2, 4000, 0.5, lambda t, x: [0.5 + 0.5 * math.sin(t / 300), 0.5 - 0.5 * math.sin(t / 300)])
assert regret(xs, losses) <= math.log(2) / 0.5 + 0.5 * (1 + 4000 * (1 / 300) ** 2) + 1e-9
assert regret(xs, losses) < 3
def test_sum_of_regrets_in_self_play():
"""With eta <= 1 / (sqrt 8 (n - 1)), the sum of the regrets is at most n ln k / eta + n eta for every T."""
three = random_game(random.Random(6), (2, 3, 2), -3, 3)
for game, T in ((CHICKEN, 600), (RPS, 600), (three, 200)):
sizes = game[0]
n, k = len(sizes), max(sizes)
eta = 1 / (math.sqrt(8) * (n - 1))
hist_x, hist_l = self_play(game, T, eta)
for t in range(1, T + 1, 13):
total = sum(regret([xs[i] for xs in hist_x[:t]], [ls[i] for ls in hist_l[:t]]) for i in range(n))
assert total <= n * math.log(k) / eta + n * eta + 1e-9
def test_zero_sum_duality_gap():
"""In a zero-sum game the sum of the two regrets is T times the duality gap of the averages."""
rng = random.Random(21)
for _ in range(3):
m = rng.randint(2, 4)
A = [[rng.randint(-3, 3) for _ in range(m + 1)] for _ in range(m)]
game = from_bimatrix(A, [[-v for v in row] for row in A])
T, eta = 400, 1 / math.sqrt(8)
hist_x, hist_l = self_play(game, T, eta)
xbar = [sum(xs[0][r] for xs in hist_x) / T for r in range(m)]
ybar = [sum(xs[1][c] for xs in hist_x) / T for c in range(m + 1)]
best_col = min(sum(xbar[r] * A[r][c] for r in range(m)) for c in range(m + 1))
best_row = max(sum(A[r][c] * ybar[c] for c in range(m + 1)) for r in range(m))
gap = best_row - best_col
span = max(max(row) for row in A) - min(min(row) for row in A) or 1
r1 = regret([xs[0] for xs in hist_x], [ls[0] for ls in hist_l])
r2 = regret([xs[1] for xs in hist_x], [ls[1] for ls in hist_l])
assert abs((r1 + r2) * span / T - gap) < 1e-9
assert 0 <= gap <= span * (2 * math.log(m + 1) / eta + 2 * eta) / T + 1e-9
def test_last_iterate_in_matching_pennies():
"""The last iterate of optimistic Hedge approaches the equilibrium; that of Hedge moves away.
The row player wants to match: its loss for an action is the chance that the column differs."""
row, col = OptimisticHedge(2, 0.1), OptimisticHedge(2, 0.1)
row.z = [0.3, 0.0]
row.x = softmax(row.z)
zr, zc = [0.3, 0.0], [0.0, 0.0]
for _ in range(3000):
x, y = row.distribution(), col.distribution()
row.update([y[1], y[0]])
col.update([x[0], x[1]])
hx, hy = softmax(zr), softmax(zc)
zr = [zr[0] - 0.1 * hy[1], zr[1] - 0.1 * hy[0]]
zc = [zc[0] - 0.1 * hx[0], zc[1] - 0.1 * hx[1]]
x, y = row.distribution(), col.distribution()
assert abs(x[0] - 0.5) + abs(y[0] - 0.5) < 0.01
hx, hy = softmax(zr), softmax(zc)
assert abs(hx[0] - 0.5) + abs(hy[0] - 0.5) > 0.5
History
Optimism in online learning goes back to Rakhlin and Sridharan (2013), who used the last loss as a prediction in mirror descent and showed fast convergence in zero-sum games; Daskalakis, Deckelbaum and Kim had earlier given uncoupled dynamics for zero-sum games that converge at a rate close to . Syrgkanis, Agarwal, Luo and Schapire (2015) defined the RVU property and extended the fast rates to general games. Daskalakis, Fishelson and Golowich (2021) brought the individual regret of optimistic Hedge down to polylogarithmic in .
References
- Fast convergence of regularized learning in games, the RVU property, its proof for optimistic follow the regularized leader and optimistic Hedge, the bound on the sum of regrets, and individual regret O(T^(1/4))
- Near-optimal no-regret learning in general games, Theorem 3.1 (with step size 1/(C m log^4 T), each of m players has regret O(m log n_i log^4 T))
- Optimization, learning, and games with predictable sequences, optimistic mirror descent with the last loss as the prediction, and its use in zero-sum games
- Tim Roughgarden, Twenty Lectures on Algorithmic Game Theory, Cambridge University Press, 2016, Lecture 17 (no-regret dynamics and multiplicative weights, the baseline that this method improves)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 259HJ8 Edit this page History Report an error Markdown