The Multiplicative Weights Update Method
Weighted majority is one instance of a general scheme that keeps reappearing across computer science, in learning (Hedge, boosting), game theory (fictitious play and no-regret dynamics), optimization (fast approximate LP and flow solvers) and complexity (hard-core lemmas). Arora, Hazan and Kale's survey (2012) called it the multiplicative weights update method (MWU) and gave one clean theorem that covers all of them. This lesson states and proves that theorem, derives the regret bound, compares MWU with the natural "follow the leader" rule that fails against an adversary, and implements the method in Python and C++.
The setting
There are decisions (experts, strategies, constraints). In each round :
- the algorithm chooses a probability distribution over the decisions;
- an adversary, who knows the algorithm but not its future coin flips, reveals a cost vector (negative costs are gains);
- the algorithm pays the expected cost .
The benchmark is the best fixed decision in hindsight, , and the regret is the difference between the two totals.
MULTIPLICATIVE-WEIGHTS(eta) -- 0 < eta <= 1/2
1 w_i = 1 for every decision i
2 for t = 1 .. T
3 p_i = w_i / (w_1 + ... + w_n) -- play the normalized weights
4 observe the cost vector m in [-1, 1]^n
5 w_i = w_i * (1 - eta * m_i) -- shrink costly decisions, grow profitable onesTheorem (Arora, Hazan and Kale, 2012). For every decision ,
Proof. Let , so . One round changes the potential to
using . So . For the lower bound, . For one has , so with (and ):
Comparing with and dividing by gives the theorem.
Corollary (regret bound). If all costs lie in , then , and the choice (assuming , so that ) gives
The average regret per round, , tends to 0: in the long run MWU does as well as the best fixed decision, against any sequence. The bound is optimal up to the constant: with random costs, every algorithm has expected regret (Cesa-Bianchi and Lugosi's book, 2006, gives the standard proof). The exponential variant is the Hedge algorithm of Freund and Schapire (1997), with the same guarantee up to constants.
Regret in practice
The program runs MWU on random costs for 20 decisions with the tuned and reports the regret against the bound for growing .
import math
import random
def mwu(costs, eta):
n = len(costs[0])
w = [1.0] * n
paid = 0.0
for m in costs:
W = sum(w)
paid += sum(wi / W * mi for wi, mi in zip(w, m))
w = [wi * (1 - eta * mi) for wi, mi in zip(w, m)]
return paid
rng = random.Random(2012)
n = 20
means = [0.3 + 0.02 * i for i in range(n)] # decision i has average cost 0.3 + 0.02 i
print(" T regret bound 2 sqrt(T ln n) regret / T")
for T in [100, 1000, 10000]:
costs = [[min(1.0, max(0.0, rng.gauss(mu, 0.2))) for mu in means] for _ in range(T)]
eta = math.sqrt(math.log(n) / T)
regret = mwu(costs, eta) - min(sum(c[i] for c in costs) for i in range(n))
print(f"{T:6} {regret:8.2f} {2 * math.sqrt(T * math.log(n)):21.2f} {regret / T:10.4f}") T regret bound 2 sqrt(T ln n) regret / T
100 10.95 34.62 0.1095
1000 46.07 109.47 0.0461
10000 171.37 346.16 0.0171
The regret grows with , but more slowly than , so the regret per round shrinks (roughly like ). On this data it stays between a third and a half of the worst-case bound: with tuned for the worst case, MWU spreads its weight more than necessary when one decision is clearly best.
Why not just follow the leader?
The obvious rule, follow the leader (FTL), plays the decision with the smallest total cost so far. It is excellent on stochastic data but has linear regret against an adversary. Two decisions with costs in round 1 and then alternately , make the leader switch every round to the decision that is about to cost 1, while each fixed decision pays only about .
import math
T = 1000
costs = [(0.5, 0.0)] + [((0.0, 1.0) if t % 2 == 1 else (1.0, 0.0)) for t in range(1, T)]
totals, ftl = [0.0, 0.0], 0.0
for m in costs:
leader = 0 if totals[0] <= totals[1] else 1
ftl += m[leader]
totals = [totals[0] + m[0], totals[1] + m[1]]
eta = math.sqrt(math.log(2) / T)
w, paid = [1.0, 1.0], 0.0
for m in costs:
paid += (w[0] * m[0] + w[1] * m[1]) / (w[0] + w[1])
w = [w[0] * (1 - eta * m[0]), w[1] * (1 - eta * m[1])]
best = min(totals)
print(f"best fixed decision: {best:.1f}")
print(f"follow the leader: {ftl:.1f} (regret {ftl - best:.1f})")
print(f"multiplicative weights: {paid:.1f} (regret {paid - best:.1f}, bound {2 * math.sqrt(T * math.log(2)):.1f})")best fixed decision: 499.5
follow the leader: 999.5 (regret 500.0)
multiplicative weights: 503.1 (regret 3.6, bound 52.7)
FTL pays almost every round, regret about . MWU's weights move slowly (by a factor per round), so it never commits to the decision the adversary is about to punish; its regret is a tiny fraction of the bound. Smoothing the leader's choice, by multiplicative weights or by adding random perturbations to the totals (Kalai and Vempala, 2005), is what makes no-regret learning possible.
In C++
MWU with cost vectors from a seeded generator, as a reusable step: the class keeps the weights, returns the distribution, and applies the update.
#include <cmath>
#include <cstdio>
#include <random>
#include <vector>
struct MWU {
std::vector<double> w;
double eta;
MWU(int n, double eta) : w(n, 1.0), eta(eta) {}
std::vector<double> distribution() const {
double W = 0;
for (double x : w) W += x;
std::vector<double> p(w.size());
for (size_t i = 0; i < w.size(); i++) p[i] = w[i] / W;
return p;
}
void update(const std::vector<double>& m) { for (size_t i = 0; i < w.size(); i++) w[i] *= 1 - eta * m[i]; }
};
int main() {
const int n = 20, T = 10000;
MWU alg(n, std::sqrt(std::log(n) / T));
std::mt19937 rng(2012);
std::vector<double> total(n, 0.0);
double paid = 0;
for (int t = 0; t < T; t++) {
std::vector<double> m(n);
for (int i = 0; i < n; i++) { // cost of decision i: 1 with probability 0.3 + 0.02 i
double u = (rng() >> 8) / 16777216.0;
m[i] = u < 0.3 + 0.02 * i ? 1.0 : 0.0;
total[i] += m[i];
}
auto p = alg.distribution();
for (int i = 0; i < n; i++) paid += p[i] * m[i];
alg.update(m);
}
double best = total[0];
for (double x : total) if (x < best) best = x;
std::printf("paid %.2f, best fixed decision %.0f, regret %.2f, bound %.2f\n", paid, best, paid - best,
2 * std::sqrt(T * std::log(n)));
}paid 3207.20, best fixed decision 3033, regret 174.20, bound 346.16
In practice
Two variants are worth knowing. Hedge uses instead of , which never makes a weight negative and has a slightly cleaner analysis. For long runs, weights underflow (a decision that is always bad has weight ); implementations keep logarithms of the weights, or renormalize every round, which changes nothing in the distribution. When only the cost of the chosen decision is revealed (the bandit setting), the same idea with importance-weighted cost estimates gives the EXP3 algorithm (Auer, Cesa-Bianchi, Freund and Schapire, 2002), with regret .
Test yourself
How does MWU update the weight of decision after seeing costs ?
- if
With costs in and , what is MWU's regret bound?
Why does follow-the-leader have linear regret on some sequences?
- It uses too many weights
- An adversary can make the current leader switch every round to the decision that is about to be costly
- Because it is randomized
- It does not; it has zero regret