Skip to main content
© 2026 ePowerAI. All rights reserved.
CoursesContact
eAI
CoursesContact
Week 14: Capstone — Theory Meets Training
Optimization
01Week 1: Optimization for Learning
02Week 2: Convex Sets and Functions
03Week 3: Gradient Descent Theory
04Week 4: Least Squares and Conditioning
05Week 5: Classification Losses
06Week 6: Stochastic Gradient Descent
07Week 7: Momentum and Acceleration
08Week 8: Adaptive First-Order Methods
09Week 9: Practical Training Dynamics
10Week 10: Nonsmooth and Composite Objectives
11Week 11: Constraints: Projections and Penalties
12Week 12: Duality for Practitioners
13Week 13: Nonconvex Deep Learning
14Week 14: Capstone — Theory Meets Training
Week 14· Optimization· Nonconvex practice25 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're navigating a landscape — 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 — 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 profile | Recommended optimiser | Step size | Batch size BBB | |---|---|---|---| | Small, convex, well-conditioned (κ<10\kappa < 10κ<10) | GD | η=1/L\eta = 1/Lη=1/L | nnn (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.9 | 32–256 | | Large nnn, nonconvex, sparse gradients | Adam | η=10−3\eta = 10^{-3}η=10−3, defaults | 32–512 | | Nonconvex, best generalisation needed | SGD + momentum + cosine LR | tuned η\etaη, β=0.9\beta = 0.9β=0.9 | 256–1024 | | Constrained (ball/box/simplex) | Projected GD/SGD | η=1/L\eta = 1/Lη=1/L for GD | as 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 — no global optimality guarantees
  • 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 landscape — 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#

| Concept | Where | Key equation | |---|---|---| | ERM | W1 | J(θ)=1n∑ℓ(fθ(xi),yi)J(\theta) = \frac{1}{n}\sum \ell(f_\theta(x_i), y_i)J(θ)=n1​∑ℓ(fθ​(xi​),yi​) | | Convexity | W2 | f(θ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 & rates | W3 | f(xK)−f∗≤2L∥x0−x∗∥2Kf(x_K) - f^* \leq \frac{2L\|x_0-x^*\|^2}{K}f(xK​)−f∗≤K2L∥x0​−x∗∥2​ | | Least squares | W4 | min⁡w∥Xw−y∥22\min_w \|Xw-y\|_2^2minw​∥Xw−y∥22​, κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min}κ=λmax​/λmin​ | | Logistic / softmax | W5 | ∇wℓ=(σ(wTx)−y)x\nabla_w \ell = (\sigma(w^T x) - y) x∇w​ℓ=(σ(wTx)−y)x | | SGD | W6 | wk+1=wk−ηkgkw_{k+1} = w_k - \eta_k g_kwk+1​=wk​−ηk​gk​ (mini-batch) | | Momentum / Nesterov | W7 | vk+1=βvk−η∇f(wk)v_{k+1} = \beta v_k - \eta \nabla f(w_k)vk+1​=βvk​−η∇f(wk​) | | Adam | W8 | mk=β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 / clipping | W9 | Cosine, warmup, ∥g∥≤C\|g\| \leq C∥g∥≤C | | Subgradients / proximal | W10 | xk+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 / projections | W11 | xk+1=PC(xk−η∇f(xk))x_{k+1} = P_C(x_k - \eta \nabla f(x_k))xk+1​=PC​(xk​−η∇f(xk​)) | | Duality | W12 | g(λ)=min⁡xL(x,λ)g(\lambda) = \min_x L(x, \lambda)g(λ)=minx​L(x,λ), SVM dual | | Nonconvex | W13 | Overparam, 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 those who want Boyd-level depth and ML-frontier training science.
  • Probability & 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.
Exercise · Multiple choice

You're training a linear regression model with $n=1000$, $d=10$, convex and well-conditioned ($\\kappa \\approx 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 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))

ax_nc = plt.gcf().add_subplot(1, 2, 2)
# 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}")
← 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
  • Browser lab