Stat 577 — Statistical Learning Theory
Spring 2026
In Week 9A we built the conceptual scaffolding for neural networks:
Today: We formalize all of this — the math behind representation learning, backpropagation, and the practical machinery that makes training work.
PyTorch’s killer feature: automatic differentiation — compute gradients for free.
The core mechanism is autograd:
requires_grad=True tells PyTorch to track every operation on a tensor.backward() traverses the computational graph backward to compute \(\partial y / \partial x\)x.gradExample: For \(f(x) = x^2 + 3x + 1\) at \(x = 2\):
y = x**2 + 3*x + 1 builds the computational graphy.backward() computes \(f'(x) = 2x + 3\), so \(f'(2) = 7\)x.grad returns 7.0This is the same chain rule we will formalize in Block 5 — PyTorch just does it automatically.
ISLR’s insight: Hidden units are learned basis functions — like splines or polynomial features, but learned from data rather than pre-specified.
This is Step A from 9A, now made precise: the hidden layer constructs a new feature space \(\mathbf{z}\) in which the output layer (Step B) can succeed.
ESL’s deeper insight: Neural networks are a form of parametric projection pursuit regression (PPR).
PPR models:
\[f(\mathbf{x}) = \sum_{m=1}^{M} g_m(\boldsymbol{\omega}_m^T \mathbf{x})\]
where each \(g_m\) is estimated nonparametrically (smoothing splines, etc.).
Neural networks fix \(g_m = \sigma\) (a known parametric function):
\[f(\mathbf{x}) = \sum_{m=1}^{M} \beta_m \, \sigma(\boldsymbol{\alpha}_m^T \mathbf{x})\]
Why this matters: PPR can use only 5–10 terms (nonparametric \(g_m\) is expensive to estimate). Neural networks, with the cheap parametric \(\sigma\), can use 20–100+ terms — vastly more representational power.
For deeper networks, the per-unit ESL notation (\(\alpha_m\), \(\beta_k\)) becomes cumbersome. We switch to matrix notation (\(\mathbf{W}^{(\ell)}\), \(\mathbf{b}^{(\ell)}\)) for the general case.
Layer \(\ell\) (hidden): \(\quad \mathbf{z}^{(\ell)} = \sigma\!\left(\mathbf{W}^{(\ell)}\mathbf{z}^{(\ell-1)} + \mathbf{b}^{(\ell)}\right), \quad \ell = 1, \ldots, L-1\)
Output layer: \(\quad f(\mathbf{x}) = g\!\left(\mathbf{W}^{(L)}\mathbf{z}^{(L-1)} + \mathbf{b}^{(L)}\right)\), where \(g\) = identity (regression), sigmoid (binary), or softmax (multi-class)
Composition: \(\quad f = f_L \circ f_{L-1} \circ \cdots \circ f_1\)
Each layer learns progressively more abstract features — this is hierarchical feature learning:
This hierarchical composition is the fundamental reason deep networks outperform shallow ones.
MNIST example (ISLR Ch 10): 784 inputs \(\to\) 256 hidden \(\to\) 128 hidden \(\to\) 10 outputs.
| Layer | Weight matrix | Dimensions | Parameters |
|---|---|---|---|
| 1 | \(\mathbf{W}^{(1)}\) | \(256 \times (784 + 1)\) | \(200{,}960\) |
| 2 | \(\mathbf{W}^{(2)}\) | \(128 \times (256 + 1)\) | \(32{,}896\) |
| Output | \(\mathbf{W}^{(3)}\) | \(10 \times (128 + 1)\) | \(1{,}290\) |
| Total | \(235{,}146\) |
Recall from 9A: 60,000 training images but 235,146 parameters — 4x overparameterized. How this works is a central question for Block 6.
Universal Approximation (Cybenko 1989, Hornik 1991)
For any continuous function \(f: [0,1]^p \to \mathbb{R}\) and any \(\epsilon > 0\), there exists a single hidden layer network with \(M\) sigmoid units and weights \(\boldsymbol{\alpha}_1, \ldots, \boldsymbol{\alpha}_M\), \(\boldsymbol{\beta}\) such that
\[\left|f(\mathbf{x}) - \left[\beta_0 + \sum_{m=1}^{M} \beta_m \, \sigma(\alpha_{0m} + \boldsymbol{\alpha}_m^T\mathbf{x})\right]\right| < \epsilon \quad \text{for all } \mathbf{x} \in [0,1]^p\]
What UAT Does NOT Say
ISLR: “In theory a single hidden layer with a large number of units has the ability to approximate most functions. However, the learning task of discovering a good solution is made much easier with multiple layers each of modest size.”
Expressivity of a ReLU network = number of linear regions it can represent.
Same number of neurons, vastly different expressive power.
Practical Advice
ReLU is the default. Start here. It is computationally trivial (\(\max(0,z)\)), avoids saturation for \(z > 0\), and induces sparsity.
Sigmoid/Tanh: Only for output layers (sigmoid for binary probability, tanh for bounded outputs) or legacy architectures. Never in hidden layers of deep networks.
Leaky ReLU: If you observe dying neurons (many hidden units permanently outputting zero), switch to Leaky ReLU.
GELU: Modern alternative used in Transformers. Marginal gains in some architectures, but adds computational cost.
When in doubt, start with ReLU.
The hidden layers learn features. The output layer encodes your statistical model for \(Y | \mathbf{X}\).
The choice of:
…together define an implicit distributional assumption about the response.
This is the bridge between neural networks and the statistical modeling framework we have built all semester.
Output activation: Identity (no nonlinearity at the output)
\[f(\mathbf{x}) = T = \beta_0 + \boldsymbol{\beta}^T \mathbf{z}\]
Loss:
\[R(\boldsymbol{\theta}) = \sum_{i=1}^{n} \bigl(y_i - f_{\boldsymbol{\theta}}(\mathbf{x}_i)\bigr)^2\]
Statistical interpretation: This assumes \(Y | \mathbf{X} \sim N\!\left(f(\mathbf{x}),\, \sigma^2\right)\).
Minimizing MSE is equivalent to maximizing the Gaussian log-likelihood:
\[\ell(\boldsymbol{\theta}) = -\frac{n}{2}\log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\sum_{i=1}^n (y_i - f_{\boldsymbol{\theta}}(\mathbf{x}_i))^2\]
The second term is just \(-\frac{1}{2\sigma^2} R(\boldsymbol{\theta})\), so \(\arg\min R = \arg\max \ell\).
Binary classification (\(K = 2\)):
Multi-class classification (\(K > 2\)):
Output: softmax — \(f_k(\mathbf{x}) = \dfrac{e^{T_k}}{\sum_{j=1}^K e^{T_j}}\), ensuring \(\sum_k f_k = 1\)
Loss: \(R(\boldsymbol{\theta}) = -\sum_{i=1}^{n} \sum_{k=1}^{K} y_{ik} \log f_k(\mathbf{x}_i)\)
Week 6 callback: This is EXACTLY the multinomial logistic regression criterion — but applied to the learned hidden features \(\mathbf{z}\) instead of the raw inputs \(\mathbf{x}\).
The Unifying Principle
Every standard neural network loss function is just negative log-likelihood under a distributional assumption:
| Loss | Distribution | Output activation |
|---|---|---|
| MSE | Gaussian \(Y | \mathbf{X} \sim N(f(\mathbf{x}), \sigma^2)\) | Identity |
| Binary cross-entropy | Bernoulli \(Y | \mathbf{X} \sim \text{Bern}(\sigma(T))\) | Sigmoid |
| Categorical cross-entropy | Multinomial \(Y | \mathbf{X} \sim \text{Cat}(\text{softmax}(\mathbf{T}))\) | Softmax |
Neural networks do not abandon statistics — they embrace it at the output layer while learning features at the hidden layers.
To train a neural network, we need:
\[\frac{\partial R}{\partial \theta_j} \quad \text{for ALL parameters } \theta_j\]
Naive approach: perturb each parameter, use finite differences:
\[\frac{\partial R}{\partial \theta_j} \approx \frac{R(\theta_j + \epsilon) - R(\theta_j)}{\epsilon}\]
Cost: \(O(P)\) forward passes for \(P\) parameters — with \(P = 235{,}146\) (MNIST), this is impractical.
Backpropagation: Compute ALL gradients in a single backward pass — cost \(\approx O(P)\), roughly the same as one forward pass.
Backpropagation is not a separate optimization algorithm — it IS the chain rule, applied systematically to the computational graph.
Consider a small network: \(p = 2\) inputs, \(M = 2\) hidden units, 1 output.
Forward pass for a single observation \((\mathbf{x}_i, y_i)\):
Step 1 — Pre-activations:
\[v_1 = \alpha_{01} + \alpha_{11}x_1 + \alpha_{21}x_2, \qquad v_2 = \alpha_{02} + \alpha_{12}x_1 + \alpha_{22}x_2\]
Step 2 — Hidden activations:
\[Z_1 = \sigma(v_1), \qquad Z_2 = \sigma(v_2)\]
Step 3 — Output:
\[f = \beta_0 + \beta_1 Z_1 + \beta_2 Z_2\]
Step 4 — Loss (for one observation):
\[R_i = \tfrac{1}{2}(y_i - f)^2\]
The computational graph encodes the dependency structure of the computation:
\[\mathbf{x} \;\xrightarrow{\;\boldsymbol{\alpha}\;}\; \mathbf{v} \;\xrightarrow{\;\sigma\;}\; \mathbf{Z} \;\xrightarrow{\;\boldsymbol{\beta}\;}\; f \;\xrightarrow{\;(\cdot)^2\;}\; R\]
To find \(\frac{\partial R}{\partial \alpha_{11}}\), the chain rule gives:
\[\frac{\partial R}{\partial \alpha_{11}} = \underbrace{\frac{\partial R}{\partial f}}_{\text{output error}} \cdot \underbrace{\frac{\partial f}{\partial Z_1}}_{\text{output weight}} \cdot \underbrace{\frac{\partial Z_1}{\partial v_1}}_{\sigma'(v_1)} \cdot \underbrace{\frac{\partial v_1}{\partial \alpha_{11}}}_{x_1}\]
Each factor corresponds to one edge in the computational graph.
Many of these factors are shared across different parameter gradients. Backpropagation exploits this sharing.
Starting from the loss \(R_i = \frac{1}{2}(y_i - f)^2\):
Output error signal (gradient of loss w.r.t. prediction):
\[\delta_i \;=\; \frac{\partial R_i}{\partial f} \;=\; -(y_i - f)\]
Gradients w.r.t. output-layer weights (ESL eq 11.14, ISLR eq 10.29):
\[\frac{\partial R_i}{\partial \beta_m} = \delta_i \cdot Z_{mi}, \qquad \frac{\partial R_i}{\partial \beta_0} = \delta_i\]
These are simple: each gradient is the error signal times the corresponding hidden activation.
For multi-output networks (\(K\) outputs): \(\delta_{ki} = -(y_{ik} - f_k(\mathbf{x}_i))\) for regression (identity output). For classification with softmax + cross-entropy, the gradient w.r.t. the logit \(T_k\) takes the same clean form: \(\delta_{ki} = -(y_{ik} - p_k(\mathbf{x}_i))\), thanks to a special cancellation between softmax and cross-entropy.
Now propagate the error backward through the hidden layer.
Hidden error signal (ESL eq 11.15):
\[s_{mi} = \sigma'(v_{mi}) \sum_{k=1}^{K} \beta_{km}\, \delta_{ki}\]
Gradients w.r.t. input-layer weights (ESL eq 11.14, ISLR eq 10.30):
\[\frac{\partial R_i}{\partial \alpha_{jm}} = s_{mi} \cdot x_{ji}\]
The key: hidden-layer errors \(s_{mi}\) are computed by back-propagating output errors \(\delta_{ki}\) through the weights \(\beta_{km}\) and the activation derivative \(\sigma'(v_{mi})\).
This is where the name “back-propagation” comes from — errors flow backward through the network, from output to input.
Backpropagation (two-pass algorithm)
Forward pass: Compute and store all activations, layer by layer:
\[\mathbf{z}^{(0)} = \mathbf{x}, \qquad \mathbf{z}^{(\ell)} = \sigma\!\left(\mathbf{W}^{(\ell)}\mathbf{z}^{(\ell-1)} + \mathbf{b}^{(\ell)}\right), \quad \ell = 1, \ldots, L-1\] \[\mathbf{f} = g\!\left(\mathbf{W}^{(L)}\mathbf{z}^{(L-1)} + \mathbf{b}^{(L)}\right)\]
where \(g\) = identity (regression), sigmoid (binary), or softmax (multi-class).
Backward pass: Compute error signals, from output back to input:
\[\boldsymbol{\delta}^{(L)} = \nabla_{\mathbf{f}} R, \qquad \boldsymbol{\delta}^{(\ell)} = \sigma'\!\left(\mathbf{v}^{(\ell)}\right) \odot \left[(\mathbf{W}^{(\ell+1)})^T \boldsymbol{\delta}^{(\ell+1)}\right], \quad \ell = L\!-\!1, \ldots, 1\]
Gradients: \(\quad \dfrac{\partial R}{\partial \mathbf{W}^{(\ell)}} = \boldsymbol{\delta}^{(\ell)} \left(\mathbf{z}^{(\ell-1)}\right)^T, \qquad \dfrac{\partial R}{\partial \mathbf{b}^{(\ell)}} = \boldsymbol{\delta}^{(\ell)}\)
Update: \(\quad \boldsymbol{\theta} \leftarrow \boldsymbol{\theta} - \eta \nabla R(\boldsymbol{\theta})\)
Efficiency: Each gradient is computed exactly once. Total cost \(\approx\) 2x the cost of a single forward pass.
Backprop Summary
1. Backpropagation is the chain rule applied to a computational graph.
2. The forward pass stores activations; the backward pass computes gradients from output to input.
3. Total cost \(\approx\) 2x one forward pass, regardless of the number of parameters.
4. Output gradients: error \(\times\) activation. Hidden gradients: back-propagated through weights.
Interactive Backprop Walkthrough — step through a 2→2→1 network with concrete numbers, forward and backward
Given the loss \(R(\boldsymbol{\theta}) = \sum_{i=1}^n R_i(\boldsymbol{\theta})\), the full-batch gradient descent update is:
\[\boldsymbol{\theta}^{(t+1)} = \boldsymbol{\theta}^{(t)} - \eta \,\nabla R\bigl(\boldsymbol{\theta}^{(t)}\bigr)\]
\(\eta\) = learning rate — the single most important hyperparameter in deep learning.
Problem: Computing \(\nabla R\) requires summing over all \(n\) observations — for ImageNet (\(n = 1.2\) million), one gradient step = one full pass through the data.
Idea: Use a random minibatch \(\mathcal{B} \subset \{1, \ldots, n\}\) to approximate the full gradient:
\[\boldsymbol{\theta}^{(t+1)} = \boldsymbol{\theta}^{(t)} - \eta \,\frac{1}{|\mathcal{B}|} \sum_{i \in \mathcal{B}} \nabla R_i\bigl(\boldsymbol{\theta}^{(t)}\bigr)\]
Properties:
Full-batch GD takes clean, deterministic steps toward the nearest minimum. SGD adds noise from minibatch sampling — the path is jittery but still converges. The noise is not a bug; it is a feature.
The surprising benefit of stochastic noise:
ISLR: “SGD naturally enforces its own form of approximately quadratic regularization.”
Empirically: solutions found by SGD generalize better than those found by full-batch GD, even when both reach the same training loss.
\(R(\boldsymbol{\theta})\) is highly non-convex — many local minima, saddle points, and plateaus.
The modern understanding of why neural network optimization works despite non-convexity:
Recall the sigmoid derivative:
\[\sigma'(v) = \sigma(v)\bigl(1 - \sigma(v)\bigr)\]
In backpropagation, each layer multiplies by \(\sigma'(v)\):
\[\boldsymbol{\delta}^{(\ell)} = \underbrace{\sigma'(\mathbf{v}^{(\ell)})}_{\leq 0.25} \odot \left[(\mathbf{W}^{(\ell+1)})^T \boldsymbol{\delta}^{(\ell+1)}\right]\]
For a network with \(L\) layers, the gradient reaching layer 1 is multiplied by \(\sigma'\) at each of \(L - 1\) hidden layers:
\[\left|\frac{\partial R}{\partial \mathbf{W}^{(1)}}\right| \sim (0.25)^{L-1} \cdot \left|\frac{\partial R}{\partial \mathbf{W}^{(L)}}\right|\]
For \(L = 10\): \((0.25)^9 \approx 3.8 \times 10^{-6}\) — the gradient has effectively vanished.
ReLU alleviates this: \(\text{ReLU}'(z) = 1\) for \(z > 0\) — no multiplicative shrinkage. Gradients flow through ReLU layers without attenuation.
Sigmoid (left): gradient norms decay exponentially from the output layer toward the input — early layers stop learning.
ReLU (right): gradient norms remain roughly constant across layers — all layers learn effectively.
Starting at exact zero: Every hidden unit computes the same function — perfect symmetry. All gradients are identical. Nothing moves.
Random near zero (ESL): typical starting values \(\sim U[-0.7, 0.7]\) with standardized inputs.
ESL: “Starting with large weights typically leads to poor solutions.”
ESL: “With small weights, the network starts out approximately linear, and becomes nonlinear as the weights increase.”
But HOW small? Random draws from \(N(0, 0.01)\) work for shallow networks, but for deep networks the variance compounds across layers — we need a principled approach.
The key idea: Choose initial weights so the variance of activations is preserved across layers.
For one layer: \(z = \sum_{i=1}^{n_{\text{in}}} w_i x_i\). If \(w_i\) and \(x_i\) are independent with \(\mathbb{E}[w] = 0\) and \(\mathbb{E}[x] = 0\) (this is why we standardize inputs):
\[\text{Var}(z) = n_{\text{in}} \cdot \text{Var}(w) \cdot \text{Var}(x)\]
Setting \(\text{Var}(z) = \text{Var}(x)\) (preserve activation variance across layers):
\[\text{Var}(w) = \frac{1}{n_{\text{in}}}\]
| Method | Variance | Best for |
|---|---|---|
| Xavier/Glorot (2010) | \(\text{Var}(w) = \dfrac{2}{n_{\text{in}} + n_{\text{out}}}\) | Sigmoid, Tanh |
| He/Kaiming (2015) | \(\text{Var}(w) = \dfrac{2}{n_{\text{in}}}\) | ReLU |
The factor of 2 in He initialization accounts for ReLU zeroing out approximately half the activations.
Principle: Choose weights so variance of activations AND gradients is approximately constant across layers — prevents both vanishing and exploding.
\[R_{\text{reg}}(\boldsymbol{\theta}) = R(\boldsymbol{\theta}) + \lambda \sum_j \theta_j^2\]
The penalty applies to all weights in the network — input-to-hidden, hidden-to-hidden, and hidden-to-output. Bias terms are typically excluded (just as in ridge regression, we do not penalize the intercept).
Typical values: \(\lambda \sim 10^{-4}\) to \(10^{-2}\), tuned via validation loss.
Since the loss surface is non-convex, different initializations may lead to different solutions.
Strategy: Train \(K\) networks with different random seeds, then average their predictions:
\[\hat{f}_{\text{avg}}(\mathbf{x}) = \frac{1}{K}\sum_{k=1}^K \hat{f}_k(\mathbf{x})\]
Average Predictions, Not Weights
ESL: “Averaging predictions from different starting points is better than averaging the parameter values, because the nonlinearity of the model makes the averaged-weight solution a poor predictor.”
\[\frac{1}{K}\sum_k f(\mathbf{x}; \boldsymbol{\theta}_k) \;\neq\; f\!\left(\mathbf{x}; \frac{1}{K}\sum_k \boldsymbol{\theta}_k\right)\]
This is the same principle behind bagging and random forests (Weeks 7–8) — averaging reduces variance.
Neural Network Training Checklist
1. Preprocessing: Standardize inputs to mean 0, standard deviation 1. One-hot encode categorical variables.
2. Architecture: Start with ReLU activations. Err on the side of too many hidden units + regularization (easier to regularize an overparameterized model than to increase capacity).
3. Initialization: He (Kaiming) for ReLU; Xavier/Glorot for sigmoid/tanh.
4. Training: SGD or Adam optimizer, batch size 32–256. Monitor training AND validation loss every epoch.
5. Regularization: Early stopping (always). Weight decay (\(\lambda \sim 10^{-4}\) to \(10^{-2}\)). Try averaging over multiple random starts.
6. Diagnostics: Plot loss curves — look for training/validation divergence. Check gradient norms per layer — watch for vanishing/exploding.
Seven Things to Remember
1. ReLU is the default activation — sigmoid/tanh cause vanishing gradients in deep networks.
2. Every standard loss function is negative log-likelihood under a distributional assumption (MSE \(\leftrightarrow\) Gaussian, cross-entropy \(\leftrightarrow\) Bernoulli/Multinomial).
3. Backpropagation = the chain rule on a computational graph. Cost \(\approx\) 2x one forward pass for ALL gradients.
4. Vanishing gradients: sigmoid multiplies by \(\leq 0.25\) per layer; in a 10-layer network, early layers see gradients shrunk by \(10^6\).
5. Xavier/He initialization maintains activation variance across layers — prevents both vanishing and exploding.
6. SGD noise is implicit regularization — it prefers flat minima that generalize better.
7. The regularization toolkit: weight decay (ridge on weights), early stopping (shrinks toward linear), multiple random starts (variance reduction).
Weeks 2–3 (Linear Models + Regularization)
A neural network with no hidden layers IS a linear model. Weight decay IS ridge regression. Early stopping implicitly regularizes by shrinking the model toward its approximately linear initialization.
Weeks 7–8 (Trees + Ensembles)
Averaging predictions from multiple random starts parallels bagging — both reduce variance by combining diverse learners trained on different sources of randomness.
What Comes Next
1. Batch Normalization — normalize activations within each layer, stabilize training dynamics
2. Dropout — randomly zero out neurons during training, prevent co-adaptation (neural network’s version of random feature subsets)
3. Adam Optimizer — adaptive learning rates per parameter, faster convergence than vanilla SGD
4. Convolutional Neural Networks (CNNs) — weight sharing + local connectivity for image data, the architecture that launched the deep learning revolution
The foundations from this week (backprop, loss functions, activations) do not change — modern deep learning adds engineering innovations that make these foundations scale.