Documentation

CslibFrontier.MachineLearning.OnlineLearning.OnlineGradientDescent

Online gradient descent #

In online convex optimization [Zinkevich2003, Hazan2022] a learner repeatedly plays a point x t of a convex set K in a real inner product space, after which an adversary reveals a convex loss f t : E → ℝ. The regret against a comparator u ∈ K after T rounds is ∑ t < T, (f t (x t) - f t u). Online gradient descent (ogd) [Hazan2022, Algorithm 8] (the greedy projection algorithm of [Zinkevich2003, Algorithm 1]) steps against a subgradient and projects back onto K:

x 0 = x₀, x (t + 1) = Π_K (x t - η t • grad t (x t)).

Rounds are indexed from 0, so the step size η t here is the source's η_{t+1}. The subgradient oracle grad : ℕ → E → E is an arbitrary function of the round and the query point, and the losses f t are arbitrary. Since OGD is deterministic, an adversary that adapts to the learner's past points selects nothing it could not have fixed in advance, so these bounds cover adaptive adversaries. Every bound holds for each comparator u ∈ K; taking the maximum over u gives the regret Regret_T of [Hazan2022, §3.1].

The projection is any map proj satisfying the Pythagorean inequality ‖proj y - z‖ ≤ ‖y - z‖ for z ∈ K and landing in K (IsPythagoreanProjection). The metric projection onto a nonempty complete convex set is one (isPythagoreanProjection_metricProjection, [Hazan2022, Theorem 2.1]). Every Pythagorean projection step satisfies the Euclidean Bregman descent inequality (projected_step_bregman_le), so all static, horizon-independent, and strongly convex logarithmic regret bounds below are derived from the master adaptive OMD telescoping theorems in CslibFrontier.MachineLearning.OnlineLearning.OnlineMirrorDescent. The losses enter through the subgradient inequality f t x + ⟪grad t x, y - x⟫ ≤ f t y for x y ∈ K, the definition of convexity with subgradients in [Hazan2022, §2.1]. For differentiable convex losses with gradients it follows from ConvexOn.add_inner_le_of_hasGradientAt. The strongly convex form f t x + ⟪grad t x, y - x⟫ + α / 2 * ‖y - x‖ ^ 2 ≤ f t y follows likewise from StrongConvexOn.add_inner_add_le_of_hasGradientAt (or the HasGradientWithinAt variants, which allow boundary points). D bounds the diameter of K and G the subgradient norms on K.

Main definitions #

Main results #

References #

proj maps into K and satisfies the Pythagorean inequality ‖proj y - z‖ ≤ ‖y - z‖ for every z ∈ K, the only properties of the projection used by online gradient descent.

The metric projection onto a nonempty complete convex set satisfies the Pythagorean inequality [Hazan2022, Theorem 2.1].

Unconstrained gradient descent: the identity is a Pythagorean projection onto the whole space. Since Set.univ has no finite diameter (unless E is trivial), and the strongly convex hypotheses force a finite diameter (norm_sub_le_of_strongConvex), the bounds that apply to it nontrivially are those that use only ‖x₀ - u‖: ogd_two_mul_inner_le, ogd_sum_inner_le_of_const and ogd_regret_le_fixed_of_norm_sub_le.

noncomputable def Cslib.MachineLearning.OnlineLearning.OCO.ogd {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (proj : E → E) (η : ℕ → ℝ) (grad : ℕ → E → E) (x₀ : E) :
ℕ → E

The iterates of online gradient descent [Hazan2022, Algorithm 8] with projection proj, step sizes η, subgradient oracle grad and starting point x₀: x (t + 1) = proj (x t - η t • grad t (x t)).

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_zero {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} :
ogd proj η grad x₀ 0 = x₀
theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_succ {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (t : ℕ) :
ogd proj η grad x₀ (t + 1) = proj (ogd proj η grad x₀ t - η t • grad t (ogd proj η grad x₀ t))
theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_mem {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) (t : ℕ) :
ogd proj η grad x₀ t ∈ K
theorem Cslib.MachineLearning.OnlineLearning.OCO.norm_ogd_sub_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {G : ℝ} (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hη : ∀ (t : ℕ), 0 ≤ η t) (t : ℕ) :
‖ogd proj η grad x₀ t - x₀‖ ≤ G * ∑ s ∈ Finset.range t, η s

Each step of online gradient descent moves at most η t * G when the subgradients on K have norm at most G, so ‖x t - x₀‖ ≤ G * ∑ s < t, η s.

theorem Cslib.MachineLearning.OnlineLearning.OCO.projected_step_bregman_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} (hP : IsPythagoreanProjection K proj) {x g u : E} (hu : u ∈ K) {w : ℝ} (hw : 0 ≤ w) (h0 : w = 0 → g = 0) :
inner ℝ g (x - u) ≤ bregmanDiv (fun (z : E) => w * (‖z‖ ^ 2 / 2)) (fun (z : E) => w • z) u x - bregmanDiv (fun (z : E) => w * (‖z‖ ^ 2 / 2)) (fun (z : E) => w • z) u (proj (x - (1 / w) • g)) + 1 / 2 * (‖g‖ ^ 2 / w)

A Pythagorean projection step x' = proj (x - (1 / w) • g) (w ≥ 0, with g = 0 when w = 0) satisfies the Euclidean Bregman descent inequality for the scaled generator ψ z = w * (‖z‖ ^ 2 / 2).

theorem Cslib.MachineLearning.OnlineLearning.OCO.projected_step_two_mul_inner_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} (hP : IsPythagoreanProjection K proj) {x g u : E} (hu : u ∈ K) {c : ℝ} (hc : 0 < c) :
2 * inner ℝ g (x - u) ≤ (‖x - u‖ ^ 2 - ‖proj (x - c • g) - u‖ ^ 2) / c + c * ‖g‖ ^ 2

One projected gradient step decreases the squared distance to a feasible comparator, up to the inner-product loss and the squared step length.

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_step_bregman_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) {u : E} (hu : u ∈ K) (t : ℕ) (hη : 0 < η t) :
inner ℝ (grad t (ogd proj η grad x₀ t)) (ogd proj η grad x₀ t - u) ≤ bregmanDiv (fun (z : E) => 1 / η t * (‖z‖ ^ 2 / 2)) (fun (z : E) => (1 / η t) • z) u (ogd proj η grad x₀ t) - bregmanDiv (fun (z : E) => 1 / η t * (‖z‖ ^ 2 / 2)) (fun (z : E) => (1 / η t) • z) u (ogd proj η grad x₀ (t + 1)) + η t * ‖grad t (ogd proj η grad x₀ t)‖ ^ 2 / 2

One step of ogd satisfies the scaled Euclidean Bregman descent inequality for ψ z = (1 / η t) * (‖z‖ ^ 2 / 2).

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_two_mul_inner_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) {u : E} (hu : u ∈ K) (t : ℕ) (hη : 0 < η t) :
2 * inner ℝ (grad t (ogd proj η grad x₀ t)) (ogd proj η grad x₀ t - u) ≤ (‖ogd proj η grad x₀ t - u‖ ^ 2 - ‖ogd proj η grad x₀ (t + 1) - u‖ ^ 2) / η t + η t * ‖grad t (ogd proj η grad x₀ t)‖ ^ 2

One step of online gradient descent against a comparator u ∈ K: 2 ⟪g, x t - u⟫ ≤ (‖x t - u‖ ^ 2 - ‖x (t + 1) - u‖ ^ 2) / η t + η t ‖g‖ ^ 2 with g = grad t (x t) [Hazan2022, proof of Theorem 3.1].

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_sum_inner_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {η : ℕ → ℝ} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {D : ℝ} (hD : ∀ x ∈ K, ∀ y ∈ K, ‖x - y‖ ≤ D) (hη : ∀ (t : ℕ), 0 < η t) (hanti : Antitone η) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range (T + 1), inner ℝ (grad t (ogd proj η grad x₀ t)) (ogd proj η grad x₀ t - u) ≤ D ^ 2 / (2 * η T) + (∑ t ∈ Finset.range (T + 1), η t * ‖grad t (ogd proj η grad x₀ t)‖ ^ 2) / 2

The generic bound for online gradient descent with positive nonincreasing step sizes on a set of diameter at most D: against every u ∈ K, ∑ t ≤ T, ⟪grad t (x t), x t - u⟫ ≤ D ^ 2 / (2 η T) + (∑ t ≤ T, η t ‖grad t (x t)‖ ^ 2) / 2 [Hazan2022, proof of Theorem 3.1].

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_sum_inner_le_of_const {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) {c : ℝ} (hc : 0 < c) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range T, inner ℝ (grad t (ogd proj (fun (x : ℕ) => c) grad x₀ t)) (ogd proj (fun (x : ℕ) => c) grad x₀ t - u) ≤ ‖x₀ - u‖ ^ 2 / (2 * c) + (c * ∑ t ∈ Finset.range T, ‖grad t (ogd proj (fun (x : ℕ) => c) grad x₀ t)‖ ^ 2) / 2

Online gradient descent with a constant step size c > 0: against every u ∈ K, ∑ t < T, ⟪grad t (x t), x t - u⟫ ≤ ‖x₀ - u‖ ^ 2 / (2 c) + c (∑ t < T, ‖grad t (x t)‖ ^ 2) / 2. Only the distance from the starting point to the comparator enters, not the diameter of K.

theorem Cslib.MachineLearning.OnlineLearning.OCO.sum_sub_le_sum_inner {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {grad : ℕ → E → E} {f : ℕ → E → ℝ} (hsub : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) ≤ f t y) {x : ℕ → E} (hx : ∀ (t : ℕ), x t ∈ K) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range T, (f t (x t) - f t u) ≤ ∑ t ∈ Finset.range T, inner ℝ (grad t (x t)) (x t - u)

Regret through subgradients: for any points x t ∈ K and any u ∈ K, the subgradient inequality bounds ∑ t < T, (f t (x t) - f t u) by ∑ t < T, ⟪grad t (x t), x t - u⟫.

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_sum_inner_le_sqrt {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {D G c : ℝ} (hD : ∀ x ∈ K, ∀ y ∈ K, ‖x - y‖ ≤ D) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hc : 0 < c) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range (T + 1), inner ℝ (grad t (ogd proj (fun (t : ℕ) => c / √(↑t + 1)) grad x₀ t)) (ogd proj (fun (t : ℕ) => c / √(↑t + 1)) grad x₀ t - u) ≤ D ^ 2 / (2 * c) * √(↑T + 1) + c * G ^ 2 * (√(↑T + 1) - 1 / 2)

Online gradient descent with step sizes c / √(t + 1): the linearized regret over T + 1 rounds is at most D ^ 2 / (2 c) √(T + 1) + c G ^ 2 (√(T + 1) - 1 / 2).

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_regret_le_three_halves {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} {f : ℕ → E → ℝ} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {D G : ℝ} (hD0 : 0 < D) (hG0 : 0 < G) (hD : ∀ x ∈ K, ∀ y ∈ K, ‖x - y‖ ≤ D) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hsub : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) ≤ f t y) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range T, (f t (ogd proj (fun (t : ℕ) => D / (G * √(↑t + 1))) grad x₀ t) - f t u) ≤ 3 / 2 * G * D * √↑T

Regret of online gradient descent [Hazan2022, Theorem 3.1]: for losses satisfying the subgradient inequality with subgradients of norm at most G on a set of diameter at most D, the step sizes D / (G √(t + 1)) give regret at most 3 / 2 * G * D * √T against every u ∈ K.

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_regret_le_zinkevich {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} {f : ℕ → E → ℝ} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {D G : ℝ} (hD : ∀ x ∈ K, ∀ y ∈ K, ‖x - y‖ ≤ D) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hsub : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) ≤ f t y) {u : E} (hu : u ∈ K) {T : ℕ} (hT : 0 < T) :
∑ t ∈ Finset.range T, (f t (ogd proj (fun (t : ℕ) => 1 / √(↑t + 1)) grad x₀ t) - f t u) ≤ D ^ 2 * √↑T / 2 + (√↑T - 1 / 2) * G ^ 2

Zinkevich's regret bound [Zinkevich2003, Theorem 1]: with step sizes 1 / √(t + 1), the regret after T ≥ 1 rounds is at most D ^ 2 √T / 2 + (√T - 1 / 2) G ^ 2.

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_regret_le_fixed_of_norm_sub_le {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} {f : ℕ → E → ℝ} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {B G : ℝ} (hB0 : 0 < B) (hG0 : 0 < G) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hsub : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) ≤ f t y) {u : E} (hu : u ∈ K) (hx₀u : ‖x₀ - u‖ ≤ B) {T : ℕ} (hT : 0 < T) :
∑ t ∈ Finset.range T, (f t (ogd proj (fun (x : ℕ) => B / (G * √↑T)) grad x₀ t) - f t u) ≤ G * B * √↑T

Fixed step size, from the distance to the comparator: for a known horizon T ≥ 1 and a comparator u ∈ K with ‖x₀ - u‖ ≤ B, the constant step size B / (G √T) gives regret at most G * B * √T against u. No bound on the diameter of K is needed, so K may be the whole space; this is the regret bound behind [ShalevShwartzBenDavid2014, Theorem 14.8].

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_regret_le_fixed {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} {f : ℕ → E → ℝ} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {D G : ℝ} (hD0 : 0 < D) (hG0 : 0 < G) (hD : ∀ x ∈ K, ∀ y ∈ K, ‖x - y‖ ≤ D) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hsub : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) ≤ f t y) {u : E} (hu : u ∈ K) {T : ℕ} (hT : 0 < T) :
∑ t ∈ Finset.range T, (f t (ogd proj (fun (x : ℕ) => D / (G * √↑T)) grad x₀ t) - f t u) ≤ G * D * √↑T

Fixed step size: for a known horizon T ≥ 1, the constant step size D / (G √T) gives regret at most G * D * √T.

theorem Cslib.MachineLearning.OnlineLearning.OCO.norm_sub_le_of_strongConvex {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {f : E → ℝ} {g : E → E} {G α : ℝ} (hα : 0 < α) (hG : ∀ x ∈ K, ‖g x‖ ≤ G) (hsc : ∀ x ∈ K, ∀ y ∈ K, f x + inner ℝ (g x) (y - x) + α / 2 * ‖y - x‖ ^ 2 ≤ f y) {x y : E} (hx : x ∈ K) (hy : y ∈ K) :
‖x - y‖ ≤ 2 * G / α

The strongly convex hypotheses bound the diameter: if f satisfies f x + ⟪g x, y - x⟫ + α / 2 * ‖y - x‖ ^ 2 ≤ f y on K with α > 0 and ‖g x‖ ≤ G on K, then ‖x - y‖ ≤ 2 G / α for x y ∈ K.

theorem Cslib.MachineLearning.OnlineLearning.OCO.ogd_regret_le_log {E : Type u_1} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {K : Set E} {proj : E → E} {grad : ℕ → E → E} {x₀ : E} {f : ℕ → E → ℝ} (hP : IsPythagoreanProjection K proj) (hx₀ : x₀ ∈ K) {G α : ℝ} (hα : 0 < α) (hG : ∀ (t : ℕ), ∀ x ∈ K, ‖grad t x‖ ≤ G) (hsc : ∀ (t : ℕ), ∀ x ∈ K, ∀ y ∈ K, f t x + inner ℝ (grad t x) (y - x) + α / 2 * ‖y - x‖ ^ 2 ≤ f t y) {u : E} (hu : u ∈ K) (T : ℕ) :
∑ t ∈ Finset.range T, (f t (ogd proj (fun (t : ℕ) => 1 / (α * (↑t + 1))) grad x₀ t) - f t u) ≤ G ^ 2 / (2 * α) * (1 + Real.log ↑T)

Logarithmic regret for strongly convex losses [Hazan2022, Theorem 3.3]: if every loss satisfies f t x + ⟪grad t x, y - x⟫ + α / 2 * ‖y - x‖ ^ 2 ≤ f t y on K with α > 0 and the subgradients have norm at most G on K, the step sizes 1 / (α (t + 1)) give regret at most G ^ 2 / (2 α) * (1 + log T) against every u ∈ K. No separate diameter hypothesis is assumed (these hypotheses already force ‖x - y‖ ≤ 2 G / α on K, norm_sub_le_of_strongConvex).