Neural Networks

⚡ Key Takeaways

Neural networks are parametric function approximators built from layered compositions of weighted sums and nonlinear activation functions, trained by gradient descent on a loss function. Key result: a feedforward network with a single sufficiently large hidden layer can approximate any continuous function on a compact set to arbitrary accuracy (Universal Approximation). Applies in: machine learning, computer vision, natural language processing, function approximation, control. Who/when: McCulloch & Pitts (1943), Rosenblatt (1958), Rumelhart–Hinton–Williams backpropagation (1986), deep learning revival (2006–2012).

💡 The Core Insight

A single neuron computes a linear decision boundary; it cannot represent nonlinearly separable patterns (e.g., XOR). But if you feed the outputs of many neurons into another layer of neurons, the composition of affine maps and nonlinearities becomes a universal building block. Depth and nonlinearity together convert a limited linear model into a representation that can bend, fold, and carve the input space arbitrarily. Crucially, the whole composite remains differentiable in its parameters, so the gradient of any scalar loss can be computed efficiently by reverse-mode differentiation.

Formal Statement

DefinitionArtificial Neuron

A single neuron with input x∈Rn\mathbf{x} \in \mathbb{R}^n, weight vector w∈Rn\mathbf{w} \in \mathbb{R}^n, bias b∈Rb \in \mathbb{R}, and activation function σ:R→R\sigma: \mathbb{R} \to \mathbb{R} computes:

1
a=σ ⁣(w⊤x+b)=σ ⁣(∑i=1nwixi+b)\quad a = \sigma\!\left( \mathbf{w}^\top \mathbf{x} + b \right) = \sigma\!\left( \sum_{i=1}^{n} w_i x_i + b \right)

Derivation hint: model the biological neuron's "weighted summation of inputs followed by a threshold firing rule"; replace the hard threshold with a smooth σ\sigma for differentiability. Here z=w⊤x+bz = \mathbf{w}^\top \mathbf{x} + b is the pre-activation (or logit), and aa is the activation (output). The bias bb shifts the decision boundary away from the origin.

DefinitionFeedforward Network / Multilayer Perceptron

A network of LL layers maps input a(0)=x\mathbf{a}^{(0)} = \mathbf{x} through layers indexed ℓ=1,…,L\ell = 1, \dots, L. Let W(ℓ)∈Rnℓ×nℓ−1W^{(\ell)} \in \mathbb{R}^{n_\ell \times n_{\ell-1}} be the weight matrix and b(ℓ)∈Rnℓ\mathbf{b}^{(\ell)} \in \mathbb{R}^{n_\ell} the bias of layer ℓ\ell. Then:

2
z(ℓ)=W(ℓ)a(ℓ−1)+b(ℓ),a(ℓ)=σ(ℓ) ⁣(z(ℓ))\quad \mathbf{z}^{(\ell)} = W^{(\ell)} \mathbf{a}^{(\ell-1)} + \mathbf{b}^{(\ell)}, \qquad \mathbf{a}^{(\ell)} = \sigma^{(\ell)}\!\left( \mathbf{z}^{(\ell)} \right)

Derivation hint: stack nℓn_\ell neurons of form [1] into one layer; each row of W(ℓ)W^{(\ell)} is one neuron's weight vector, and σ\sigma is applied elementwise. The full network is the composition fθ(x)=σ(L)∘A(L)∘⋯∘σ(1)∘A(1)(x)f_\theta(\mathbf{x}) = \sigma^{(L)} \circ A^{(L)} \circ \dots \circ \sigma^{(1)} \circ A^{(1)}(\mathbf{x}) where A(ℓ)(a)=W(ℓ)a+b(ℓ)A^{(\ell)}(\mathbf{a}) = W^{(\ell)}\mathbf{a} + \mathbf{b}^{(\ell)}, and θ={W(ℓ),b(ℓ)}ℓ=1L\theta = \{W^{(\ell)}, \mathbf{b}^{(\ell)}\}_{\ell=1}^{L}.

DefinitionCommon Activation Functions
3
σsig(z)=11+e−z,tanh⁡(z)=ez−e−zez+e−z,ReLU(z)=max⁡(0,z)\quad \sigma_{\text{sig}}(z) = \frac{1}{1+e^{-z}}, \quad \tanh(z) = \frac{e^z - e^{-z}}{e^z + e^{-z}}, \quad \text{ReLU}(z) = \max(0, z)

Derivation hint: sigmoid is the logistic CDF squashing R→(0,1)\mathbb{R}\to(0,1); tanh⁡\tanh is a rescaled sigmoid; ReLU is the simplest piecewise-linear nonlinearity, ∂zReLU=1[z>0]\partial_z\text{ReLU} = \mathbf{1}[z>0].

DefinitionLoss Functions

For supervised learning with targets y\mathbf{y}, common losses for a dataset of NN examples are mean squared error (regression) and cross-entropy (classification):

4
LMSE=1N∑k=1N∥fθ(xk)−yk∥2,LCE=−1N∑k=1N∑cyk,c log⁡p^k,c\quad \mathcal{L}_{\text{MSE}} = \frac{1}{N}\sum_{k=1}^{N} \left\| f_\theta(\mathbf{x}_k) - \mathbf{y}_k \right\|^2, \qquad \mathcal{L}_{\text{CE}} = -\frac{1}{N}\sum_{k=1}^{N} \sum_{c} y_{k,c}\,\log \hat{p}_{k,c}

Derivation hint: MSE is the negative log-likelihood under a Gaussian noise model; cross-entropy is the negative log-likelihood under a categorical (softmax) model. The softmax output converts logits z\mathbf{z} into a probability vector: p^c=ezc/∑jezj\hat{p}_c = e^{z_c} / \sum_j e^{z_j}.

TheoremUniversal Approximation (Cybenko 1989; Hornik 1991)

Let σ\sigma be a continuous, non-constant, bounded function (e.g. sigmoid). For any continuous function g:K→Rg: K \to \mathbb{R} on a compact set K⊂RnK \subset \mathbb{R}^n and any ε>0\varepsilon > 0, there exist N∈NN \in \mathbb{N}, weights wi∈Rn\mathbf{w}_i \in \mathbb{R}^n, biases bi∈Rb_i \in \mathbb{R}, and coefficients αi∈R\alpha_i \in \mathbb{R} such that:

5
sup⁡x∈K∣g(x)−∑i=1Nαi σ ⁣(wi⊤x+bi)∣<ε\quad \sup_{\mathbf{x}\in K}\left| g(\mathbf{x}) - \sum_{i=1}^{N} \alpha_i\,\sigma\!\left(\mathbf{w}_i^\top \mathbf{x} + b_i\right) \right| < \varepsilon

Derivation hint: the set of single-hidden-layer functions is dense in C(K)C(K); Cybenko's proof uses the Hahn–Banach theorem and discriminatory property of σ\sigma to show no nonzero signed measure annihilates this set. That is, a single hidden layer of unbounded width can approximate any continuous function uniformly on compacts. Width may be exponential; depth can give exponentially more efficient representations.

Why It Holds / Derivation

The defining algorithm is backpropagation — efficient computation of ∇θL\nabla_\theta \mathcal{L} by the chain rule.

ProofBackpropagation

Goal: compute ∂L/∂Wij(ℓ)\partial \mathcal{L} / \partial W^{(\ell)}_{ij} and ∂L/∂bi(ℓ)\partial \mathcal{L} / \partial b^{(\ell)}_i for all layers.

Step 1 — Define the error signal. Let δi(ℓ)=∂L/∂zi(ℓ)\delta^{(\ell)}_i = \partial \mathcal{L} / \partial z^{(\ell)}_i, the sensitivity of the loss to the pre-activation of neuron ii in layer ℓ\ell. Collect into δ(ℓ)\boldsymbol\delta^{(\ell)}.

Step 2 — Output layer. By the chain rule through a(L)=σ(L)(z(L))\mathbf{a}^{(L)} = \sigma^{(L)}(\mathbf{z}^{(L)}):

6
δ(L)=∇a(L)L  ⊙  σ(L)′ ⁣(z(L))\quad \boldsymbol\delta^{(L)} = \nabla_{\mathbf{a}^{(L)}} \mathcal{L} \;\odot\; \sigma^{(L)\prime}\!\left(\mathbf{z}^{(L)}\right)

Derivation hint: ∂L/∂zi(L)=(∂L/∂ai(L))(∂ai(L)/∂zi(L))\partial\mathcal L/\partial z^{(L)}_i = (\partial\mathcal L/\partial a^{(L)}_i)(\partial a^{(L)}_i/\partial z^{(L)}_i); the second factor is σ′\sigma'; ⊙\odot is elementwise product.

Step 3 — Recursive backward pass. Since zj(ℓ+1)=∑iWji(ℓ+1)ai(ℓ)+bj(ℓ+1)z^{(\ell+1)}_j = \sum_i W^{(\ell+1)}_{ji} a^{(\ell)}_i + b^{(\ell+1)}_j and ai(ℓ)=σ(zi(ℓ))a^{(\ell)}_i = \sigma(z^{(\ell)}_i):

7
δ(ℓ)=(W(ℓ+1)⊤δ(ℓ+1))⊙σ(ℓ)′ ⁣(z(ℓ))\quad \boldsymbol\delta^{(\ell)} = \left( W^{(\ell+1)\top} \boldsymbol\delta^{(\ell+1)} \right) \odot \sigma^{(\ell)\prime}\!\left(\mathbf{z}^{(\ell)}\right)

Derivation hint: apply the multivariable chain rule δi(ℓ)=∑jδj(ℓ+1)(∂zj(ℓ+1)/∂ai(ℓ))(∂ai(ℓ)/∂zi(ℓ))\delta^{(\ell)}_i=\sum_j \delta^{(\ell+1)}_j (\partial z^{(\ell+1)}_j/\partial a^{(\ell)}_i)(\partial a^{(\ell)}_i/\partial z^{(\ell)}_i); the first partial is Wji(ℓ+1)W^{(\ell+1)}_{ji}.

Step 4 — Parameter gradients. Since zi(ℓ)z^{(\ell)}_i depends on Wij(ℓ)W^{(\ell)}_{ij} through aj(ℓ−1)a^{(\ell-1)}_j:

8
∂L∂Wij(ℓ)=δi(ℓ) aj(ℓ−1),∂L∂bi(ℓ)=δi(ℓ)\quad \frac{\partial \mathcal{L}}{\partial W^{(\ell)}_{ij}} = \delta^{(\ell)}_i \, a^{(\ell-1)}_j, \qquad \frac{\partial \mathcal{L}}{\partial b^{(\ell)}_i} = \delta^{(\ell)}_i

Derivation hint: ∂zi(ℓ)/∂Wij(ℓ)=aj(ℓ−1)\partial z^{(\ell)}_i/\partial W^{(\ell)}_{ij} = a^{(\ell-1)}_j and ∂zi(ℓ)/∂bi(ℓ)=1\partial z^{(\ell)}_i/\partial b^{(\ell)}_i = 1; multiply by δi(ℓ)\delta^{(\ell)}_i.

Step 5 — Cost. One forward pass plus one backward pass computes the entire gradient in O(∣θ∣)O(|\theta|) time — the same order as evaluating the network itself. ■\blacksquare

∎
DefinitionGradient Descent Update

Parameters are updated against the gradient with learning rate η>0\eta > 0. Stochastic gradient descent (SGD) uses a minibatch B\mathcal{B}:

9
θ←θ−η ∇θLB(θ),∇θLB=1∣B∣∑k∈B∇θℓ(fθ(xk),yk)\quad \theta \leftarrow \theta - \eta\,\nabla_\theta \mathcal{L}_{\mathcal{B}}(\theta), \qquad \nabla_\theta \mathcal{L}_{\mathcal{B}} = \frac{1}{|\mathcal{B}|}\sum_{k\in\mathcal{B}} \nabla_\theta \ell(f_\theta(\mathbf{x}_k), \mathbf{y}_k)

Derivation hint: first-order Taylor expansion L(θ−η∇)≈L(θ)−η∥∇∥2\mathcal L(\theta-\eta\nabla)\approx \mathcal L(\theta)-\eta\|\nabla\|^2 shows movement along −∇-\nabla decreases loss for small η\eta; the minibatch estimate is an unbiased gradient estimator.

Figure
A two-hidden-layer feedforward network: forward signal flow and backward gradient flow
Feedforward Network — forward (gold) and backprop (gray) x a⁽¹⁾ a⁽²⁾ ŷ δ propagated backward: δ⁽ˡ⁾ = (Wᵀ δ⁽ˡ⁺¹⁾) ⊙ σ′(z⁽ˡ⁾) z⁽ˡ⁾ = W⁽ˡ⁾a⁽ˡ⁻¹⁾ + b⁽ˡ⁾ → a⁽ˡ⁾ = σ(z⁽ˡ⁾)
FR
Frank Rosenblatt
1928–1971

An American psychologist who, in 1958, built the Perceptron — both an algorithm and a physical machine (the Mark I Perceptron) with motor-driven potentiometers as adjustable weights, designed to recognize images. Rosenblatt proved the Perceptron Convergence Theorem: for linearly separable data, the simple update w←w+ykxk\mathbf{w} \leftarrow \mathbf{w} + y_k\mathbf{x}_k on misclassified points terminates in finitely many steps. His optimistic claims drew sharp criticism; Minsky and Papert's 1969 book Perceptrons showed single-layer perceptrons cannot compute XOR, contributing to the first "AI winter." Multilayer networks with backpropagation eventually vindicated the broader research program two decades later.

Building Intuition

🧠 Intuition

Think of each neuron as drawing a hyperplane in input space and outputting "how far, and on which side" (softened by σ\sigma). The first hidden layer carves space into linear regions; the second layer takes logical combinations of those regions (intersections via AND-like patterns, unions via OR-like patterns); deeper layers combine those into ever-more-elaborate shapes. With ReLU, the network is literally a continuous piecewise-linear function — the input space is partitioned into polytopes, and the network is affine on each. Depth multiplies the number of linear regions exponentially, which is why deep narrow networks can be vastly more expressive than shallow wide ones with the same parameter count. Training "bends" all these boundaries simultaneously by following the negative gradient downhill on the loss surface.

Worked Examples

ExampleForward pass through one neuron

Given: input x=(1,2)⊤\mathbf{x} = (1, 2)^\top, weights w=(0.5,−1)⊤\mathbf{w} = (0.5, -1)^\top, bias b=0.5b = 0.5, activation = sigmoid.

Step 1 — Pre-activation: z=0.5(1)+(−1)(2)+0.5=0.5−2+0.5=−1.0z = 0.5(1) + (-1)(2) + 0.5 = 0.5 - 2 + 0.5 = -1.0.

Step 2 — Activation: a=σ(−1.0)=11+e1.0=11+2.718=13.718=0.269a = \sigma(-1.0) = \dfrac{1}{1+e^{1.0}} = \dfrac{1}{1+2.718} = \dfrac{1}{3.718} = 0.269.

Step 3 — Derivative (for later backprop): σ′(z)=a(1−a)=0.269×0.731=0.197\sigma'(z) = a(1-a) = 0.269 \times 0.731 = 0.197.

a=0.269,σ′(z)=0.197 (dimensionless)\boxed{a = 0.269,\qquad \sigma'(z) = 0.197\ \text{(dimensionless)}}
ExampleOne backprop / SGD step on MSE

Given: the neuron above with output a=0.269a = 0.269, target y=1y = 1, MSE loss ℓ=(a−y)2\ell = (a - y)^2, learning rate η=0.1\eta = 0.1.

Step 1 — Loss gradient w.r.t. output: ∂ℓ/∂a=2(a−y)=2(0.269−1)=−1.462\partial \ell / \partial a = 2(a - y) = 2(0.269 - 1) = -1.462.

Step 2 — Error signal: δ=∂ℓ∂a σ′(z)=(−1.462)(0.197)=−0.288\delta = \dfrac{\partial \ell}{\partial a}\,\sigma'(z) = (-1.462)(0.197) = -0.288.

Step 3 — Weight gradients: ∂ℓ/∂w1=δ x1=−0.288(1)=−0.288\partial\ell/\partial w_1 = \delta\,x_1 = -0.288(1) = -0.288; ∂ℓ/∂w2=δ x2=−0.288(2)=−0.576\partial\ell/\partial w_2 = \delta\,x_2 = -0.288(2) = -0.576; ∂ℓ/∂b=δ=−0.288\partial\ell/\partial b = \delta = -0.288.

Step 4 — Update [9]: w1←0.5−0.1(−0.288)=0.529w_1 \leftarrow 0.5 - 0.1(-0.288) = 0.529; w2←−1−0.1(−0.576)=−0.942w_2 \leftarrow -1 - 0.1(-0.576) = -0.942; b←0.5−0.1(−0.288)=0.529b \leftarrow 0.5 - 0.1(-0.288) = 0.529.

w→(0.529, −0.942),b→0.529 (moves output toward target 1)\boxed{\mathbf{w} \to (0.529,\,-0.942),\quad b \to 0.529\ \text{(moves output toward target 1)}}

Common Misconceptions

⚠️ Common mistake

"More layers always help." Naïvely stacking layers can worsen training due to vanishing/exploding gradients: by [7], δ\boldsymbol\delta is repeatedly multiplied by W⊤W^\top and σ′\sigma'. With sigmoids (σ′≤0.25\sigma' \le 0.25), the gradient shrinks geometrically with depth, so early layers barely learn. Remedies — ReLU activations, careful initialization (He/Xavier), batch normalization, and residual connections — were essential to make deep networks trainable. Depth without these tricks is often harder, not better.

⚠️ Common mistake

"Universal approximation means networks can learn anything from data." Theorem [5] is purely about existence of weights, not learnability. It guarantees nothing about (a) finding those weights by gradient descent, (b) how many samples are required, or (c) generalization to unseen inputs. Approximation, optimization, and generalization are three separate problems.

CounterexampleA single neuron cannot solve XOR

The XOR function maps (0,0)→0(0,0)\to 0, (0,1)→1(0,1)\to 1, (1,0)→1(1,0)\to 1, (1,1)→0(1,1)\to 0. A single neuron computes σ(w⊤x+b)\sigma(\mathbf{w}^\top\mathbf{x}+b), whose decision boundary w⊤x+b=0\mathbf{w}^\top\mathbf{x}+b = 0 is a single line. No line separates {(0,1),(1,0)}\{(0,1),(1,0)\} from {(0,0),(1,1)}\{(0,0),(1,1)\} — the positive and negative classes are interleaved at opposite corners. Resolution: one hidden layer of two neurons (e.g. computing OR and NAND) followed by an AND output neuron solves XOR exactly. This concrete failure of single-layer perceptrons, highlighted by Minsky–Papert (1969), motivated multilayer networks.

Connections

connection

Neural networks sit at the intersection of several fields. The training objective and update rule come from Gradient Descent and Convex Optimization (though the landscape is non-convex). Backpropagation is exactly reverse-mode Automatic Differentiation applied to a computational graph. The cross-entropy loss and softmax derive from Maximum Likelihood Estimation under a categorical model, linking to Probability Theory. The single-neuron model with sigmoid is precisely Logistic Regression, so a network generalizes a stack of regressions. Universal approximation rests on density arguments from Functional Analysis (Hahn–Banach, Stone–Weierstrass). The matrix operations in [2] are Linear Algebra, and convolutional variants connect to Fourier Analysis and signal processing.

Real-World Applications

🔬 Where this appears

Historical Development

⏳ History
- 1943 — McCulloch & Pitts publish a logical model of the neuron as a threshold unit, showing networks can compute logical functions.
- 1949 — Donald Hebb proposes Hebbian learning ("neurons that fire together wire together").
- 1958 — Rosenblatt introduces the Perceptron and proves its convergence theorem for linearly separable data.
- 1969 — Minsky & Papert's Perceptrons exposes the XOR limitation; funding and interest decline (first AI winter).
- 1974/1986 — Werbos (1974) and Rumelhart, Hinton & Williams (1986) popularize backpropagation for training multilayer networks.
- 1989 — Cybenko proves the Universal Approximation Theorem; LeCun applies convolutional networks to handwritten digits (LeNet).
- 1997 — Hochreiter & Schmidhuber introduce LSTM, solving long-range dependency learning in recurrent nets.
- 2012 — Krizhevsky, Sutskever & Hinton's AlexNet wins ImageNet by a wide margin on GPUs, igniting the deep-learning era.
- 2017 — Vaswani et al. introduce the Transformer ("Attention Is All You Need"), now the dominant architecture for language and beyond.

Subtleties & Limits

open-problem

Despite practical success, deep learning's theory has large gaps. Why does SGD generalize? Overparameterized networks with more parameters than data points can fit random labels yet still generalize on real data, defying classical bias-variance intuition (the "double descent" phenomenon). Why is non-convex optimization easy? The loss surface has exponentially many saddle points and local minima, yet SGD reliably finds good solutions — partial explanations invoke the geometry of overparameterized landscapes and the "lottery ticket" hypothesis. Expressivity vs. trainability: depth gives exponential expressive power, but provably learnable function classes remain narrow. Robustness and interpretability: networks are vulnerable to imperceptible adversarial perturbations and remain largely black boxes. Sample/energy efficiency: humans learn from far fewer examples and far less energy than current models. These questions span optimization theory, statistical learning theory, and approximation theory.

See Also

Backpropagation · Automatic Differentiation · Universal Approximation Theorem · Stochastic Gradient Descent · Activation Functions · Deep Learning · Support Vector Machines