Documentation

CslibFrontier.MachineLearning.LossMinimization.StochasticGradientDescent

Stochastic gradient descent for convex Lipschitz losses #

Projected stochastic gradient descent minimizes the true risk L_D(w) = ∫ ℓ w z ∂D of a convex loss over a convex set K from an i.i.d. sample S = (z₀, …, z_{T-1}). In step t it takes a subgradient g x (S t) of the loss ℓ · (S t) at the current point x and moves against it:

x 0 = x₀, x (t + 1) = proj (x t - η t • g (x t) (S t)),

which is online gradient descent (OCO.ogd) on the losses ℓ · (S t). Since x t depends only on S 0, …, S (t - 1), the online-to-batch conversion (OnlineLearning.integral_trueRisk_average_le_add) turns the regret bound of online gradient descent into a bound on the expected true risk of the average iterate. With step size B / (ρ √T), subgradients of norm at most ρ on K and a comparator u ∈ K with ‖x₀ - u‖ ≤ B, this is 𝔼_S L_D ((1 / T) ∑ t < T, x t) ≤ L_D u + B ρ / √T [ShalevShwartzBenDavid2014, Theorem 14.8, Corollary 14.12] (locators unverified).

K may be the whole space with proj = id, as in the source's unconstrained analysis; the only integrability hypothesis is that ℓ x₀ is D-integrable. Measurability of proj, ℓ and g makes the iterates measurable functions of the sample. For K = Set.univ the projection is the identity; the metric projection onto a nonempty complete convex set is Lipschitz (lipschitzWith_metricProjection), hence measurable.

The bound is in expectation. High-probability bounds, the log T / T rates for strongly convex losses, and running time are not treated here.

Main definitions #

Main results #

References #

noncomputable def Cslib.MachineLearning.sgd {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {T : ℕ} (proj : E → E) (η : ℕ → ℝ) (g : E → Z → E) (x₀ : E) (S : Fin T → Z) :
ℕ → E

The iterates of projected stochastic gradient descent with projection proj, step sizes η, subgradient oracle g and starting point x₀ on the sample S: x (t + 1) = proj (x t - η t • g (x t) (S t)) for t < T. After the sample is exhausted the subgradients are 0.

theorem Cslib.MachineLearning.sgd_def {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {T : ℕ} (proj : E → E) (η : ℕ → ℝ) (g : E → Z → E) (x₀ : E) (S : Fin T → Z) :
sgd proj η g x₀ S = OnlineLearning.OCO.ogd proj η (fun (t : ℕ) (x : E) => if h : t < T then g x (S ⟨t, h⟩) else 0) x₀
theorem Cslib.MachineLearning.sgd_mem {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {T : ℕ} {K : Set E} {proj : E → E} (hP : OnlineLearning.OCO.IsPythagoreanProjection K proj) (η : ℕ → ℝ) (g : E → Z → E) {x₀ : E} (hx₀ : x₀ ∈ K) (S : Fin T → Z) (t : ℕ) :
sgd proj η g x₀ S t ∈ K
theorem Cslib.MachineLearning.sgd_congr {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {T : ℕ} (proj : E → E) (η : ℕ → ℝ) (g : E → Z → E) (x₀ : E) {S S' : Fin T → Z} (t : ℕ) (hS : ∀ (i : Fin T), ↑i < t → S i = S' i) :
sgd proj η g x₀ S t = sgd proj η g x₀ S' t

Iterate t of stochastic gradient descent depends only on the examples before t.

theorem Cslib.MachineLearning.sgd_update {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] {T : ℕ} (proj : E → E) (η : ℕ → ℝ) (g : E → Z → E) (x₀ : E) (S : Fin T → Z) (t : Fin T) (z : Z) :
sgd proj η g x₀ (Function.update S t z) ↑t = sgd proj η g x₀ S ↑t

Iterate t of stochastic gradient descent does not depend on example t.

theorem Cslib.MachineLearning.measurable_sgd {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [MeasurableSpace Z] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] {T : ℕ} {proj : E → E} (hproj : Measurable proj) (η : ℕ → ℝ) {g : E → Z → E} (hg : Measurable (Function.uncurry g)) (x₀ : E) (t : ℕ) :
Measurable fun (S : Fin T → Z) => sgd proj η g x₀ S t

Each iterate of stochastic gradient descent is a measurable function of the sample.

theorem Cslib.MachineLearning.integral_trueRisk_sgd_average_le {Z : Type u_1} {E : Type u_2} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [MeasurableSpace Z] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] {T : ℕ} (hT : 0 < T) {D : MeasureTheory.Measure Z} [MeasureTheory.IsProbabilityMeasure D] {K : Set E} (hK : Convex ℝ K) {proj : E → E} (hP : OnlineLearning.OCO.IsPythagoreanProjection K proj) (hproj : Measurable proj) {ℓ : E → Z → ℝ} (hℓ : Measurable (Function.uncurry ℓ)) {g : E → Z → E} (hgm : Measurable (Function.uncurry g)) (hsub : ∀ (z : Z), ∀ x ∈ K, ∀ y ∈ K, ℓ x z + inner ℝ (g x z) (y - x) ≤ ℓ y z) {ρ : ℝ} (hρ : 0 < ρ) (hgρ : ∀ (z : Z), ∀ x ∈ K, ‖g x z‖ ≤ ρ) {x₀ u : E} (hx₀ : x₀ ∈ K) (hint : MeasureTheory.Integrable (ℓ x₀) D) (hu : u ∈ K) {B : ℝ} (hB : 0 < B) (hx₀u : ‖x₀ - u‖ ≤ B) :
(∫ (S : Fin T → Z), trueRisk ℓ D ((↑T)⁻¹ • ∑ t : Fin T, sgd proj (fun (x : ℕ) => B / (ρ * √↑T)) g x₀ S ↑t) ∂MeasureTheory.Measure.pi fun (x : Fin T) => D) ≤ trueRisk ℓ D u + B * ρ / √↑T

Stochastic gradient descent for convex Lipschitz losses [ShalevShwartzBenDavid2014, Theorem 14.8, Corollary 14.12] (locators unverified). Let g x z be a subgradient of the loss ℓ · z at x ∈ K relative to the convex set K, of norm at most ρ, and let ℓ x₀ be D-integrable. For a comparator u ∈ K with ‖x₀ - u‖ ≤ B, projected SGD with step size B / (ρ √T) on T i.i.d. examples from D satisfies 𝔼_S L_D ((1 / T) ∑ t < T, x t) ≤ L_D u + B ρ / √T.