ES98E · Course contents

Part A · Lectures 5–8

4. Neural learning: representation, optimisation and generalisation

A fixed Fourier basis represents a known periodic pattern efficiently. But for a complicated image or a molecular environment, choosing all useful features by hand can be the harder problem. A neural network makes the representation trainable, at the price of coupling feature choice to a nonlinear optimisation problem.

The likelihood interpretation of squared error survives unchanged: replacing Φw\Phi w by network outputs changes the parameterisation, not the Gaussian observation model. We can therefore focus on what depth adds, how gradients reach early layers, and why a good training fit remains insufficient.

In this chapter: activations, stochastic optimisation, residual learning, regularisation.

Where the nonlinearity enters

An affine layer followed by an elementwise activation computes

hℓ=ϕ(Wℓhℓ−1+bℓ),h0=x.h_\ell=\phi(W_\ell h_{\ell-1}+b_\ell),\qquad h_0=x.

Without the activations, composing any number of such layers yields one affine map. Nonlinearity makes new representations possible. For common activations such as tanh and ReLU, sufficiently wide networks with an affine output layer can uniformly approximate continuous functions on compact subsets of Euclidean space. This is an existence statement, under the relevant activation hypotheses; it gives neither a practical width nor a training guarantee. Arbitrary nonlinear activations do not all satisfy the same approximation theorem. Cybenko’s theorem gives a classical continuous-sigmoidal case.

Tanh is smooth and zero-centred, with derivative 1−tanh⁡2z1-\tanh^2z. For large ∣z∣|z|, it saturates and the derivative becomes small. ReLU, max⁡(0,z)\max(0,z), has derivative one on the positive half-line and zero on the negative half-line; it has no classical derivative at zero. A training implementation chooses a subgradient there. Leaky ReLU keeps a small negative-side slope, allowing updates where ReLU would be inactive.

Compare the functions and derivatives together. A large tanh activation can be almost unresponsive to a further change in its input; an inactive ReLU can be exactly unresponsive.

Output size is not gradient size
Tanh and its derivativevaluez-33-1.23.2solid: function · dashed: derivativeReLU and its derivativevaluez-33-1.23.2solid: function · dashed: derivative
Tanh and ReLU on the same input interval. Solid curves show the activations and dashed curves their derivatives. The ReLU derivative at zero is undefined and is omitted. Tanh saturation weakens local derivatives; ReLU preserves them only on its active side. ↗

Backpropagation applies the chain rule through Jacobians Jℓ=DℓWℓJ_\ell=D_\ell W_\ell, where DℓD_\ell contains activation derivatives. The early-layer gradient includes products of these matrices. Saturation can contract those products, but the weight matrices also matter. ReLU does not guarantee nonvanishing gradients, nor does tanh make deep learning impossible. Initialisation, normalisation, depth and conditioning determine the combined effect. A unit that remains negative for every training example gets zero ReLU gradient through that branch; a shared change upstream could still make it active later.

A gradient is transported through the same computation in reverse. Follow a unit output derivative back through a small scalar network. Changing the input exposes both tanh saturation and the inactive side of ReLU, while the common weight makes clear that activation derivatives are only part of the product.

Follow a gradient back through the layers

δℓ = δℓ₊₁ · w · φ′(w hℓ) · w = 1.1

tanh1.800.960.790.700.650.61input gradient: 0.00849ReLU1.801.982.182.402.642.90input gradient: 1.61051

tanh derivative product = 0.00849ReLU derivative product = 1.611

A pulse travels backwards through five scalar layers. Its size tracks the accumulated derivative magnitude, with a small minimum marker kept visible at zero. Tanh and ReLU share the same input and weight. Move the input below zero to expose the inactive ReLU branch. ReLU uses the chosen zero subgradient at its kink; a positive-side derivative does not remove weight-induced growth. ↗

A useful gradient need not use every observation

For empirical risk L(w)=n−1∑iℓi(w)L(w)=n^{-1}\sum_i\ell_i(w), full gradient descent uses wt+1=wt−ηt∇L(wt)w_{t+1}=w_t-\eta_t\nabla L(w_t). A uniformly sampled mini-batch BB gives

gB(w)=1∣B∣∑i∈B∇ℓi(w),wt+1=wt−ηtgB(wt).g_B(w)=\frac1{|B|}\sum_{i\in B}\nabla\ell_i(w),\qquad w_{t+1}=w_t-\eta_tg_B(w_t).

At a fixed ww, uniform sampling makes EB[gB]=∇L\mathbb E_B[g_B]=\nabla L. Biased sampling needs appropriate weights. Random reshuffling across an epoch is useful, but its later batches are not conditionally independent uniform draws given all earlier updates. Each update processes fewer examples; roughly n/∣B∣n/|B| updates constitute an epoch.

The computation saved per update permits frequent progress and mini-batch hardware parallelism. Gradient noise can help leave some unstable or shallow regions, but is not a guarantee of escaping local minima or finding a globally optimal solution. Its covariance depends on the data and current weights. Large learning rates can still destabilise even a convex quadratic: for L(w)=aw2/2L(w)=aw^2/2, a>0a>0, the update is wt+1=(1−ηa)wtw_{t+1}=(1-\eta a)w_t, convergent only for 0<ηa<20<\eta a<2.

A fixed quadratic lets us separate optimisation dynamics from representation learning. Its narrow direction has five times the curvature of its broad one. Play the iterates, then increase the learning rate past the stability threshold: the same downhill direction can produce a divergent sequence when the step is too large.

An optimiser has a step size, not just a direction

L(w) = ½(w₁² + 5w₂²) · wnext = w − η∇L(w)

-2.62.62.6-2.6weight w₁weight w₂ (equal units)dots: iterates · line: visual interpolation

step 0/40loss = 8.400

Play the exact gradient-descent iterates on a fixed quadratic. The contour ellipse and trajectory share equal coordinate units. Motion between points is a visual interpolation, not a continuous solver. Above η = 0.4 the steep direction is unstable; trajectories leaving the fixed viewport are reported instead of silently rescaled. ↗

Adam maintains moving estimates of gradients and squared gradients, with bias corrections, to rescale updates coordinatewise. It changes optimisation dynamics; it does not make the network objective convex. Learning-rate schedules and validation remain consequential for both SGD and adaptive methods.

Finite-step optimisation also selects among available solutions. One local formal calculation illustrates this without claiming a universal generalisation theorem. Under smoothness assumptions, a modified potential

L~=L+η4∥∇L∥2+O(η2)\widetilde L=L+\frac\eta4\|\nabla L\|^2+O(\eta^2)

has gradient-flow dynamics that match a deterministic gradient-descent step to the corresponding order in η\eta. Indeed, the η2∇2L∇L/2\eta^2\nabla^2L\nabla L/2 flow term is cancelled by the gradient of the added term. This is a local small-step approximation, not an exact SGD objective. Mini-batch dynamics require additional stochastic analysis. The source's unconditional “SGD minimises this augmented loss and therefore finds flat, generalising minima” is too strong; notions of sharpness also depend on parameter scaling.

Learn a change to a representation

If a useful representation is already present, a new block should be able to preserve it. A residual block writes

hℓ+1=hℓ+Fℓ(hℓ),∂hℓ+1∂hℓ=I+JFℓ.h_{\ell+1}=h_\ell+F_\ell(h_\ell),\qquad \frac{\partial h_{\ell+1}}{\partial h_\ell}=I+J_{F_\ell}.

The identity path lets the block express “no change” by learning a small residual. It also introduces short gradient routes through a deep composition. Matching dimensions is necessary; a projection shortcut can replace the identity when widths change. This is the central construction of He et al.'s residual networks.

For a scalar illustration, compare a plain block with derivative aa to a residual block with residual derivative aa: LL repetitions give aLa^L and (1+a)L(1+a)^L. Small residual derivatives can preserve gradients, but a=−1a=-1 kills the residual derivative and positive aa can cause growth. Skip connections improve trainability without guaranteeing it. Gradient decorrelation or “shattering” is distinct from a small gradient norm; a rapidly varying gradient is not a flat landscape. Expanding products of I+JFI+J_F suggests multiple paths, but a nonlinear ResNet is not literally an average of independent shorter networks.

Batch normalisation is one way to control activation scales. For a feature in a mini-batch, it computes

h^i=hi−μBvB+ϵ,BN⁡(hi)=γh^i+δ.\hat h_i=\frac{h_i-\mu_B}{\sqrt{v_B+\epsilon}},\qquad \operatorname{BN}(h_i)=\gamma\hat h_i+\delta.

Learned γ,δ\gamma,\delta restore adjustable scale and shift. Training uses batch statistics; inference typically uses stored running statistics, making batch size and distribution shift relevant. Normalisation is useful but is neither required by every residual design nor a proof against exploding gradients.

A depth-scaled update hℓ+1=hℓ+Δt F(tℓ,hℓ)h_{\ell+1}=h_\ell+\Delta t\,F(t_\ell,h_\ell) is an Euler step. With appropriate regularity and scaling as Δt→0\Delta t\to0, it leads to an ODE. Merely adding infinitely many unscaled blocks does not establish that limit. We use this distinction again in differential-equation models.

Choosing among successful fits

The bias–variance decomposition applies to the entire training algorithm, including architecture, randomness and stopping rule. More parameters can add expressive power, but high parameter count alone neither proves memorisation nor predicts test error. Regularisation changes which fits are preferred.

An explicit penalty gives Lλ=L+λg(w)L_\lambda=L+\lambda g(w). The Gaussian-prior interpretation of ℓ2\ell_2 penalties retains the likelihood scaling derived earlier. Under ordinary SGD, adding λ∥w∥2\lambda\|w\|^2 gives the update contribution −2ηλw-2\eta\lambda w, a multiplicative shrinkage. With adaptive optimisers, decoupled weight decay and an ℓ2\ell_2 objective penalty generally differ. An ℓ1\ell_1 penalty encourages sparsity, although plain gradient-based training need not produce the exact zeros of a proximal solver, and sparse internal weights do not automatically identify causal input features.

Early stopping uses validation performance to choose a training duration. Dropout independently masks activations during training; with retention probability qq, inverted dropout uses mh/qmh/q, m∼Bernoulli⁡(q)m\sim\operatorname{Bernoulli}(q), so the activation's expectation is preserved. Inference usually removes the masks. Shared-weight subnetworks provide an ensemble interpretation, not an exact identity with averaging every nonlinear subnetwork's output.

An explicit ensemble averages independently trained predictions. For KK predictors with equal error variance vv and pairwise correlation ρ\rho, the average has variance

Var⁡(eˉ)=v(ρ+1−ρK).\operatorname{Var}(\bar e)=v\left(\rho+\frac{1-\rho}{K}\right).

Only uncorrelated errors give the full 1/K1/K reduction. Shared bias and correlated failures remain. Bayesian neural networks instead integrate predictions over a weight posterior; approximating that posterior is the inference problem developed later. Neither ensembles nor Bayesian terminology alone ensure calibration.

We now have a flexible trainable function, but a dense layer still ignores the organisation of its input. Symmetry and graphs ask which relationships an architecture should preserve before any data are seen.