Skip to main content

Deep Learning I

Neural networks, depth and modularity, stochastic gradient descent, backpropagation, and momentum.

6.1 Neural Networks

A neural network is a hypothesis class built from composed nonlinear functions that learns features directly from raw inputs. Composing linear maps alone collapses into a single linear map; applying an elementwise nonlinearity after each affine layer gives

\[ z_1 = x, \qquad z_{i+1} = f_i(W_i z_i + b_i), \qquad h_\theta(x) = z_k. \]

Expressing each layer as a matrix operation maps naturally to parallel hardware (GPUs).

6.1.1 Activation Functions

Common elementwise nonlinearities \(f_i:\mathbb R\to\mathbb R\):

  • Hyperbolic tangent: \(\tanh(x) = \dfrac{e^{2x}-1}{e^{2x}+1}\)
  • Sigmoid: \(\sigma(x) = \dfrac{1}{1+e^{-x}}\)
  • ReLU: \(\max\{x, 0\}\)

6.1.2 Universal Approximation

Theorem 6.1 (Universal Approximation Theorem) Any continuous function can be approximated arbitrarily well by a neural network with a single hidden layer, given enough hidden neurons.

6.2 Depth and Representation

  • Biology: Loosely inspired by hierarchical processing in the visual cortex (though the actual biological link is weak).
  • Circuit theory: Depth yields exponentially more compact representations—e.g., \(n\)-bit parity needs \(O(2^n)\) units in one hidden layer, vs. \(O(n)\) units across \(O(\log n)\) layers.
  • Modularity: Lower layers learn reusable features shared by higher layers (a learnable kernel rather than a hand-crafted one), improving data efficiency.
  • Empirical performance: At the same parameter budget, deep (“thin + tall”) networks outperform wide shallow (“fat + short”) ones.
  • Why now: Driven by large datasets, parallel compute, and better architectures and optimization.

6.3 Training Neural Networks

Training minimizes \(\min_\theta \sum_{i=1}^m \ell\bigl(h_\theta(x^{(i)}), y^{(i)}\bigr)\) with standard losses (squared error, logistic/hinge, softmax). Because the objective is non-convex, optimization targets good local solutions rather than guaranteed global optima.

6.3.1 Stochastic Gradient Descent

Full gradient descent averages over all \(m\) samples per step, which is costly for large datasets. Stochastic gradient descent (SGD) updates on one sample (or in practice a small minibatch) at a time:

\[ \theta \leftarrow \theta - \alpha\,\nabla_\theta\ell\bigl(h_\theta(x^{(i)}),\,y^{(i)}\bigr). \]

6.3.2 Jacobians and Backpropagation

Definition 6.1 (Jacobian Matrix) For \(f:\mathbb R^n\to\mathbb R^m\), the Jacobian \(\frac{\partial f(x)}{\partial x}\in\mathbb R^{m\times n}\) has \((i,j)\)-entry \(\frac{\partial f_i(x)}{\partial x_j}\). For scalar \(f\), \(\nabla_x f(x) = \bigl(\frac{\partial f(x)}{\partial x}\bigr)^\top\).

Three Jacobian rules used in the derivation:

  • Chain rule: \(\dfrac{\partial f(g(x))}{\partial x} = \dfrac{\partial f}{\partial g}\dfrac{\partial g}{\partial x}\).
  • Linear map: \(\dfrac{\partial(Ax)}{\partial x} = A\).
  • Elementwise map: \(\dfrac{\partial f(x)}{\partial x} = \operatorname{diag}\bigl(f'(x)\bigr)\).

Backpropagation computes all parameter gradients simultaneously in one forward pass and one backward pass by caching intermediate products. For layer \(z_{i+1} = f_i(W_i z_i + b_i)\), let \(D_i = \operatorname{diag}\bigl(f_i'(W_i z_i + b_i)\bigr)\), so \(\frac{\partial z_{i+1}}{\partial z_i} = D_i W_i\) and \(\frac{\partial z_{i+1}}{\partial b_i} = D_i\).

Define the upstream gradient \(g_i^\top = \frac{\partial \ell}{\partial z_k}\frac{\partial z_k}{\partial z_{k-1}}\cdots\frac{\partial z_{i+1}}{\partial z_i}\). Then \(g_i\) satisfies the backward recursion (with \(\circ\) elementwise):

\[ g_k = \nabla_{z_k}\ell(z_k, y), \qquad g_i = W_i^\top\bigl(g_{i+1} \circ f_i'(W_i z_i + b_i)\bigr), \]

which immediately gives the parameter gradients:

\[ \nabla_{b_i}\ell = g_{i+1}\circ f_i'(W_i z_i + b_i), \qquad \nabla_{W_i}\ell = \bigl(g_{i+1}\circ f_i'(W_i z_i + b_i)\bigr)z_i^\top. \]

Evaluating \(g_i\) via vector–matrix products from left to right costs \(O(n^2(k-i))\) instead of \(O(n^3(k-i))\) for matrix–matrix products.

Using \(\operatorname{vec}(ABC)=(C^\top\otimes A)\operatorname{vec}(B)\), write \(W_i z_i = (z_i^\top\otimes I)\operatorname{vec}(W_i)\). The chain rule gives

\[ \frac{\partial \ell}{\partial\operatorname{vec}(W_i)} = g_{i+1}^\top\operatorname{diag}\bigl(f_i'(W_i z_i + b_i)\bigr)(z_i^\top\otimes I), \]

which reshapes to \(\nabla_{W_i}\ell = \bigl(f_i'(W_i z_i + b_i)\circ g_{i+1}\bigr)z_i^\top\).

6.3.3 Non-Convexity and Momentum

  • Non-convex losses contain plateaus, saddle points, and local minima, so gradient descent has no global-optimum guarantee.
  • Momentum adds inertia from the previous step (\(\text{movement} = -\text{gradient} + \text{momentum}\)) to help carry updates past plateaus, saddle points, and shallow local minima.