ML Methods
Feedforward Networks and Backpropagation
Feedforward neural networks as compositions of affine transforms and nonlinearities, the universal approximation theorem, and backpropagation as reverse-mode automatic differentiation on the computational graph.
Learning position
Read this page in the graph.
ml-methods | layer 2 | tier 1. This page has 11 direct prerequisites and 33 published dependents.
What next
Convolutional Neural NetworksThis is the first curated or graph-derived continuation from the current page.
Evidence badge
Source-grounded pageThis page has no public Lean mapping yet. Use the evidence page to inspect how claim status labels work.
Why This Matters
Feedforward networks are the foundation of modern deep learning. The history of deep learning traces back through multiple waves of enthusiasm and disillusionment, but every architecture -- convolutional networks, transformers, residual networks -- is built from the same primitive: layers of affine transformations followed by nonlinear activation functions. Understanding this primitive deeply -- what it can represent, how to train it, and what goes wrong -- is essential before studying any specialized architecture.
Backpropagation is the algorithm that makes training possible. It is not a learning algorithm itself -- it is an efficient method for computing gradients. Without backpropagation, training a network with parameters would require forward passes to compute the gradient (one per parameter). Backpropagation computes the full gradient in a single backward pass, making deep learning computationally feasible.
Mental Model
A feedforward network is a pipeline: input flows through a series of layers, each applying a linear transformation (matrix multiply + bias) followed by a nonlinearity (ReLU, sigmoid, tanh). The output of each layer is the input to the next. Training means adjusting the matrices and biases so that the final output matches the desired labels.
Backpropagation computes how much each weight contributed to the error by propagating the error signal backward through the network, using the chain rule at each layer. It is reverse-mode automatic differentiation applied to the computational graph of the network.
Feedforward Architecture
Feedforward Neural Network
An -layer feedforward neural network computes:
where are weight matrices, are bias vectors, and is a nonlinear activation function applied elementwise. The parameters are .
Layer by layer, the computation is:
where is the input and is the output (the final layer may omit the nonlinearity for regression, or use softmax for classification).
Width and Depth
The width of layer is (the number of neurons). The depth of the network is (the number of layers). A "deep" network has many layers; a "wide" network has many neurons per layer. Depth enables hierarchical feature composition; width enables representing more features at each level.
Universal Approximation
Universal Approximation Theorem
Statement
For any continuous function on a compact set and any , there exists a single-hidden-layer network such that:
That is, feedforward networks with one hidden layer are dense in the space of continuous functions on compact sets, in the supremum norm.
Intuition
A single hidden layer with enough neurons can approximate any continuous function to arbitrary accuracy. Each neuron carves out a half-space in input space. With enough half-spaces, you can build any shape. Think of it as approximation by a very flexible linear combination of basis functions.
Proof Sketch
The original proof by Cybenko (1989) for sigmoid activations uses the Hahn-Banach theorem and the Riesz representation theorem. The idea: suppose the set of functions representable by the network is not dense. Then by Hahn-Banach, there exists a nonzero bounded linear functional that vanishes on all such functions. This functional corresponds to a signed measure . Show that for all implies , giving a contradiction.
Why It Matters
Universal approximation tells you that neural networks are expressive enough -- the hypothesis class is rich enough to approximate any target. But it says absolutely nothing about:
- How to find the weights: the optimization landscape is non-convex
- How many neurons are needed: the width may need to be exponentially large in
- Whether the learned function generalizes: expressiveness is about approximation error, not estimation error
This is an existence theorem, not a constructive one. It guarantees the capacity is there but gives no guidance on learning.
Failure Mode
The theorem requires arbitrary width. For fixed-width networks, depth matters: there exist functions that require exponential width with bounded depth but only polynomial width with sufficient depth. This is the theoretical motivation for deep (many-layer) networks over wide shallow ones.
Backpropagation
Backpropagation computes the gradient of the loss with respect to all parameters. It is the chain rule applied systematically from output to input.
Forward pass: compute and store all pre-activations and post-activations for .
Backward pass: starting from the loss gradient , propagate backward:
where denotes elementwise multiplication and is the derivative of the activation at the pre-activation values.
The parameter gradients at layer are:
The lab above makes the recurrence visible. Each bar is the scale of the backward signal reaching one layer, measured relative to the output-side gradient. A balanced initialization keeps the bars near the same height. Small weights or sigmoid derivatives turn the leftmost bars into nearly zero: the early layers receive gradients too small to move their features. Large weights do the opposite: the bars grow as the signal moves backward, so an ordinary learning rate becomes a destabilizing update. The dead ReLU toggle shows a different failure: one zero derivative blocks every upstream path through that unit, even when the surrounding weight scale is reasonable.
Worked Mechanism: One Layer in Reverse
For a single dense layer, write the forward computation as
Suppose the rest of the network has already supplied the adjoint . The reverse pass through this layer has two local steps. First, pass through the activation:
Second, pass through the affine map:
The shapes are the sanity check. If , , and , then , matching . The input adjoint lands back in , matching the previous layer's activation. Most implementation bugs in hand-written backprop show up as a shape mismatch in one of these three equations.
For a minibatch with activations arranged as rows, and . If is the batch of activation adjoints, the weight gradient is
That formula explains the common "matrix multiply in reverse" pattern in deep learning kernels. The forward dense layer multiplies input activations by weights. The backward dense layer multiplies output adjoints by saved input activations. Training cost is high because every layer performs comparable matrix multiplications in both directions, not because the chain rule itself is conceptually hard.
The cache is not optional. To compute , the reverse pass needs the forward value . To compute for nonlinear activations, it usually needs either or . If those values are not stored, the system must recompute them exactly. Recomputing is valid only when the forward operation is deterministic under the same random seeds and masks. Dropout, data-dependent branches, mixed-precision rounding, and in-place mutation all make this harder than the blackboard recurrence suggests.
Mathematical backprop and optimizer behavior are different layers. Backprop returns and for the current loss and current parameters. It does not choose the learning rate, clip exploding gradients, average across minibatches, add momentum, or regularize the weights. Those choices belong to SGD, Adam, and the broader optimizer layer. Confusing the gradient subroutine with the update rule hides where training failures actually enter.
There are two common batch-level mistakes worth naming. First, the gradient of the average loss over a minibatch should average the per-example adjoints. If the loss is
then every parameter gradient carries the same factor . Omitting the factor silently changes the learning-rate scale when the batch size changes. This is why moving from batch size 32 to 256 can destabilize a handwritten training loop even when the symbolic derivative is otherwise correct: the update became 8 times larger because the gradient was summed rather than averaged.
Second, broadcasting bias terms must be reversed by summing over the batch axis. In the forward pass, is copied into every row of . In the backward pass, those copies collapse:
A bias gradient with shape is not a valid parameter gradient; it is the set of per-example contributions before reduction. Autodiff libraries handle this reduction automatically, but the rule matters when reading kernel code or debugging a custom operation.
The same local reasoning explains why residual connections improve trainability. For a residual block , the input adjoint is
Even if the learned branch has small or poorly conditioned Jacobian, the identity path sends directly backward. Residual networks do not avoid backprop; they change the Jacobian product so a clean signal path remains available across many layers.
Layer normalization and careful initialization serve the same goal from a different angle. They do not alter the chain rule, but they keep the local Jacobians in a range where the product across layers is less likely to vanish or explode. This is why a modern transformer block combines residual paths, normalization, and initialization rules rather than relying on backprop alone. The gradient algorithm is general; trainable architecture is the extra design work that keeps its output numerically useful.
Backpropagation Complexity
Statement
For a feedforward network with total parameters, backpropagation computes the full gradient in time -- the same order as a single forward pass. Computing each partial derivative individually by finite differences would require forward passes, giving total time.
Intuition
The key insight is that backpropagation reuses intermediate computations. The error signal at layer is computed from by a single matrix-vector multiply. Each layer adds work -- the same as the forward pass through that layer. Since the forward pass is (summing over all layer sizes), the backward pass is also .
This is not a coincidence. Backpropagation is reverse-mode automatic differentiation: it computes all partial derivatives simultaneously by traversing the computational graph once in reverse.
Proof Sketch
The forward pass through layer computes (cost ) and (cost ). Total forward cost: .
The backward pass at layer computes (cost ) and (cost ). Total backward cost: .
Why It Matters
This linear-time complexity is what makes deep learning possible. A modern language model has billions of parameters. Computing the gradient in rather than is the difference between training in weeks and never training at all.
Failure Mode
Backpropagation requires storing all intermediate activations for the backward pass. This is the memory bottleneck of training: memory scales linearly with depth and batch size. Gradient checkpointing trades computation for memory by recomputing activations during the backward pass instead of storing them.
There is also a graph-structure failure mode. The claim assumes the forward pass stores exactly the local values needed by each reverse step. If the implementation discards activations, mutates them in place before their adjoint is used, or builds a dynamic graph whose branches are not replayed consistently, the backward pass either recomputes work or returns the wrong gradient. Modern autodiff systems spend much of their engineering budget on this bookkeeping: saved tensors, version counters, checkpoint boundaries, and deterministic replay for stochastic layers.
Backprop does not guarantee useful gradients
Backprop exactly computes the gradient of the objective represented by the current computation graph, up to numerical precision. That does not mean the gradient is useful. It may be nearly zero in early layers, too large to step with the chosen learning rate, dominated by minibatch noise, or pointed toward a sharp region that generalizes poorly. The theorem is an efficiency theorem for gradient computation; it is not a convergence theorem and not a generalization theorem.
Backprop reuses adjoints instead of recomputing paths
Take the scalar chain
A finite-difference estimate of perturbs , runs the full forward pass, then repeats for . With two weights that cost is tolerable; with two billion weights it is not.
Backprop computes one output adjoint and reuses it:
The same reverse sweep produces gradients for , , and the input. No parameter gets its own forward pass. The stored forward values and are the only extra data needed for this chain.
Vanishing and Exploding Gradients
The backward recurrence multiplies by at each layer. Over layers:
- If at most layers, the product shrinks exponentially: vanishing gradients. Early layers learn extremely slowly.
- If at most layers, the product grows exponentially: exploding gradients. Training becomes unstable.
Signal scale across 16 sigmoid layers
Suppose each weight matrix has spectral norm near 1 and every sigmoid unit is near its highest derivative, so . Even in this best local regime for sigmoid, a 16-layer network sends at most
of the output-side gradient to the first layer. If the output loss supplies a gradient of order 1, the first layer sees an update of order . With learning rate , that is an update near before accounting for matrix norms and minibatch noise. The first layer is mathematically trainable, but numerically it barely changes.
This is why the vanishing-gradient issue is not just a vague warning about "deep networks." It is a product of the actual chain-rule factors. Change the activation derivative, the singular values of the weight matrices, or the normalization scheme, and the product changes.
A ReLU gate can kill an upstream feature
For ReLU, the derivative is 1 on positive pre-activations and 0 on negative pre-activations. Consider one hidden unit with on a minibatch. Its activation is , and its local derivative is also 0. The backward term becomes
Every parameter feeding that unit receives zero gradient on that minibatch: and . If the bias and weights keep the unit negative across most data, the unit becomes dead. ReLU fixes the sigmoid saturation problem on active paths, but it creates a gate-level counterexample to the idea that gradients always flow backward through a network.
Activation Functions
ReLU
The Rectified Linear Unit is . Its derivative is for and for . ReLU does not saturate for positive inputs, which mitigates vanishing gradients. However, neurons with have zero gradient ("dying ReLU").
Sigmoid: , with . The maximum derivative is 0.25, so gradients shrink by at least a factor of 4 per layer. This causes severe vanishing gradients in deep networks.
Tanh: , with . Better than sigmoid (centered at zero, larger maximum derivative) but still saturates for large .
ReLU is the default activation for hidden layers in modern networks because it avoids the saturation problem entirely for positive inputs.
Weight Initialization
Proper initialization ensures that the variance of activations and gradients remains roughly constant across layers at the start of training.
Xavier (Glorot) Initialization
For a layer with inputs and outputs, Xavier initialization sets:
This is derived by requiring for linear activations (). It works well with tanh and sigmoid activations.
He Initialization
For layers using ReLU, He initialization sets:
The factor of 2 accounts for the fact that ReLU zeros out half of the activations (those with ), which halves the variance. Without this correction, activations shrink toward zero in deeper layers.
Canonical Examples
Two-layer network for XOR
The XOR function on is not linearly separable. A two-layer ReLU network with 2 hidden neurons realizes it exactly (Goodfellow, Bengio, Courville 2016, §6.1):
- Hidden layer: ,
- Output:
Verify on all four inputs: ; ; ; . The hidden layer folds the input space so the two "XOR " corners collapse onto the same half-line and the output becomes linearly separable. This folding is the defining power of neural networks: learning nonlinear intermediate representations from data.
One MSE backprop step on the XOR network with numbers
Take the same 2-2-1 architecture as the XOR example above, but with weights slightly off the closed-form solution so the gradient is nonzero. Use ReLU hidden units and a linear output, mean-squared error loss , learning rate , and the single training point .
Initial parameters. , , , .
Forward pass.
- Hidden pre-activations: , .
- Hidden activations: , .
- Output: .
- Loss: .
Backward pass. With output linear and loss MSE, . Walk the chain:
- Output layer: ; .
- Backprop into hidden activations: .
- Through ReLU: . The dead unit kills its half of the gradient.
- Hidden layer: ; .
Parameter update. ; ; ; . All other parameters unchanged on this step (their gradients were zero, mostly because blocked the second hidden unit's path).
Re-forward to confirm the loss dropped. Recompute on the same input: , , . New loss , down from . One full gradient step halved the loss on this example.
The intermediate cache is what backprop stores during forward to reuse during backward — exactly the pattern from the chain-rule worked example. Goodfellow, Bengio, Courville, Deep Learning (2016), §6.5 has the general algorithm; this example is the smallest setting where every term is computable by hand.
Vanishing gradient with sigmoid
Consider a 10-layer network with sigmoid activations. At each layer, the gradient is multiplied by . After 10 layers, the gradient at the first layer is at most times the gradient at the output. With ReLU and proper initialization, the gradient passes through unchanged (for active neurons), preserving the learning signal across all layers.
Common Confusions
Universal approximation does not mean easy to train
The universal approximation theorem is an existence result: a wide enough network can approximate any function. But finding the right weights via gradient descent on a non-convex loss landscape is a completely separate problem. The loss may have many local minima, saddle points, and flat regions. In practice, overparameterized networks are easier to optimize (the loss landscape becomes more benign), but this is an empirical observation, not a consequence of the approximation theorem.
Backpropagation is not a learning algorithm
Backpropagation computes gradients. That is all it does. The learning algorithm is gradient descent (or Adam, or SGD with momentum, etc.), which uses the gradients that backpropagation provides. Saying "we train with backpropagation" is technically imprecise -- you train with gradient descent, and backpropagation is the subroutine that makes gradient computation efficient.
Deep networks are not just wide networks stacked
Adding depth is qualitatively different from adding width. Depth enables compositional representations: early layers learn simple features, later layers compose them into complex features. Width at a single layer enables representing more features at one level of abstraction. There are functions (like parity) that require exponential width with bounded depth but only polynomial size with sufficient depth.
Summary
- A feedforward network is a composition of affine transforms + nonlinearities
- Universal approximation: one hidden layer suffices for approximation, but says nothing about learning or generalization
- Backpropagation = reverse-mode autodiff = chain rule applied backward through the computational graph
- Backprop computes the full gradient in time, same as a forward pass
- Vanishing gradients: sigmoid/tanh derivatives shrink the gradient exponentially with depth
- ReLU avoids saturation for positive inputs; it is the default activation
- Xavier initialization preserves variance for linear/tanh; He initialization corrects for ReLU zeroing half the activations
Exercises
Problem
Consider a 3-layer network with input , hidden layer sizes , and scalar output. How many parameters (weights and biases) does this network have?
Problem
Derive the backpropagation recurrence. Starting from the loss and the layer equations , , show that:
Problem
The universal approximation theorem guarantees a single hidden layer suffices for approximation. Why, then, do we use deep networks? Give a concrete example of a function family where depth gives an exponential advantage over width.
References
Canonical:
- Linnainmaa, "The representation of the cumulative rounding error of an algorithm as a Taylor expansion of the local rounding errors" (1970) -- reverse-mode AD
- Werbos, "Beyond Regression: New Tools for Prediction and Analysis in the Behavioral Sciences" (PhD thesis, Harvard 1974) -- backprop applied to neural networks
- Rumelhart, Hinton, Williams, "Learning Representations by Back-Propagating Errors" (Nature 1986) -- backprop popularization
- Cybenko, "Approximation by Superpositions of a Sigmoidal Function" (Math. Control Signals Systems 1989) -- universal approximation for sigmoid
- Hornik, Stinchcombe, White, "Multilayer Feedforward Networks are Universal Approximators" (Neural Networks 1989) -- general version
- Hornik, "Approximation Capabilities of Multilayer Feedforward Networks" (Neural Networks 1991) -- extension to unbounded activations
- Leshno, Lin, Pinkus, Schocken, "Multilayer Feedforward Networks with a Nonpolynomial Activation Function Can Approximate Any Function" (Neural Networks 1993) -- sharpest classical result
- Barron, "Universal Approximation Bounds for Superpositions of a Sigmoidal Function" (IEEE TIT 1993) -- quantitative rate
- Glorot, Bengio, "Understanding the Difficulty of Training Deep Feedforward Neural Networks" (AISTATS 2010) -- Xavier initialization
Current:
- He, Zhang, Ren, Sun, "Delving Deep into Rectifiers" (ICCV 2015) -- He initialization
- Goodfellow, Bengio, Courville, Deep Learning (2016), Chapters 6-8 -- feedforward networks and autodiff
- Baydin, Pearlmutter, Radul, Siskind, "Automatic Differentiation in Machine Learning: a Survey" (JMLR 2018) -- forward-mode vs reverse-mode AD
Next Topics
Building on feedforward fundamentals:
- Convolutional neural networks: exploiting spatial structure with weight sharing
- Recurrent neural networks: extending feedforward networks to sequences
- Batch normalization: stabilizing training by normalizing intermediate activations
Last reviewed: June 25, 2026
Canonical graph
Required before and derived from this topic
These links come from prerequisite edges in the curriculum graph. Editorial suggestions are shown here only when the target page also cites this page as a prerequisite.
Required prerequisites
11- Differentiation in Rⁿlayer 0A · tier 1
- Tensors and Tensor Operationslayer 0A · tier 1
- Vector Calculus Chain Rulelayer 0A · tier 1
- Deep Learning (Goodfellow, Bengio, Courville)layer 0B · tier 1
- Activation Functionslayer 1 · tier 1
Derived topics
33- Batch Normalizationlayer 2 · tier 1
- Dropoutlayer 2 · tier 1
- Gradient Flow and Vanishing Gradientslayer 2 · tier 1
- Linear Layer: Shapes, Bias, and Memorylayer 2 · tier 1
- Skip Connections and ResNetslayer 2 · tier 1
+28 more on the derived-topics page.
Graph-backed continuations