Skip to main content
© 2026 ePowerAI — free, open courseware. No login required.
CoursesContact
ePOWERAI
CoursesContact
Week 14: Capstone — Theory Meets Training
Optimization

Foundations

  1. 01Week 1: Optimization for Learning
  2. 02Week 2: Convex Sets and Functions
  3. 03Week 3: Gradient Descent Theory

Model problems

  1. 04Week 4: Least Squares and Conditioning
  2. 05Week 5: Classification Losses

First-order stack

  1. 06Week 6: Stochastic Gradient Descent
  2. 07Week 7: Momentum and Acceleration
  3. 08Week 8: Adaptive First-Order Methods
  4. 09Week 9: Practical Training Dynamics

Structure

  1. 10Week 10: Nonsmooth and Composite Objectives
  2. 11Week 11: Constraints: Projections and Penalties
  3. 12Week 12: Duality for Practitioners

Nonconvex practice

  1. 13Week 13: Nonconvex Deep Learning
  2. 14Week 14: Capstone — Theory Meets Training
Week 14· Optimization· Nonconvex practice8 min read

Week 14: Capstone — Theory Meets Training

Learning Outcomes
  • Audit a training setup: identify loss shape, convexity status, conditioning, and noise level
  • Select optimiser (GD, SGDStochastic Gradient Descent, AdamAdaptive Moment Estimation (optimizer)) + schedule + batch size for a given problem profile
  • Map optimisation tools to RL training loops and generative model training
  • Write a short method justification citing course theory
Prerequisites

Background: The entire course (Weeks 1–13). This capstone assumes you can recognise convexity (W2), estimate smoothness (W3), choose among optimisers (W6–9), interpret constraints (W11), and think about nonconvex landscapes (W13).

Forward links: Advanced Optimization (second-order, variance reduction, SAM, distributed) picks up where this capstone leaves off. Probability & Statistics provides the MLE/MAP/KL language that connects training objectives to probabilistic modelling.

The full diagnostic checklist#

Before choosing an optimiser, run through this checklist:

  1. Convex or not? If the loss is convex (linear/logistic regression, SVM dual), global optimality is achievable. If nonconvex (deep nets), you are navigating a complex loss surface, so focus on architecture and initialisation.

  2. Smoothness estimate: What is LLL, the Lipschitz constant of the gradient? For quadratics f(x)=12xTQxf(x) = \frac{1}{2}x^T Q xf(x)=21​xTQx, L=λmax⁡(Q)L = \lambda_{\max}(Q)L=λmax​(Q). For deep nets, estimate via a power-iteration sweep on a mini-batch Hessian. Start with η≈1/L\eta \approx 1/Lη≈1/L.

  3. Condition number: Estimate κ=λmax⁡/λmin⁡\kappa = \lambda_{\max} / \lambda_{\min}κ=λmax​/λmin​. Large κ\kappaκ (>100>100>100) means GD will be slow, so add momentum or use Adam.

  4. Noise level: What is the variance of mini-batch gradients? High noise (small BBB, heterogeneous data) → use momentum or Adam + warmup + gradient clipping. Low noise (large BBB, homogeneous data) → plain SGD may suffice.

  5. Constraint structure: Are there box constraints, a simplex constraint, or a norm bound? If projections are cheap (ball, box), use projected GD. If not, consider soft penalties.

Method selection table#

Problem profileRecommended optimiserStep sizeBatch size BBB
Small, convex, well-conditioned (κ<10\kappa < 10κ<10)GDη=1/L\eta = 1/Lη=1/Lnnn (full)
Large nnn, convex, moderate κ\kappaκSGDη0=1/L\eta_0 = 1/Lη0​=1/L, decay ∝1/k\propto 1/\sqrt{k}∝1/k​32–256
Large ddd, convex, ill-conditioned (κ>100\kappa > 100κ>100)SGD + momentumη≈1/L\eta \approx 1/Lη≈1/L, β=0.9\beta = 0.9β=0.932–256
Large nnn, nonconvex, sparse gradientsAdamη=10−3\eta = 10^{-3}η=10−3, defaults32–512
Nonconvex, best generalisation neededSGD + momentum + cosine LRtuned η\etaη, β=0.9\beta = 0.9β=0.9256–1024
Constrained (ball/box/simplex)Projected GD/SGDη=1/L\eta = 1/Lη=1/L for GDas above
Composite (smooth + ℓ1\ell_1ℓ1​)Proximal gradient (ISTA)η=1/Lg\eta = 1/L_gη=1/Lg​as above

The default in 2026: Adam/AdamW with cosine LR schedule and small warmup. This is the safe choice when prototyping. Switch to SGD + momentum + cosine only when maximising final performance on a well-understood problem.

Case study A: policy gradient for RL#

Reinforcement learning optimises a policy πθ(a∣s)\pi_\theta(a \mid s)πθ​(a∣s) to maximise expected return. The policy gradient estimator is:

∇θJ(θ)≈1B∑i=1B∇θlog⁡πθ(ai∣si)⋅A^i\nabla_\theta J(\theta) \approx \frac{1}{B} \sum_{i=1}^B \nabla_\theta \log \pi_\theta(a_i \mid s_i) \cdot \hat A_i∇θ​J(θ)≈B1​∑i=1B​∇θ​logπθ​(ai​∣si​)⋅A^i​

where A^i\hat A_iA^i​ is an advantage estimate.

Optimisation profile:

  • Nonconvex. The policy objective is highly nonconvex, so no global optimality guarantees apply
  • High variance. The advantage estimates A^i\hat A_iA^i​ are noisy, creating large gradient variance even with BBB moderate
  • Non-stationary. The data distribution shifts as the policy changes, and value function estimates co-evolve

Standard recipe: Adam with η=3×10−4\eta = 3 \times 10^{-4}η=3×10−4, β1=0.9\beta_1 = 0.9β1​=0.9, β2=0.999\beta_2 = 0.999β2​=0.999, batch size determined by environment parallelism. Gradient clipping at norm 0.50.50.5–1.01.01.0. Linear LR decay or constant η\etaη. The value function baseline acts as a variance-reduction mechanism.

Link: Reinforcement Learning course

Case study B: denoising diffusion training#

Diffusion models and flow matching train a denoiser ϵθ(xt,t)\epsilon_\theta(x_t, t)ϵθ​(xt​,t) to predict the noise added to a clean sample. The training objective is:

J(θ)=Et,x0,ϵ[∥ϵ−ϵθ(αˉt x0+1−αˉt ϵ,t)∥22]J(\theta) = \mathbb{E}_{t, x_0, \epsilon} \left[ \|\epsilon - \epsilon_\theta(\sqrt{\bar\alpha_t}\, x_0 + \sqrt{1-\bar\alpha_t}\,\epsilon, t)\|_2^2 \right]J(θ)=Et,x0​,ϵ​[∥ϵ−ϵθ​(αˉt​​x0​+1−αˉt​​ϵ,t)∥22​]

Optimisation profile:

  • Large-scale. Models are large (10710^7107–10910^9109 parameters), datasets enormous
  • Well-behaved objective. The L2 denoising loss has a relatively benign surface, close to a massive least-squares problem in function space
  • Low gradient noise. The per-example loss is a simple squared error with explicit targets

Standard recipe: AdamW (Adam with decoupled weight decay) with η=10−4\eta = 10^{-4}η=10−4, β1=0.9\beta_1 = 0.9β1​=0.9, β2=0.999\beta_2 = 0.999β2​=0.999, cosine LR schedule with warmup. EMA of model weights (not gradient moments) for final inference. Large batch B≈256B \approx 256B≈256–204820482048 distributed across GPUs.

Link: Generative Models course

Course map#

ConceptWhereKey equation
ERMW1J(θ)=1n∑ℓ(fθ(xi),yi)J(\theta) = \frac{1}{n}\sum \ell(f_\theta(x_i), y_i)J(θ)=n1​∑ℓ(fθ​(xi​),yi​)
ConvexityW2f(θx+(1−θ)y)≤θf(x)+(1−θ)f(y)f(\theta x + (1-\theta)y) \leq \theta f(x) + (1-\theta)f(y)f(θx+(1−θ)y)≤θf(x)+(1−θ)f(y)
Smoothness & ratesW3f(xK)−f∗≤2L∥x0−x∗∥2Kf(x_K) - f^* \leq \frac{2L\lVert x_0-x^*\rVert^2}{K}f(xK​)−f∗≤K2L∥x0​−x∗∥2​
Least squaresW4min⁡w∥Xw−y∥22\min_w \lVert Xw-y\rVert_2^2minw​∥Xw−y∥22​, κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min}κ=λmax​/λmin​
Logistic / softmaxW5∇wℓ=(σ(wTx)−y)x\nabla_w \ell = (\sigma(w^T x) - y) x∇w​ℓ=(σ(wTx)−y)x
SGDW6wk+1=wk−ηkgkw_{k+1} = w_k - \eta_k g_kwk+1​=wk​−ηk​gk​ (mini-batch)
Momentum / NesterovW7vk+1=βvk−η∇f(wk)v_{k+1} = \beta v_k - \eta \nabla f(w_k)vk+1​=βvk​−η∇f(wk​)
AdamW8mk=β1mk−1+(1−β1)gkm_k = \beta_1 m_{k-1} + (1-\beta_1) g_kmk​=β1​mk−1​+(1−β1​)gk​, vk=β2vk−1+(1−β2)gk2v_k = \beta_2 v_{k-1} + (1-\beta_2) g_k^2vk​=β2​vk−1​+(1−β2​)gk2​
LR schedules / clippingW9Cosine, warmup, ∥g∥≤C\lVert g\rVert \leq C∥g∥≤C
Subgradients / proximalW10xk+1=proxηh(xk−η∇g(xk))x_{k+1} = \text{prox}_{\eta h}(x_k - \eta \nabla g(x_k))xk+1​=proxηh​(xk​−η∇g(xk​))
Constraints / projectionsW11xk+1=PC(xk−η∇f(xk))x_{k+1} = P_C(x_k - \eta \nabla f(x_k))xk+1​=PC​(xk​−η∇f(xk​))
DualityW12g(λ)=min⁡xL(x,λ)g(\lambda) = \min_x L(x, \lambda)g(λ)=minx​L(x,λ), SVM dual
NonconvexW13Overparam, init, normalisation

What next#

  • Advanced optimization. Second-order methods (Newton, L-BFGS), variance reduction (SVRG), distributed training, sharpness-aware minimisation (SAM), and automatic differentiation, for readers who want Boyd-level depth and ML-frontier training science.
  • Probability and statistics. The modelling side: MLE/MAP, exponential families, graphical models, and information theory (entropy/KL): the language connecting loss functions to probabilistic stories.
  • Reinforcement Learning and Generative Models: These applied courses use the optimisers from this course as black-box subroutine drivers. You now understand what's inside the black box.

Knowledge check#

Exercise · Multiple choice

You're training a linear regression model with n = 1000, d = 10, convex and well-conditioned (κ ≈ 5). Which optimiser and justification fits best?

GD with η=1/L — convex, well-conditioned, small n — exact descent works well
Adam with default η=10⁻³ — always the safe choice
SGD with B=1 — maximum stochasticity for exploration
Nesterov momentum — needs acceleration for κ=5
Question 1 of 4

For an RL policy gradient problem (high variance, nonconvex, non-stationary), the standard optimiser choice is:

Adam with small η and gradient clipping
Full-batch GD with η=1/L
Newton's method
Subgradient method

Browser lab: a training-diagnostics dashboard#

A mini training-diagnostics dashboard: (1) estimate LLL (smoothness) on a synthetic LS problem, plot loss + gradient norm; (2) run Adam on a small nonconvex problem and print the diagnostic checklist output.

python · runs in browser
import numpy as np
import matplotlib.pyplot as plt

rng = np.random.default_rng(42)

# --- Part 1: Estimate L on least squares ---
n, d = 200, 5
X = rng.normal(size=(n, d))
w_true = rng.normal(size=d)
y = X @ w_true + rng.normal(scale=0.2, size=n)

L_est = np.linalg.eigvalsh(X.T @ X / n).max()
print(f"[Diagnostic] Smoothness estimate: L ≈ {L_est:.4f}")
print(f"[Diagnostic] Recommended η for GD: 1/L ≈ {1/L_est:.4f}")

w = np.zeros(d)
eta = 1.0 / L_est
losses, grad_norms = [], []
for _ in range(60):
    resid = X @ w - y
    g = X.T @ resid / n
    w = w - eta * g
    losses.append(0.5 * np.mean(resid**2))
    grad_norms.append(np.linalg.norm(g))

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4.5))
ax1.semilogy(losses); ax1.set_title("Loss"); ax1.set_xlabel("Iter"); ax1.grid(True, alpha=0.3)
ax2.semilogy(grad_norms); ax2.set_title("||grad||"); ax2.set_xlabel("Iter"); ax2.grid(True, alpha=0.3)

# --- Part 2: Nonconvex check with Adam ---
def f_nonconvex(w):
    x, y = w[0], w[1]
    return x**4 - 3*x**2 + 0.5*x + y**4 - 2*y**2 + 0.3*y

def grad_nonconvex(w):
    x, y = w[0], w[1]
    return np.array([4*x**3 - 6*x + 0.5, 4*y**3 - 4*y + 0.3])

print("\n[Diagnostic] Nonconvex problem: f(x,y) = x⁴−3x²+½x + y⁴−2y²+0.3y")
print("[Diagnostic] Status: NONCONVEX — multiple local minima")
print("[Diagnostic] Method: Adam (default), η=0.05")
print("[Diagnostic] No constraints, moderate noise expected")

w = np.array([2.0, 2.0])
m = np.zeros(2); v = np.zeros(2)
eta_a, b1, b2, eps = 0.05, 0.9, 0.999, 1e-8
losses_nc = []
for t in range(1, 151):
    g = grad_nonconvex(w)
    m = b1*m + (1-b1)*g; v = b2*v + (1-b2)*g**2
    mh = m/(1-b1**t); vh = v/(1-b2**t)
    w = w - eta_a * mh/(np.sqrt(vh)+eps)
    losses_nc.append(f_nonconvex(w))

# Overwrite ax2 with the nonconvex results
ax2.clear()
ax2.plot(losses_nc)
ax2.set_title("Nonconvex Loss (Adam)"); ax2.set_xlabel("Iter")
ax2.grid(True, alpha=0.3)

plt.tight_layout(); plt.show()
print(f"\n[Diagnostic] Final loss: {losses_nc[-1]:.6f}")
print("Notice: both dashboards answer the same four questions — convexity, smoothness, conditioning, and noise.")

Key takeaways#

  • Method choice follows from five questions: convex or not, smoothness LLL, condition number κ\kappaκ, gradient noise, and constraint structure.
  • Each answer maps to a concrete optimizer, step size, and batch size; the method-selection table is this course compressed into one page.
  • The 2026 default is AdamW with cosine decay and warmup; switch to SGD + momentum + cosine when chasing final accuracy on a well-understood task.
  • RL policy gradients are nonconvex, high-variance, and non-stationary, so they use Adam with a small η\etaη and gradient clipping.
  • Diffusion training is a large but benign least-squares-style problem, so it uses AdamW with cosine decay plus warmup and a weight EMA.
  • Every earlier week shows up in the checklist: convexity (W2), smoothness (W3), conditioning (W4), stochasticity (W6), momentum and adaptivity (W7-8), schedules and clipping (W9), proximal and constraints (W10-11), duality (W12), and nonconvex practice (W13).

Further reading#

  • Ian Goodfellow, Yoshua Bengio & Aaron Courville, Deep Learning (MIT Press, 2016). Chapter 8 is the practitioner's guide to optimiser selection and training diagnostics.
  • Léon Bottou, Frank E. Curtis & Jorge Nocedal, Optimization Methods for Large-Scale Machine Learning (SIAM Review, 2018). Sections 6–7 discuss method choice and diagnostics at scale.
  • Diederik P. Kingma & Jimmy Ba, "Adam: A Method for Stochastic Optimization" (ICLR 2015). The default-optimiser reference. Freely available at arXiv:1412.6980.
  • Ilya Loshchilov & Frank Hutter, "Decoupled Weight Decay Regularization" (ICLR 2019). AdamW, the modern default. Freely available at arXiv:1711.05101.

Reading is free. PDF and ePub unlock with the newsletter. Join once and every lesson opens in this browser.

← Previous
Week 13: Nonconvex Deep Learning
On this page
  • The full diagnostic checklist
  • Method selection table
  • Case study A: policy gradient for RL
  • Case study B: denoising diffusion training
  • Course map
  • What next
  • Knowledge check
  • Browser lab: a training-diagnostics dashboard
  • Key takeaways
  • Further reading