From the free course Backpropagation on Lykke
Theoretical Derivations and Optimal Control
Key concepts: Kelley-Bryson gradient formula · Optimal control theory · Hidden-node teaching · Multilayer Perceptron (MLP)
An advanced look at backpropagation through the lens of optimal control theory and the Kelley-Bryson formula.
Theoretical Derivations and Optimal Control
The evolution of gradient-based learning is often presented as a modern triumph of computer science, yet its roots are deeply embedded in the soil of 1960s optimal control theory and variational calculus. This section explores the rigorous mathematical foundations of backpropagation, its temporal and structural extensions, and its identity as a specific case of discrete-time optimal control.
By framing neural network training through the lens of the Kelley-Bryson optimal-control gradient formula, we move beyond simple "error correction" and into the realm of trajectory optimization. This perspective is vital for engineering systems where the "output" is not merely a classification label, but a sequence of actions in a dynamic environment.
AI_SVGI_SVG## The Fundamental Mechanics of Backpropagation
At its core, Backpropagation is an efficient algorithm for calculating the gradient of a loss function with respect to the weights of a neural network. While often conflated with optimization algorithms like Stochastic Gradient Descent (SGD), backpropagation strictly refers to the computation of the gradient, not the update itself.
1. What it is: Reverse Mode Automatic Differentiation
Mathematically, backpropagation is a specific implementation of Reverse Mode Automatic Differentiation (AD). It leverages the Chain Rule of calculus to propagate the "blame" for the error from the output layer back to the input layer.
Definition: The Backpropagation Principle Given a composite function $L(f_n(...f_1(x)))$, the gradient $\nabla L$ is computed by caching intermediate derivatives during a forward pass and accumulating products in reverse order. This reduces the computational complexity from $O(N^2)$ (for naive finite differences) to $O(N)$, where $N$ is the number of parameters.
2. The Mathematical Derivation
Consider a feedforward network where $a^{(l)}$ is the activation of layer $l$, $w^{(l)}$ are the weights, and $\sigma$ is the activation function. The forward pass is defined as: $$z^{(l)} = w^{(l)} a^{(l-1)} + b^{(l)}$$ $$a^{(l)} = \sigma(z^{(l)})$$
To find the gradient of the loss $C$ with respect to a weight $w_{jk}^{(l)}$, we apply the chain rule: $$\frac{\partial C}{\partial w_{jk}^{(l)}} = \frac{\partial C}{\partial z_j^{(l)}} \frac{\partial z_j^{(l)}}{\partial w_{jk}^{(l)}}$$
We define the error term (or "sensitivity") of node $j$ in layer $l$ as: $$\delta_j^{(l)} = \frac{\partial C}{\partial z_j^{(l)}}$$
The recursive step that defines backpropagation is: $$\delta^{(l)} = ((w^{(l+1)})^T \delta^{(l+1)}) \odot \sigma'(z^{(l)})$$ where $\odot$ denotes the Hadamard (element-wise) product.
| Component | Symbol | Role in Derivation |
|---|---|---|
| Loss Function | $C$ or $L$ | The scalar value we aim to minimize. |
| Activation | $a^{(l)}$ | The output of a layer after the non-linearity. |
| Pre-activation | $z^{(l)}$ | The weighted sum before the non-linearity. |
| Sensitivity | $\delta^{(l)}$ | The partial derivative of loss w.r.t. the pre-activation. |
| Weight Gradient | $\nabla_w C$ | The final product used by the optimizer. |
3. Why it Matters: Dynamic Programming
Backpropagation is an application of Dynamic Programming. By storing the sensitivities $\delta^{(l)}$ at each layer, we avoid the redundant re-calculation of the chain rule for every single weight. In a deep network, a weight in the first layer contributes to the error through millions of paths; backpropagation collapses these paths into a single recursive calculation.
4. Implementation Example (Python/NumPy)
The following code demonstrates a non-trivial backward pass for a single dense layer, highlighting the matrix operations that mirror the theoretical derivation.
import numpy as np
def backward_pass(activations, weights, biases, z_values, target, loss_derivative_func):
"""
Performs a single backward pass for a multi-layer perceptron.
"""
layers = len(weights)
deltas = [None] * layers
grad_w = [None] * layers
grad_b = [None] * layers
# 1. Compute output error (delta for the last layer)
# delta^L = grad_a(C) * sigma'(z^L)
output_activation = activations[-1]
delta = loss_derivative_func(output_activation, target) * sigmoid_prime(z_values[-1])
deltas[-1] = delta
# 2. Backpropagate the error
for l in range(layers - 2, -1, -1):
# delta^l = (W^{l+1}.T @ delta^{l+1}) * sigma'(z^l)
delta = np.dot(weights[l+1].T, deltas[l+1]) * sigmoid_prime(z_values[l])
deltas[l] = delta
# 3. Compute gradients for weights and biases
for l in range(layers):
# grad_w = delta^l @ activation^{l-1}.T
grad_w[l] = np.dot(deltas[l], activations[l].T)
grad_b[l] = deltas[l]
return grad_w, grad_b
def sigmoid_prime(z):
"""Derivative of the sigmoid function."""
s = 1 / (1 + np.exp(-z))
return s * (1 - s)
Optimal Control and the Kelley-Bryson Formula
The connection between backpropagation and Optimal Control is found in the Adjoint State Method. In the 1960s, Henry J. Kelley and Arthur E. Bryson developed methods for optimizing the trajectories of rockets. Their work provided the exact mathematical framework that would later be recognized as backpropagation.
1. The Control Perspective
In optimal control, we seek a control sequence $u_t$ that minimizes a cost function $J$ subject to system dynamics $x_{t+1} = f(x_t, u_t)$. If we view a neural network as a discrete-time dynamical system:
- States ($x_t$): The activations of layer $t$.
- Controls ($u_t$): The weights of layer $t$.
- Dynamics ($f$): The layer transformation (linear sum + activation).
2. The Hamiltonian and Adjoint Variables
To solve this, we define the Hamiltonian: $$H_t = L(x_t, u_t) + \lambda_{t+1}^T f(x_t, u_t)$$ where $\lambda$ are the Lagrange Multipliers (or Adjoint Variables). The "Adjoint Equation" describes how these multipliers evolve: $$\lambda_t = \frac{\partial H_t}{\partial x_t} = \frac{\partial f^T}{\partial x_t} \lambda_{t+1} + \frac{\partial L}{\partial x_t}$$
This is precisely the backpropagation formula. The adjoint variables $\lambda$ are the sensitivities $\delta$ we use in machine learning.
| Control Theory Term | Neural Network Equivalent |
|---|---|
| Adjoint State ($\lambda$) | Error Sensitivity ($\delta$) |
| Plant Dynamics ($f$) | Layer Transformation |
| Control Input ($u$) | Network Weights ($w$) |
| Terminal Cost | Loss Function ($C$) |
| Hamiltonian ($H$) | Local Objective Function |
3. Why this matters: Hidden-Node Teaching
By treating the network as a control system, we can implement Hidden-Node Teaching. Instead of only providing a target at the final output, we can treat hidden layers as intermediate states with their own "desired" trajectories. This is used in Target Propagation and helps mitigate the vanishing gradient problem by providing local anchors for learning.
Backpropagation Through Time (BPTT)
When dealing with sequential data, such as speech or time-series, we use Recurrent Neural Networks (RNNs). Training these requires Backpropagation Through Time (BPTT).
1. What it is: Network Unfolding
BPTT works by "unfolding" the recurrent network into a deep feedforward network where each layer represents a time step. The key constraint is Shared Parameters: the same weight matrix $W$ is used at every time step.
2. The Mechanics of BPTT
In an unfolded RNN of $T$ steps, the total loss is the sum of losses at each time step: $L = \sum_{t=1}^T L_t$. The gradient with respect to the shared weights $W$ is the sum of the gradients at each time step: $$\frac{\partial L}{\partial W} = \sum_{t=1}^T \frac{\partial L_t}{\partial W}$$
Because the state $h_t$ depends on $h_{t-1}$, the gradient $\frac{\partial L_t}{\partial W}$ must be computed by backpropagating through all previous time steps: $$\frac{\partial L_t}{\partial W} = \sum_{k=1}^t \frac{\partial L_t}{\partial h_t} \frac{\partial h_t}{\partial h_k} \frac{\partial h_k}{\partial W}$$
3. Variations: Truncated BPTT
For very long sequences (e.g., thousands of words), standard BPTT is computationally expensive and prone to Vanishing/Exploding Gradients. Truncated BPTT processes the sequence in chunks. It performs a forward pass for $n$ steps, but only backpropagates for $k$ steps ($k \le n$).
| Method | Memory Complexity | Gradient Accuracy | Use Case |
|---|---|---|---|
| Full BPTT | $O(T)$ | Exact | Short sequences, high precision. |
| Truncated BPTT | $O(k)$ | Biased/Approximate | Long sequences (NLP, Audio). |
| Real-Time Recurrent Learning (RTRL) | $O(N^4)$ | Exact (Forward) | Online learning in small networks. |
4. Common Pitfalls: The Vanishing Gradient
In BPTT, the term $\frac{\partial h_t}{\partial h_k}$ involves a product of Jacobian matrices: $$\prod_{i=k+1}^t \frac{\partial h_i}{\partial h_{i-1}}$$ If the eigenvalues of the weight matrix are less than 1, the gradient shrinks exponentially as it travels back in time, effectively "forgetting" long-term dependencies. This led to the development of Gated Architectures like LSTM and GRU.
Backpropagation Through Structure (BPTS)
While BPTT handles linear sequences, Backpropagation Through Structure (BPTS) extends gradient-based learning to Recursive Neural Networks, which operate on tree-structured or graph-structured data.
1. What it is: Recursive Learning
BPTS is used when the input is a structure, such as a parse tree in linguistics or a molecular graph in chemistry. Instead of a fixed sequence of time steps, the "unfolding" follows the topology of the input structure.
2. How it Works
- Structural Forward Pass: The network processes nodes from the leaves up to the root. Each parent node activation is a function of its children: $h_{parent} = f(h_{child1}, h_{child2}, W)$.
- Structural Backward Pass: The gradient is propagated from the root down to the leaves. At each branching point, the error signal is split and sent to the children according to the weights of the recursive transformation.
3. Distributed Representations
BPTS was pioneered by Goller and Küchler (1996) to learn Task-Dependent Distributed Representations. By training on structures, the network learns to map complex symbolic trees into a continuous vector space where semantic similarity is represented by spatial proximity.
4. Comparison of Backpropagation Variants
| Feature | Standard Backprop | BPTT | BPTS |
|---|---|---|---|
| Topology | Fixed DAG (Layers) | Linear Chain (Time) | Tree/Graph (Structure) |
| Weight Sharing | No (usually) | Across time steps | Across recursive nodes |
| Primary Application | Image Classification | Speech, Translation | Logic, Chemistry, Parsing |
| Complexity | $O(Layers)$ | $O(Time)$ | $O(Nodes)$ |
Theoretical Challenges and Modern Perspectives
1. The Local Optima Myth
Early critiques of backpropagation focused on the risk of getting stuck in local optima. However, high-dimensional optimization research suggests that in large neural networks, local minima are rarely the problem. Instead, saddle points (where the gradient is zero but the point is not a minimum) are the primary obstacle. Modern optimizers like Adam and RMSProp use momentum to "slide" past these saddle points.
2. Biological Plausibility
A major debate in theoretical neuroscience is whether the brain performs backpropagation. The "Weight Transport Problem" (the need for the backward pass to know the exact weights of the forward pass) makes standard BP biologically unlikely. This has led to theories like Feedback Alignment, where random backward weights can still provide useful gradient signals.
3. Second-Order Methods
While backpropagation provides the first derivative (Jacobian), some researchers use Hessian-Free Optimization or K-FAC (Kronecker-factored Approximate Curvature) to incorporate second-order information. These methods can converge in fewer iterations but require significantly more computation per step.
Key Insight: The Duality of Learning Backpropagation is not just an algorithm; it is a bridge. It connects the discrete world of symbolic logic (through BPTS) and the continuous world of physical dynamics (through Optimal Control). Every time we train a model, we are essentially solving a high-dimensional trajectory optimization problem.
AI_STUDY_GUIDEI_STUDY_GUIDE--
Appendix: Summary of Key Formulas
1. The Adjoint State Equation (Optimal Control): $$\lambda_t = \left( \frac{\partial f}{\partial x_t} \right)^T \lambda_{t+1} + \frac{\partial L}{\partial x_t}$$
2. The BPTT Gradient (RNN): $$\frac{\partial L}{\partial W} = \sum_{t=1}^T \sum_{k=1}^t \frac{\partial L_t}{\partial h_t} \left( \prod_{i=k+1}^t \frac{\partial h_i}{\partial h_{i-1}} \right) \frac{\partial h_k}{\partial W}$$
3. The BPTS Recursive Step: $$\delta_{child} = (W_{branch}^T \delta_{parent}) \odot \sigma'(z_{child})$$
This article is part of the DeepWiki series on Neural Computation and Control Theory. For further reading, see the sections on "Variational Calculus in Machine Learning" and "Gated Recurrent Units."
Source Materials
Study Backpropagation on Lykke
This course page is free to open: signed out, you can read its first two sections, and signing in, on any plan, opens the rest. The free Lykke Chrome extension syncs your own Canvas courses, so ChatGPT, Claude and Muse can answer from your classes and deadlines. It only reads Canvas.
Add the free extensionSign in to open every section