Documentation

CslibFrontier.MachineLearning.OnlineLearning.RegretMatching

Internal regret, nonpositive-orthant projection, and Blackwell–Hart–Mas-Colell regret-matching #

This module formalizes internal regret, its quantitative relationship with external and swap regret ([BM07b] §§4.2, 4.4 and Exercise 4.1), the Euclidean metric projection onto the nonpositive orthant with Blackwell's quadratic potential bound ([Bla56]; [HMC00] §3, Figure 2, pp. 1135–1138 and Appendix Step M1, p. 1146), and the resulting horizon-free, parameter-free O(√T) external and internal/swap regret-matching algorithms ([HMC00] Theorem A, eqs. (3.1)–(3.5), pp. 1133–1138, and Theorem B, eqs. (4.2a)–(4.2b), p. 1139):

  1. External, internal, and swap regret functionals: for an action sequence p : ℕ → ι → ℝ and loss sequence ℓ : ℕ → ι → ℝ over T rounds, pairInternalRegret p ℓ T j k measures the cost saved by replacing action j with k (switchAction j k), swapRegretOf p ℓ T δ measures the cost saved by an arbitrary modification rule δ : ι → ι, and externalRegretOf p ℓ T k compares against the constant action k. Swap regret decomposes as ∑ j, pairInternalRegret p ℓ T j (δ j), bounding both internal regret (δ = switchAction j k) and external regret (δ = fun _ => k), while internal regret at most R bounds swap regret by |ι| * R ([BM07b] Exercise 4.1).
  2. Euclidean projection onto ℝ_{\le 0}^L and Blackwell's potential: reusing Cslib.metricProjection from CslibFrontier.Foundations.Analysis.InnerProductSpace.MetricProjection, the nearest point of nonposOrthant L = {z : EuclideanSpace ℝ L | ∀ l, z l ≤ 0} to y is l ↦ min 0 (y l) (metricProjection_nonposOrthant, Figure 2 of [HMC00], p. 1137), with squared residual norm ∑ l, max 0 (y l) ^ 2. Whenever an instantaneous vector sequence r : ℕ → L → ℝ satisfies the Blackwell halfspace condition ∑ l, max 0 (∑ s < t, r s l) * r t l ≤ 0 for all t < T, the squared Euclidean distance of ∑ t < T, r t to nonposOrthant L is at most ∑ t < T, ∑ l, r t l ^ 2 (blackwell_orthant_potential_le).
  3. Blackwell external regret-matching (regretMatchingProb): playing p_t(a) ∝ [R_t(a)]_+ (and uniformly when no positive regrets exist; [HMC00] eq. (4.2b), p. 1139) satisfies the Blackwell condition with equality in every round without any learning-rate or horizon parameter, yielding externalRegretOf (regretMatchingProb ℓ) ℓ T k ≤ B √(|ι| T) whenever pairwise loss differences are bounded by B (regretMatching_externalRegret_le).
  4. Hart–Mas-Colell stationary internal regret-matching (internalRegretMatchingProb): playing a stationary distribution (Matrix.stationaryVec) of the positive-diagonal inertial transition matrix built from positive pairwise regrets ([HMC00] eqs. (2.2) and (3.1), Theorem A, pp. 1130–1138) satisfies balance equation (3.1) and the Blackwell condition on ι × ι with equality, guaranteeing anytime internal regret at most B √((|ι| - 1) T) (internalRegretMatching_pairInternalRegret_le) and swap regret at most B √(|ι| (|ι| - 1) T) (internalRegretMatching_swapRegret_le).

Main definitions #

Main results #

References #

Internal, swap, and external regret functionals #

The single-pair modification rule switch_i(·, j, k) of [BM07b] (§4.4): replaces action j by k and leaves every other action unchanged.

def Cslib.MachineLearning.OnlineLearning.Experts.pairInternalRegret {ι : Type u_1} (p ℓ : ℕ → ι → ℝ) (T : ℕ) (j k : ι) :

Cumulative pairwise internal regret for replacing action j with k over the first T rounds ([BM07b] §4.2; T times D_T^i(j, k) in [HMC00] eq. (2.1b), p. 1130).

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.pairInternalRegret_zero {ι : Type u_1} (p ℓ : ℕ → ι → ℝ) (j k : ι) :
pairInternalRegret p ℓ 0 j k = 0
@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.pairInternalRegret_same {ι : Type u_1} (p ℓ : ℕ → ι → ℝ) (T : ℕ) (j : ι) :
pairInternalRegret p ℓ T j j = 0
theorem Cslib.MachineLearning.OnlineLearning.Experts.pairInternalRegret_succ {ι : Type u_1} (p ℓ : ℕ → ι → ℝ) (T : ℕ) (j k : ι) :
pairInternalRegret p ℓ (T + 1) j k = pairInternalRegret p ℓ T j k + p T j * (ℓ T j - ℓ T k)
def Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) (δ : ι → ι) :

Cumulative swap regret against a modification rule δ : ι → ι over the first T rounds ([BM07b] §4.2).

def Cslib.MachineLearning.OnlineLearning.Experts.externalRegretOf {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) (k : ι) :

Cumulative external regret against a fixed action k : ι over the first T rounds ([BM07b] §4.2).

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.externalRegretOf_zero {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (k : ι) :
externalRegretOf p ℓ 0 k = 0
theorem Cslib.MachineLearning.OnlineLearning.Experts.externalRegretOf_succ {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) (k : ι) :
externalRegretOf p ℓ (T + 1) k = externalRegretOf p ℓ T k + (∑ j : ι, p T j * ℓ T j - ℓ T k)
theorem Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf_eq_sum_pairInternalRegret {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) (δ : ι → ι) :
swapRegretOf p ℓ T δ = ∑ j : ι, pairInternalRegret p ℓ T j (δ j)

Swap regret against δ is the sum of the pairwise internal regrets (j, δ j) over all actions j ([BM07b] §4.2).

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf_id {ι : Type u_1} [Fintype ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) :
swapRegretOf p ℓ T id = 0
theorem Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf_switchAction {ι : Type u_1} [Fintype ι] [DecidableEq ι] (p ℓ : ℕ → ι → ℝ) (T : ℕ) (j k : ι) :
swapRegretOf p ℓ T (switchAction j k) = pairInternalRegret p ℓ T j k

Swap regret against switchAction j k equals the pairwise internal regret pairInternalRegret for (j, k) ([BM07b] §§4.2, 4.4).

theorem Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf_const {ι : Type u_1} [Fintype ι] {p ℓ : ℕ → ι → ℝ} {T : ℕ} (hp : ∀ t < T, ∑ j : ι, p t j = 1) (k : ι) :
(swapRegretOf p ℓ T fun (x : ι) => k) = externalRegretOf p ℓ T k

When p t sums to 1 in each round t < T, swap regret against the constant map fun _ => k equals external regret against k ([BM07b] §4.2).

theorem Cslib.MachineLearning.OnlineLearning.Experts.swapRegretOf_le_card_mul_of_pairInternalRegret_le {ι : Type u_1} [Fintype ι] {p ℓ : ℕ → ι → ℝ} {T : ℕ} {R : ℝ} (hR : ∀ (j k : ι), pairInternalRegret p ℓ T j k ≤ R) (δ : ι → ι) :
swapRegretOf p ℓ T δ ≤ ↑(Fintype.card ι) * R

Exercise 4.1 of [BM07b]: if every pairwise internal regret is at most R, then swap regret against every modification rule δ : ι → ι is at most |ι| * R.

Euclidean projection onto ℝ_{\le 0}^L and Blackwell's quadratic potential #

The closed convex nonpositive orthant {z ∈ ℝ^L | ∀ l, z l ≤ 0} in EuclideanSpace ℝ L ([HMC00] §3, p. 1136, ℝ_-^L).

Figure 2 of [HMC00] (§3, p. 1137): the Euclidean metricProjection of y onto nonposOrthant L is the coordinatewise negative part l ↦ min 0 (y l).

Coordinatewise, subtracting the projection onto nonposOrthant L yields the positive part l ↦ max 0 (y l) ([HMC00] §3, p. 1137, λ(D_t) = D_t - [D_t]_- = [D_t]_+).

The squared distance of y to nonposOrthant L equals ∑ l, max 0 (y l) ^ 2.

theorem Cslib.MachineLearning.OnlineLearning.Experts.blackwell_orthant_potential_le {L : Type u_1} [Fintype L] {r : ℕ → L → ℝ} {T : ℕ} (hB : ∀ t < T, ∑ l : L, max 0 (∑ s ∈ Finset.range t, r s l) * r t l ≤ 0) :
∑ l : L, max 0 (∑ t ∈ Finset.range T, r t l) ^ 2 ≤ ∑ t ∈ Finset.range T, ∑ l : L, r t l ^ 2

Blackwell's quadratic potential bound for the nonpositive orthant ([Bla56]; [HMC00] §3, pp. 1135–1138, and Appendix Step M1, p. 1146): if a sequence of vectors r : ℕ → L → ℝ satisfies the halfspace condition ∑ l, max 0 (∑ s ∈ range t, r s l) * r t l ≤ 0 at every round t < T, then ∑ l, max 0 (∑ t ∈ range T, r t l) ^ 2 ≤ ∑ t ∈ range T, ∑ l, r t l ^ 2.

The one-step telescope uses the nearest-point property metricProjection_eq_iff_forall_norm_le of metricProjection (nonposOrthant L) and the Hilbert-space expansion norm_add_sq_real.

theorem Cslib.MachineLearning.OnlineLearning.Experts.blackwell_orthant_coord_le {L : Type u_1} [Fintype L] {r : ℕ → L → ℝ} {T : ℕ} (hB : ∀ t < T, ∑ l : L, max 0 (∑ s ∈ Finset.range t, r s l) * r t l ≤ 0) (l₀ : L) :
∑ t ∈ Finset.range T, r t l₀ ≤ √(∑ t ∈ Finset.range T, ∑ l : L, r t l ^ 2)

Coordinatewise consequence of blackwell_orthant_potential_le: every coordinate cumulative sum is bounded by √(∑ t < T, ∑ l, r t l ^ 2).

Blackwell's external regret-matching (p_t(a) ∝ [R_t(a)]_+) #

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.regretMatchingStep {ι : Type u_1} [Fintype ι] (rPos : ι → ℝ) (a : ι) :

One step of Blackwell's external regret-matching ([HMC00] eq. (4.2b), p. 1139): normalizes a nonnegative regret vector rPos when its sum is positive, and plays the uniform distribution 1 / |ι| otherwise.

theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatchingStep_nonneg {ι : Type u_1} [Fintype ι] {rPos : ι → ℝ} (hr : ∀ (b : ι), 0 ≤ rPos b) (a : ι) :
theorem Cslib.MachineLearning.OnlineLearning.Experts.mul_regretMatchingStep_eq {ι : Type u_1} [Fintype ι] {rPos : ι → ℝ} (hr : ∀ (b : ι), 0 ≤ rPos b) (a : ι) :
(∑ b : ι, rPos b) * regretMatchingStep rPos a = rPos a

Key proportionality identity of regretMatchingStep: for any nonnegative rPos, rPos a = (∑ b, rPos b) * regretMatchingStep rPos a holds unconditionally (without splitting on whether ∑ b, rPos b = 0).

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.regretMatchingProb {ι : Type u_1} [Fintype ι] (ℓ : ℕ → ι → ℝ) :
ℕ → ι → ℝ

Blackwell's external regret-matching learner ([Bla56]; [HMC00] §4(c), eqs. (4.2a)–(4.2b), p. 1139): in round t, plays proportional to the positive cumulative external regrets max 0 (externalRegretOf p ℓ t a), defaulting to the uniform distribution when no action has positive regret.

Unfolding equation for regretMatchingProb: round t applies regretMatchingStep to the positive cumulative external regrets from rounds < t.

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatchingProb_zero {ι : Type u_1} [Fintype ι] (ℓ : ℕ → ι → ℝ) (a : ι) :

In round 0, regretMatchingProb plays the uniform distribution 1 / |ι|.

theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatchingProb_congr {ι : Type u_1} [Fintype ι] {ℓ ℓ' : ℕ → ι → ℝ} {t : ℕ} (h : ∀ s < t, ℓ s = ℓ' s) :

regretMatchingProb is causal (an online algorithm): round t depends only on losses before round t.

theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_regretMatchingProb {ι : Type u_1} [Fintype ι] [Nonempty ι] (ℓ : ℕ → ι → ℝ) (t : ℕ) :
∑ a : ι, regretMatchingProb ℓ t a = 1
theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_max_externalRegret_mul_sub_eq_zero {ι : Type u_1} [Fintype ι] [Nonempty ι] (ℓ : ℕ → ι → ℝ) (t : ℕ) :
∑ a : ι, max 0 (externalRegretOf (regretMatchingProb ℓ) ℓ t a) * (∑ b : ι, regretMatchingProb ℓ t b * ℓ t b - ℓ t a) = 0

regretMatchingProb satisfies the Blackwell halfspace condition with equality in every round t, for arbitrary real-valued losses.

theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_max_externalRegret_regretMatchingProb_sq_le {ι : Type u_1} [Fintype ι] [Nonempty ι] (ℓ : ℕ → ι → ℝ) (T : ℕ) :
∑ a : ι, max 0 (externalRegretOf (regretMatchingProb ℓ) ℓ T a) ^ 2 ≤ ∑ t ∈ Finset.range T, ∑ a : ι, (∑ b : ι, regretMatchingProb ℓ t b * ℓ t b - ℓ t a) ^ 2

Quadratic potential bound for regretMatchingProb: the sum of squared positive external regrets after T rounds is at most ∑ t < T, ∑ a, (⟨p_t, ℓ_t⟩ - ℓ_t(a)) ^ 2.

theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatching_externalRegret_le {ι : Type u_1} [Fintype ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} {B : ℝ} (hB0 : 0 ≤ B) (hℓ : ∀ s < T, ∀ (a b : ι), |ℓ s a - ℓ s b| ≤ B) (k : ι) :
externalRegretOf (regretMatchingProb ℓ) ℓ T k ≤ B * √(↑(Fintype.card ι) * ↑T)

Anytime O(√T) external regret of Blackwell's regret-matching ([Bla56]; [HMC00] §4(c), Theorem B, p. 1139, quantitative finite-horizon form): if pairwise loss differences in rounds < T are bounded by B ≥ 0, then against every expert k : ι, externalRegretOf (regretMatchingProb ℓ) ℓ T k ≤ B * √(|ι| * T).

theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatching_externalRegret_le_of_mem_Icc {ι : Type u_1} [Fintype ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} (hℓ : ∀ s < T, ∀ (a : ι), ℓ s a ∈ Set.Icc 0 1) (k : ι) :

Specialization of regretMatching_externalRegret_le to [0, 1]-valued losses ([BM07b] §4.2 convention): external regret at most √(|ι| * T) for all T.

theorem Cslib.MachineLearning.OnlineLearning.Experts.regretMatching_externalRegret_le_of_abs_le {ι : Type u_1} [Fintype ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} {M : ℝ} (hM : 0 ≤ M) (hℓ : ∀ s < T, ∀ (a : ι), |ℓ s a| ≤ M) (k : ι) :
externalRegretOf (regretMatchingProb ℓ) ℓ T k ≤ 2 * M * √(↑(Fintype.card ι) * ↑T)

Specialization of regretMatching_externalRegret_le to [-M, M]-valued losses: external regret at most 2 * M * √(|ι| * T) for all T.

Hart–Mas-Colell stationary internal regret-matching (Theorem A) #

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.internalRegretTransition {ι : Type u_1} [Fintype ι] [DecidableEq ι] (rPos : ι → ι → ℝ) :
Matrix ι ι ℝ

Inertial regret-transition matrix of [HMC00] (§2, eq. (2.2), p. 1130, and Appendix p. 1144) with positive normalization μ = 1 + ∑ j', ∑ k', rPos j' k': off-diagonal entry (j, k) is rPos j k / μ, and diagonal entry (j, j) carries the remaining positive inertia mass 1 - (∑ k' ≠ j, rPos j k') / μ.

theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_mul_internalRegretTransition_balance {ι : Type u_1} [Fintype ι] [DecidableEq ι] {rPos : ι → ι → ℝ} {q : ι → ℝ} (hr : ∀ (j k : ι), 0 ≤ rPos j k) (hdiag : ∀ (j : ι), rPos j j = 0) (hstat : Matrix.vecMul q (internalRegretTransition rPos) = q) (j : ι) :
∑ k : ι, q k * rPos k j = q j * ∑ k : ι, rPos j k

Balance equation (3.1) of [HMC00] (§3, p. 1133, and (3.5) on p. 1137): any stationary vector q of internalRegretTransition rPos (where rPos ≥ 0 and rPos j j = 0) satisfies ∑ k, q k * rPos k j = q j * ∑ k, rPos j k for every action j.

theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_balance_mul_sub_eq_zero {ι : Type u_1} [Fintype ι] {rPos : ι → ι → ℝ} {q : ι → ℝ} (hbal : ∀ (j : ι), ∑ k : ι, q k * rPos k j = q j * ∑ k : ι, rPos j k) (v : ι → ℝ) :
∑ p : ι × ι, rPos p.1 p.2 * (q p.1 * (v p.1 - v p.2)) = 0

Equations (3.3)–(3.4) of [HMC00] (§3, pp. 1136–1137): whenever q satisfies the balance equation (3.1) for rPos, the inner product of rPos with the instantaneous pairwise regret vector (j, k) ↦ q j * (v j - v k) vanishes identically for every loss/payoff vector v : ι → ℝ.

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.internalRegretMatchingProb {ι : Type u_1} [Fintype ι] [DecidableEq ι] (ℓ : ℕ → ι → ℝ) :
ℕ → ι → ℝ

Hart–Mas-Colell stationary internal regret-matching learner ([HMC00] §3, eq. (3.1), Theorem A, p. 1133): in round t, chooses Matrix.stationaryVec of the inertial regret-transition matrix formed from the positive cumulative internal regrets of rounds < t.

theorem Cslib.MachineLearning.OnlineLearning.Experts.internalRegretMatchingProb_congr {ι : Type u_1} [Fintype ι] [DecidableEq ι] {ℓ ℓ' : ℕ → ι → ℝ} {t : ℕ} (h : ∀ s < t, ℓ s = ℓ' s) :

internalRegretMatchingProb is causal (an online algorithm): round t depends only on losses before round t.

internalRegretMatchingProb satisfies Hart and Mas-Colell's balance equation (3.1) in every round t.

theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_max_pairInternalRegret_sq_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} {B : ℝ} (hℓ : ∀ s < T, ∀ (a b : ι), |ℓ s a - ℓ s b| ≤ B) :
∑ p : ι × ι, max 0 (pairInternalRegret (internalRegretMatchingProb ℓ) ℓ T p.1 p.2) ^ 2 ≤ B ^ 2 * (↑(Fintype.card ι - 1) * ↑T)

Quadratic potential bound for internalRegretMatchingProb: when pairwise loss differences in rounds < T are bounded by B, ∑ p : ι × ι, max 0 (pairInternalRegret (internalRegretMatchingProb ℓ) ℓ T p.1 p.2) ^ 2 ≤ B ^ 2 * ((|ι| - 1 : ℕ) * T).

theorem Cslib.MachineLearning.OnlineLearning.Experts.internalRegretMatching_pairInternalRegret_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} {B : ℝ} (hB0 : 0 ≤ B) (hℓ : ∀ s < T, ∀ (a b : ι), |ℓ s a - ℓ s b| ≤ B) (j k : ι) :

Quantitative Theorem A of [HMC00] (§3, pp. 1133, 1138): if pairwise loss differences in rounds < T are bounded by B ≥ 0, then internalRegretMatchingProb achieves pairwise internal regret at most B * √((|ι| - 1) * T) for every pair of actions (j, k) and every horizon T.

theorem Cslib.MachineLearning.OnlineLearning.Experts.internalRegretMatching_swapRegret_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {ℓ : ℕ → ι → ℝ} {T : ℕ} {B : ℝ} (hB0 : 0 ≤ B) (hℓ : ∀ s < T, ∀ (a b : ι), |ℓ s a - ℓ s b| ≤ B) (δ : ι → ι) :
swapRegretOf (internalRegretMatchingProb ℓ) ℓ T δ ≤ B * √(↑(Fintype.card ι) * ↑(Fintype.card ι - 1) * ↑T)

Anytime O(√T) swap regret of Hart–Mas-Colell stationary regret-matching: by Cauchy–Schwarz over the |ι| pairs (j, δ j), if pairwise loss differences in rounds < T are bounded by B ≥ 0, then against every modification rule δ : ι → ι, swapRegretOf (internalRegretMatchingProb ℓ) ℓ T δ ≤ B * √(|ι| * (|ι| - 1) * T).