TExcelTAD
Home › Linear Programming & Duality for Algorithms › The Multiplicative Weights Update Method

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 O(Tln⁡n)O(\sqrt{T \ln n}) 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 nn decisions (experts, strategies, constraints). In each round t=1,…,Tt = 1, \ldots, T:

  1. the algorithm chooses a probability distribution p(t)p^{(t)} over the decisions;
  2. an adversary, who knows the algorithm but not its future coin flips, reveals a cost vector m(t)∈[−1,1]nm^{(t)} \in [-1, 1]^n (negative costs are gains);
  3. the algorithm pays the expected cost m(t)⋅p(t)=∑ipi(t)mi(t)m^{(t)} \cdot p^{(t)} = \sum_i p_i^{(t)} m_i^{(t)}.

The benchmark is the best fixed decision in hindsight, min⁡i∑tmi(t)\min_i \sum_t m_i^{(t)}, and the regret is the difference between the two totals.

text
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 ones

Theorem (Arora, Hazan and Kale, 2012). For every decision ii,

∑t=1Tm(t)⋅p(t)  ≤  ∑t=1Tmi(t)  +  η∑t=1T∣mi(t)∣  +  ln⁡nη.\sum_{t=1}^{T} m^{(t)} \cdot p^{(t)} \;\le\; \sum_{t=1}^{T} m_i^{(t)} \;+\; \eta \sum_{t=1}^{T} \lvert m_i^{(t)} \rvert \;+\; \frac{\ln n}{\eta} .

Proof. Let Φt=∑iwi(t)\Phi_t = \sum_i w_i^{(t)}, so Φ1=n\Phi_1 = n. One round changes the potential to

Φt+1=∑iwi(t)(1−ηmi(t))=Φt(1−η m(t)⋅p(t))≤Φt e−η m(t)⋅p(t),\Phi_{t+1} = \sum_i w_i^{(t)} (1 - \eta m_i^{(t)}) = \Phi_t \big(1 - \eta\, m^{(t)} \cdot p^{(t)}\big) \le \Phi_t \, e^{-\eta\, m^{(t)} \cdot p^{(t)}},

using 1−x≤e−x1 - x \le e^{-x}. So ΦT+1≤n e−η∑tm(t)⋅p(t)\Phi_{T+1} \le n \, e^{-\eta \sum_t m^{(t)} \cdot p^{(t)}}. For the lower bound, ΦT+1≥wi(T+1)=∏t(1−ηmi(t))\Phi_{T+1} \ge w_i^{(T+1)} = \prod_t (1 - \eta m_i^{(t)}). For ∣x∣≤12\lvert x \rvert \le \frac{1}{2} one has ln⁡(1−x)≥−x−x2\ln(1 - x) \ge -x - x^2, so with x=ηmi(t)x = \eta m_i^{(t)} (and (mi(t))2≤∣mi(t)∣(m_i^{(t)})^2 \le \lvert m_i^{(t)} \rvert):

ln⁡ΦT+1≥−η∑tmi(t)−η2∑t∣mi(t)∣.\ln \Phi_{T+1} \ge -\eta \sum_t m_i^{(t)} - \eta^2 \sum_t \lvert m_i^{(t)} \rvert .

Comparing with ln⁡ΦT+1≤ln⁡n−η∑tm(t)⋅p(t)\ln \Phi_{T+1} \le \ln n - \eta \sum_t m^{(t)} \cdot p^{(t)} and dividing by η\eta gives the theorem. □\square

Corollary (regret bound). If all costs lie in [0,1][0, 1], then ∑t∣mi(t)∣≤T\sum_t \lvert m_i^{(t)} \rvert \le T, and the choice η=ln⁡n/T\eta = \sqrt{\ln n / T} (assuming T≥4ln⁡nT \ge 4 \ln n, so that η≤12\eta \le \frac{1}{2}) gives

regret=∑tm(t)⋅p(t)−min⁡i∑tmi(t)≤2Tln⁡n.\text{regret} = \sum_t m^{(t)} \cdot p^{(t)} - \min_i \sum_t m_i^{(t)} \le 2 \sqrt{T \ln n} .

The average regret per round, 2ln⁡n/T2\sqrt{\ln n / T}, 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 Ω(Tln⁡n)\Omega(\sqrt{T \ln n}) (Cesa-Bianchi and Lugosi's book, 2006, gives the standard proof). The exponential variant wi←wie−ηmiw_i \leftarrow w_i e^{-\eta m_i} 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 η\eta and reports the regret against the bound for growing TT.

python · try it yourself
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 TT, but more slowly than TT, so the regret per round shrinks (roughly like 1/T1/\sqrt{T}). On this data it stays between a third and a half of the worst-case bound: with η\eta 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 (12,0)(\frac{1}{2}, 0) in round 1 and then alternately (0,1)(0, 1), (1,0)(1, 0) make the leader switch every round to the decision that is about to cost 1, while each fixed decision pays only about T2\frac{T}{2}.

python · try it yourself
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 T2\frac{T}{2}. MWU's weights move slowly (by a factor 1−η1 - \eta 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.

cpp · try it yourself
#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 e−ηmie^{-\eta m_i} instead of 1−ηmi1 - \eta m_i, 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 (1−η)T(1 - \eta)^T); 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 O(Tnln⁡n)O(\sqrt{T n \ln n}).

Test yourself

How does MWU update the weight of decision ii after seeing costs m(t)m^{(t)}?

  1. wi←wi+ηmiw_i \leftarrow w_i + \eta m_i
  2. wi←wi(1−ηmi)w_i \leftarrow w_i (1 - \eta m_i)
  3. wi←0w_i \leftarrow 0 if mi>0m_i > 0
  4. wi←1/miw_i \leftarrow 1/m_i

With costs in [0,1][0, 1] and η=ln⁡n/T\eta = \sqrt{\ln n / T}, what is MWU's regret bound?

  1. O(T)O(T)
  2. 2Tln⁡n2\sqrt{T \ln n}
  3. ln⁡n\ln n
  4. O(nT)O(n \sqrt{T})

Why does follow-the-leader have linear regret on some sequences?

  1. It uses too many weights
  2. An adversary can make the current leader switch every round to the decision that is about to be costly
  3. Because it is randomized
  4. It does not; it has zero regret