Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

15. Optimization & Machine Learning: Advanced Topics

CNRS & DMA, École Normale Supérieure

Chapter PDF · Complete book

Reliable and efficient learning requires control of model complexity, economical use of large datasets, and accurate derivative calculations. We study regularization through ridge regression and sparsity, followed by stochastic gradient methods that reduce the cost of individual updates. The final section derives automatic differentiation on computational graphs and applies it to feedforward networks, recurrent models, and optimization procedures.

15.1 Regularization

When the sample size nn is small relative to the model dimension pp, regularization helps control the complexity of empirical risk minimization.

15.1.1 Penalized Least Squares

For simplicity, consider regularized least-squares regression:

minxRp  fλ(x):=12 ⁣Axy ⁣2+λR(x)(15.1)\underset{x \in \mathbb{R}^p}{\min}\; f_\lambda(x) \mathrel{:=}\frac{1}{2}|\!| Ax-y |\!|^2 + \lambda R(x) \tag{15.1}

where R(x)R(x) is the regularizer and λ0\lambda\geqslant 0 the regularization parameter.

The regularizer expresses prior structure of the weight vector xx, such as small magnitude or sparsity. The strength λ\lambda can be selected by cross-validation.

We assume that RR is finite, nonnegative, lower semicontinuous, and coercive, i.e. R(x)+R(x) \rightarrow +\infty as  ⁣x ⁣+|\!| x |\!| \rightarrow +\infty.

The following proposition shows that as λ0\lambda\downarrow0, regularization selects among the exact solutions when Ax=yAx=y is feasible. This is particularly useful when ker(A){0}\ker(A)\neq\{0\} and there are infinitely many exact solutions.

15.1.2 Ridge Regression

Ridge regression uses the quadratic penalty R(x)=12 ⁣x ⁣Rp2R(x)=\frac12|\!| x |\!|_{\mathbb{R}^p}^2. For λ>0\lambda>0, the objective in (15.1) has a unique minimizer:

xλ:=argminxRp  fλ(x)=12 ⁣Axy ⁣Rn2+λ2 ⁣x ⁣Rp2.x_\lambda\mathrel{:=}\underset{x \in \mathbb{R}^p}{\mathop{\mathrm{argmin}}}\; f_\lambda(x) = \frac{1}{2} |\!| Ax-y |\!|^2_{\mathbb{R}^n} +\frac\lambda 2|\!| x |\!|_{\mathbb{R}^p}^2.

One has

fλ(x)=A(Axy)+λx,fλ(xλ)=0\nabla f_\lambda(x)=A^\top(Ax-y)+\lambda x,\qquad\nabla f_\lambda(x_\lambda)=0

Thus xλx_\lambda depends linearly on yy and can be computed by solving a linear system. Two equivalent expressions are available.

The systems can be solved directly, for example by Cholesky factorization, or iteratively, for example by conjugate gradients. The latter exploits the quadratic structure more effectively than ordinary gradient descent.

For n>pn>p, use the smaller system (15.4); for n<pn<p, use (15.5).

Pseudo-inverse.

As λ0\lambda\downarrow0, xλx_\lambda converges to the minimum-norm least-squares solution A+yA^+y. If Ax=yAx=y is feasible, this is, by (15.2)

argminAx=y   ⁣x ⁣.\underset{Ax=y}{\mathop{\mathrm{argmin}}}\;|\!| x |\!| .

If AA has full column rank, so ker(A)={0}\ker(A)=\{0\} and npn\geqslant p, AARp×pA^\top A \in \mathbb{R}^{p \times p} is an invertible matrix, and (AA+λIdp)1(AA)1(A^\top A + \lambda\mathrm{Id}_p)^{-1} \rightarrow (A^\top A)^{-1}, so that

x0=A+ywhereA+:=(AA)1A.x_0 = A^+ y \quad \text{where} \quad A^+ \mathrel{:=}(A^\top A)^{-1}A^\top .

If AA has full row rank, so ker(A)={0}\ker(A^\top)=\{0\} and npn\leqslant p, the alternative formula is

x0=A+ywhereA+:=A(AA)1.x_0 = A^+ y \quad \text{where} \quad A^+ \mathrel{:=}A^\top (AA^\top)^{-1}.

When n=pn=p and AA is invertible, both formulas reduce to A+=A1A^+=A^{-1}. For any rank, the singular value decomposition (SVD) gives the Moore–Penrose pseudoinverse by inverting the nonzero singular values and leaving the zero ones unchanged.

Figure 15.1. q\ell ^q balls {x  ;  kxkq1}\left\{ x \;;\; \sum _k |x_k|^q \leqslant 1 \right\} for varying qq.

15.1.3 Lasso

The Lasso uses an 1\ell^1 penalty:

R(x)= ⁣x ⁣1:=k=1pxk.R(x) = |\!| x |\!|_1 \mathrel{:=}\sum_{k=1}^p |x_k|.

The penalty promotes sparsity in the solutions xλx_\lambda of

xλargminxRp  fλ(x)=12 ⁣Axy ⁣Rn2+λ ⁣x ⁣1x_\lambda\in \underset{x \in \mathbb{R}^p}{\mathop{\mathrm{argmin}}}\; f_\lambda(x) = \frac{1}{2} |\!| Ax-y |\!|^2_{\mathbb{R}^n} + \lambda|\!| x |\!|_1

The solutions xλx_\lambda may be nonunique, and typically have many zero coefficients.

Figure 15.1 illustrates the geometry of q\ell^q balls. They concentrate around the coordinate axes as q0q \rightarrow 0, favoring sparse solutions, but become nonconvex for q<1q<1.

Sparsity can encode a prior on the unknown, as in imaging, or select a small subset of predictive features. Feature selection can make a model easier to interpret and cheaper to evaluate.

Whether Lasso or ridge regression performs better depends on sparsity, correlations, noise, and the prediction task.

The objective fλf_\lambda is convex, but the 1\ell^1 penalty is nonsmooth, so ordinary gradient descent does not apply at all points.

Section 15.1.4 develops an appropriate modification of gradient descent.

A closed-form solution xλx_\lambda is generally unavailable, but the case of an orthogonal design matrix AA reduces to coordinatewise thresholding.

Figure 15.2. Effect of λ\lambda on the penalized scalar objective F(x):=12(xy)2+λxF(x)\mathrel{:=}\frac12(x-y)^2+\lambda|x|.

Figure 15.2. Effect of λ\lambda on the penalized scalar objective F(x):=12(xy)2+λxF(x)\mathrel{:=}\frac12(x-y)^2+\lambda|x|.

The nonlinear map SλS_\lambda is soft thresholding.

15.1.4 Iterative Soft Thresholding

We derive an iterative algorithm by minimizing a quadratic surrogate.

We aim at minimizing

f(x):=12 ⁣yAx ⁣2+λ ⁣x ⁣1f(x) \mathrel{:=}\frac{1}{2} |\!| y-Ax |\!|^2 + \lambda|\!| x |\!|_1

For a fixed reference point xx', introduce the surrogate with parameter τ>0\tau>0:

fτ(x,x):=f(x)12 ⁣AxAx ⁣2+12τ ⁣xx ⁣2.f_\tau(x,x') \mathrel{:=}f(x) - \frac{1}{2}|\!| Ax-Ax' |\!|^2 + \frac{1}{2\tau}|\!| x-x' |\!|^2.

The surrogate touches the objective, fτ(x,x)=f(x)f_\tau(x,x)=f(x). Its additional quadratic term is

K(x,x):=12 ⁣AxAx ⁣2+12τ ⁣xx ⁣2=12(1τIdpAA)(xx),xx.K(x,x') \mathrel{:=}- \frac{1}{2}|\!| Ax-Ax' |\!|^2 + \frac{1}{2\tau}|\!| x-x' |\!|^2= \frac{1}{2}\langle \left( \frac{1}{\tau}\mathrm{Id}_p-A^\top A \right) (x-x') ,\,x-x'\rangle.

The term K(x,x)K(x,x') is nonnegative when λmax(AA)1/τ\lambda_{\max}(A^\top A) \leqslant 1/\tau, equivalently τ1/ ⁣A ⁣op2\tau \leqslant 1/|\!| A |\!|_{\text{op}}^2, where  ⁣A ⁣op=σmax(A)|\!| A |\!|_{\text{op}} = \sigma_{\max}(A) is the operator norm.

Thus fτ(x,x)f_\tau(x,x') is a valid surrogate:

f(x)fτ(x,x),fτ(x,x)=f(x),andf()fτ(,x) is smooth.f(x) \leqslant f_\tau(x,x'), \quad f_\tau(x,x)=f(x), \quad \text{and} \quad f(\cdot)-f_\tau(\cdot,x') \text{ is smooth.}

The surrogate is strongly convex in its first argument, so its minimizer is unique.

Define the iteration

xk+1:=argminx  fτ(x,xk)(15.6)x_{k+1} \mathrel{:=}\underset{x}{\mathop{\mathrm{argmin}}}\; f_{\tau}(x,x_k) \tag{15.6}

which ensures by construction that

f(xk+1)f(xk).f(x_{k+1}) \leqslant f(x_k).

Equation (15.7) defines iterative soft thresholding. For A0A\neq0, the surrogate argument applies when 0<τ1/ ⁣A ⁣op20<\tau\leqslant 1/|\!| A |\!|_{\mathrm{op}}^2. Convergence to a Lasso solution holds for a fixed step in the larger range 0<τ<2/ ⁣A ⁣op20<\tau<2/|\!| A |\!|_{\mathrm{op}}^2. If A=0A=0, every positive step is admissible.

15.2 Stochastic Optimization

We study stochastic gradient methods for large datasets of size nn and for objectives defined as expectations.

15.2.1 Minimizing Sums and Expectations

Many learning objectives are finite averages:

minxRp  f(x):=1ni=1nfi(x)(15.8)\underset{x \in \mathbb{R}^p}{\min}\; f(x) \mathrel{:=}\frac{1}{n} \sum_{i=1}^n f_i(x) \tag{15.8}

or expectations:

minxRp  f(x):=Ezπ(f(x,z))=Zf(x,z)dπ(z).(15.9)\underset{x \in \mathbb{R}^p}{\min}\; f(x) \mathrel{:=}\mathbb{E}_{\mathbf{z}\sim \pi}( f(x,\mathbf{z}) ) = \int_{\mathcal{Z}} f(x,z) \mathrm{d}\pi(z). \tag{15.9}

A finite average is an expectation under the uniform measure π=1ni=1nδi\pi=\frac1n\sum_{i=1}^n\delta_i, with f(x,i)=fi(x)f(x,i)=f_i(x). Conversely, drawing (zi)i(z_i)_i i.i.d. from π\pi and setting fi(x)=f(x,zi)f_i(x)=f(x,z_i) gives an empirical approximation of (15.9). Under integrability, the empirical objective converges pointwise by the law of large numbers. Convergence of minima or minimizers requires additional assumptions.

For example, empirical risk minimization with linear predictors uses

fi(x)=(ai,x,yi)andf(x,z)=(a,x,y)(15.10)f_i(x) = \ell(\langle a_i,\,x\rangle,y_i) \quad \text{and} \quad f(x,z) = \ell(\langle a,\,x\rangle,y) \tag{15.10}

for z=(a,y)Z=(A=Rp)×Yz=(a,y) \in \mathcal{Z}= (\mathcal{A}=\mathbb{R}^p) \times \mathcal{Y} (typically Y=R\mathcal{Y}=\mathbb{R} or Y={1,+1}\mathcal{Y}=\{-1,+1\} for regression and classification), where \ell is some loss function.

We illustrate the methods with binary logistic classification, using

L(s,y):=log(1+exp(sy)).(15.11)L(s,y) \mathrel{:=}\log( 1+\exp(-sy) ). \tag{15.11}

The same computational approach extends to general parametric models, including deep neural networks.

The stochastic methods below apply both to finite sums (15.8) and to expectations (15.9), under the corresponding unbiasedness and moment assumptions. We present them for finite sums. When nn is large, the aim is to make each iteration inexpensive without evaluating every summand.

When the summands fi(x)f_i(x) are similar, a single gradient can approximate the average well: fif\nabla f_i \approx \nabla f. Evaluating fi\nabla f_i is typically nn times cheaper than forming the full gradient.

Stochastic optimization is nevertheless not always faster than batch gradient descent.

For moderate nn, a deterministic method may use the available computation more effectively.

When nn is too large for a full pass to be practical, stochastic methods divide the work into small updates and begin improving the model immediately. Mini-batches also permit parallel computation.

15.2.2 Batch Gradient Descent (BGD)

Batch gradient descent (BGD), analyzed in Section 14.4, iterates

xk+1=xkτkf(xk)x_{k+1} = x_k - \tau_k \nabla f(x_k)

For a convex objective with an LL-Lipschitz gradient and a minimizer, the condition 0<τminτkτmax<2/L0<\tau_{\min}\leqslant\tau_k\leqslant\tau_{\max}<2/L ensures convergence. Strong convexity strengthens this to a linear rate.

For a finite-sum objective, the gradient is

f(x)=1ni=1nfi(x)(15.12)\nabla f(x) = \frac{1}{n} \sum_{i=1}^n \nabla f_i(x) \tag{15.12}

Its cost is typically O(np)O(np) when each fi\nabla f_i can be evaluated in time linear in pp.

For an ERM summand of the form (15.10), Taylor expansion gives

fi(x+ε)=(ai,x+ai,ε,yi)=(ai,x,yi)+(ai,x,yi)ai,ε+o( ⁣ε ⁣)=fi(x)+(ai,x,yi)ai,ε+o( ⁣ε ⁣),\begin{aligned} f_i(x+\varepsilon) &= \ell(\langle a_i,\,x\rangle + \langle a_i,\,\varepsilon\rangle,y_i) = \ell(\langle a_i,\,x\rangle,y_i) + \ell'(\langle a_i,\,x\rangle,y_i)\langle a_i,\,\varepsilon\rangle + o(|\!| \varepsilon |\!|) \\ &= f_i(x) + \langle \ell'(\langle a_i,\,x\rangle,y_i)a_i,\,\varepsilon\rangle + o(|\!| \varepsilon |\!|), \end{aligned}

Here (s,y)\ell'(s,y) denotes differentiation with respect to the score ss, with the response yy fixed. Consequently,

fi(x)=(ai,x,yi)ai.(15.13)\nabla f_i(x) = \ell'( \langle a_i,\,x\rangle,y_i ) a_i. \tag{15.13}

For the logistic loss, one has

L(s,y)=yesy1+esy.L'(s,y)=-y \frac{e^{-sy}}{ 1+e^{-sy} }.

Figure 15.3. Objective-error evolution for batch gradient descent in logistic classification.

15.2.3 Stochastic Gradient Descent (SGD)

Figure 15.4. Unbiased stochastic gradient estimate (panel 1) and a schematic SGD trajectory (panel 2).

For very large nn, computing the full gradient f\nabla f as in (15.12) is prohibitive.

SGD replaces the full gradient by the gradient of one summand fif_{i}, with ii sampled uniformly. This gives an unbiased estimate:

Eifi(x)=f(x)(15.14)\mathbb{E}_{\mathbf{i}}{ \nabla f_{\mathbf{i}}(x) } = \nabla f(x) \tag{15.14}

where i\mathbf{i} is a random variable distributed uniformly in {1,,n}\{1,\ldots,n\}.

Starting from x0x_0, stochastic gradient descent (SGD) iterates

xk+1=xkτkfi(k)(xk)x_{k+1} = x_k - \tau_k \nabla f_{i(k)}(x_k)

where, for each iteration index kk, i(k)i(k) is drawn independently of previous draws, uniformly from {1,,n}\{1,\ldots,n\}.

The iterates xk+1x_{k+1} are random. We therefore study convergence to a minimizer of ff in a probabilistic sense, such as mean square or probability, together with the corresponding rates.

A batch-gradient step costs O(np)O(np), whereas an SGD step costs O(p)O(p). This makes SGD attractive when nn is large and repeated passes through the data are costly. Redundancy between observations can sometimes yield accurate predictions after only knk \ll n updates, before all observations have been used.

The step-size schedule τk\tau_k must balance two requirements: it usually needs to decrease to suppress stochastic noise, but not so quickly that the method stops making progress before reaching a minimizer.

A common schedule has asymptotic behavior τkk1\tau_k \sim k^{-1} as k+k\rightarrow +\infty. One such schedule is

τk:=τ01+k/k0(15.15)\tau_k \mathrel{:=}\frac{\tau_0}{1 + k/k_0} \tag{15.15}

where τ0>0\tau_0>0 sets the initial step and k0>0k_0>0 controls how long the steps remain approximately constant.

Figure 15.5 illustrates minimization of f1(x)+f2(x)f_1(x)+f_2(x) for xRx \in \mathbb{R}, with f1(x)=(x1)2f_1(x)=(x-1)^2 and f2(x)=(x+1)2f_2(x)=(x+1)^2. The distribution of xkx_k concentrates around the minimizer x=0x^\star=0. The initial iterate x0x_0 is uniform on [1/2,1/2][-1/2,1/2].

Figure 15.5. Repeated SGD runs for kxkRk\mapsto x_k\in\mathbb{R}. Left: the distribution of iterates at each iteration. Right: individual trajectories.

The following theorem gives a mean-square convergence rate. The second-moment assumption is imposed along the iterates, not uniformly on all of Rp\mathbb{R}^p: a globally strongly convex function cannot have a globally bounded gradient.

The preceding SGD bound, and the averaging scheme below, give sublinear rates even when ff is strongly convex. By contrast, batch gradient descent has a linear rate under the assumptions of Theorem 14.16.

Figure 15.6 compares the objective values f(xk)f(x_k). The black dashed curve shows batch gradient descent, with the iteration axis rescaled to reflect the nn-fold cost of a batch update.

Figure 15.6. Objective-error evolution for SGD in logistic classification; the dashed curve shows batch gradient descent.

15.2.4 Stochastic Gradient Descent with Averaging (SGA)

Diminishing steps can slow SGD as τk\tau_k approaches zero.

Averaging reduces fluctuations in the estimate. Run SGD on auxiliary iterates (x~k)k( \tilde x_k)_k,

x~k+1=x~kτkfi(k)(x~k)\tilde x_{k+1}=\tilde x_k - \tau_k \nabla f_{i(k)}(\tilde x_k)

and return their Cesàro average:

xk:=1k=1kx~.x_k \mathrel{:=}\frac{1}{k} \sum_{\ell=1}^k \tilde x_{\ell}.

This gives stochastic gradient descent with averaging (SGA), also called averaged SGD.

The average can be maintained without storing the full trajectory, using the recursive update

xk+1=1k+1x~k+1+kk+1xk.x_{k+1}=\frac{1}{k+1}\tilde x_{k+1}+\frac{k}{k+1}x_k.

A typical step-size schedule is

τk:=τ01+k/k0.\tau_k \mathrel{:=}\frac{\tau_0}{1 + \sqrt{k/k_0}}.

These steps decrease more slowly, at rate k1/2k^{-1/2}.

Averaging can reduce sensitivity to the tuning parameters (k0,τ0)(k_0,\tau_0), although their choice still affects performance.

Bach proves that for logistic classification, averaging can adapt to local curvature under suitable regularity and step-size assumptions. This is a problem-dependent result, rather than a universal improvement of every constant over SGD.

15.2.5 Stochastic Averaged Gradient Descent (SAG)

For a finite dataset with nn samples of total size n×pn \times p, one can trade additional memory for reduced gradient noise by storing past gradient evaluations. This yields the stochastic averaged gradient (SAG) method.

Store the latest gradient of each summand in a table (Gi)i=1n(G^i)_{i=1}^n, requiring O(np)O(np) memory. Maintain its average gg as an approximation to the full gradient.

Initialize Gi=0G^i=0 for all ii and g=0g=0, so that g=n1iGig=n^{-1}\sum_iG^i is the stored average. At each iteration, update the table and then xx:

xk+1=xkτgwhere{hfi(k)(xk),gg+1n(hGi(k)),Gi(k)h.x_{k+1} = x_k - \tau g \quad \text{where} \quad \left\{ \begin{array}{l} h\leftarrow\nabla f_{i(k)}(x_k), \\ g\leftarrow g+\frac 1n(h-G^{i(k)}), \\ G^{i(k)} \leftarrow h. \end{array} \right.

Because most entries were evaluated at earlier iterates, the table average is generally biased conditional on the current history. Its convergence analysis therefore differs from the unbiased-SGD proof above. SAG uses a fixed step size τ\tau. As for batch gradient descent, choose τ\tau on the scale of 1/L1/L, where LL bounds the Lipschitz constants of the individual gradients fi\nabla f_i; the admissible numerical constant depends on the convergence theorem.

For smooth convex finite sums with a minimizer and a suitable step size, SAG admits an O(1/k)O(1/k) expected objective bound for averaged iterates. Furthermore, in the presence of strong convexity (for instance after adding a positive quadratic penalty to logistic regression), it has a linear convergence rate, i.e.

E(f(xk))f(x)=O(ρk),\mathbb{E}( f(x_k) ) - f(x^\star) = O\left( \rho^k \right),

for some 0<ρ<10 < \rho < 1.

These improvements exploit the finite-sum structure: SAG stores information about each of the nn summands. SGD and averaged SGD also extend beyond finite nn to general expectations (15.9).

Figure 15.7 shows a comparison of SGD, SGA and SAG.

Figure 15.7. Objective gaps for SGD, averaged SGD (SGA), and SAG, displayed on logarithmic axes.

15.3 Automatic Differentiation

Gradient evaluation f(x)\nabla f(x) is the main operation in batch and stochastic gradient methods. For linear models and shallow networks, explicit formulas usually reduce it to matrix-vector products. For deeper or more elaborate computations, expanded derivative formulas become unwieldy and can duplicate work. Automatic differentiation organizes the chain rule recursively to reuse intermediate results.

15.3.1 Finite Differences and Symbolic Calculus

For f:RpRf : \mathbb{R}^p \rightarrow \mathbb{R}, we want to evaluate f:RpRp\nabla f : \mathbb{R}^p \mapsto \mathbb{R}^p. A finite-difference approximation with a small parameter ε>0\varepsilon>0 is

1ε(f(x+εδ1)f(x),,f(x+εδp)f(x))f(x)\frac{1}{\varepsilon}(f(x+\varepsilon\delta_1)-f(x), \ldots,f(x+\varepsilon\delta_p)-f(x))^\top \approx \nabla f(x)

This requires p+1p+1 evaluations of ff. Here δk=(0,,0,1,0,,0)\delta_k=(0,\ldots,0,1,0,\ldots,0) is the coordinate vector with its 1 at position kk.

For large pp, repeated evaluations are expensive. Finite differences also balance truncation error against floating-point cancellation as ε\varepsilon decreases. Reverse-mode automatic differentiation computes the full gradient at a cost typically proportional to one evaluation of ff.

Like symbolic differentiation, automatic differentiation applies exact derivative rules, subject to floating-point error. It organizes those rules around the operations of the program that evaluates the function, preserving reuse of intermediate computations.

15.3.2 Computational Graphs

Let x=(x1,,xs)x=(x_1,\ldots,x_s) be the inputs to a program evaluating ff. Number its intermediate variables xs+1,,xtx_{s+1},\ldots,x_t, with output xt=f(x)x_t=f(x), and let xkRnkx_k\in\mathbb{R}^{n_k}. We seek the Jacobian blocks f(x)xkRnt×nk\frac{ \partial f(x)}{\partial x_k} \in\mathbb{R}^{n_t\times n_k} for k=1,,sk=1,\ldots,s. The scalar case nk=1n_k=1 is easiest to follow; the formulas also apply to vector variables if the matrix products retain the displayed order. The total input dimension is p=k=1snkp=\sum_{k=1}^s n_k.

Figure 15.8. A computational graph.

Represent the computation as a sequence of elementary maps:

k=s+1,,t,xk=fk(x1,,xk1)\forall \,k=s+1,\ldots,t, \quad x_k = f_k( x_1,\ldots,x_{k-1} )

Each fkf_k depends only on earlier variables; see Figure 15.8. The directed acyclic graph (DAG) connects each argument used by fkf_k to its output xkx_k. The indexing is a topological order: every edge points from a smaller to a larger index.

Evaluating f(x)f(x) is a forward traversal of the graph.

Automatic differentiation differentiates the supplied computational graph. It does not by itself choose an efficient implementation of the original formula; the derivative computation benefits from the efficiency and reuse already present in the forward program.

15.3.3 Forward Mode of Automatic Differentiation

Forward mode propagates derivatives of each intermediate variable with respect to a chosen input block, here x1x_1. For scalar inputs, repeating the traversal for all pp coordinates gives the full derivative. The formulas below also propagate a block Jacobian when n1>1n_1>1.

Figure 15.9. Derivative dependencies in forward mode (left) and reverse mode (right).

Initialize the input derivatives by

x1x1=Idn1×n1,x2x1=0n2×n1,,xsx1=0ns×n1,\frac{ \partial x_1}{\partial x_1} = \mathrm{Id}_{n_1 \times n_1}, \quad \frac{ \partial x_2}{\partial x_1} = 0_{n_2 \times n_1}, \ldots, \quad \frac{ \partial x_s}{\partial x_1} = 0_{n_s \times n_1},

These are one and zero for scalar inputs. Propagate the derivatives using

k=s+1,,t,xkx1=parent(k)[xkx]×xx1=parent(k)fkx(x1,,xk1)×xx1.\forall \,k=s+1,\ldots,t, \quad \frac{ \partial x_k}{\partial x_1} = \sum_{\ell \in \text{parent}(k)} \left[ \frac{ \partial x_k}{\partial x_\ell} \right] \times \frac{ \partial x_\ell}{\partial x_1} = \sum_{\ell \in \text{parent}(k)} \frac{ \partial f_k}{\partial x_\ell} (x_1,\ldots,x_{k-1}) \times \frac{ \partial x_\ell}{\partial x_1} .

The notation “parent(k)\text{parent}(k)” denotes the nodes <k\ell<k of the graph that are connected to kk, see Figure 15.9, left.

The stored quantities are the derivatives xx1\frac{ \partial x_\ell}{\partial x_1}. The symbol ×\times denotes matrix multiplication in the vector-valued case.

The brackets [][\ldots] indicate a local derivative: xkx\frac{ \partial x_k}{\partial x_\ell} is the derivative of the elementary map fkf_k with respect to that argument. It can be evaluated when needed, assuming the local derivative is available in closed form.

Suppose the local derivative operations fkx\frac{ \partial f_k}{\partial x_\ell} have comparable costs, as when the variable dimensions nkn_k are uniformly bounded, and each node has a bounded number of parents. Computing the full Jacobian coordinate by coordinate requires pp traversals, each with cost comparable to a forward evaluation. This becomes expensive for large pp.

Simple example.

We consider the function

f(x,y)=ylog(x)+ylog(x)(15.19)f(x,y) = y\log(x)+\sqrt{y\log(x)} \tag{15.19}

on the open domain x>0x>0, ylogx>0y\log x>0, where all elementary derivatives exist. Its computational graph is displayed in Figure 15.10. The iterations of the forward mode to compute the derivative with respect to xx read

xx=1,yx=0ax=[ax]xx=1xxx{xa=log(x)}bx=[ba]ax+[by]yx=yax+0{(y,a)b=ya}cx=[cb]bx=12bbx{bc=b}fx=[fb]bx+[fc]cx=1bx+1cx{(b,c)f=b+c}\begin{aligned} \frac{ \partial x}{\partial x} &= 1, \quad \frac{ \partial y}{\partial x} = 0 \\ \frac{ \partial a}{\partial x} &= \left[ \frac{ \partial a}{\partial x} \right] \frac{ \partial x}{\partial x} = \frac{1}{x} \frac{ \partial x}{\partial x} & \{x \mapsto a = \log(x)\}\\ \frac{ \partial b}{\partial x} &= \left[ \frac{ \partial b}{\partial a} \right] \frac{ \partial a}{\partial x} + \left[ \frac{ \partial b}{\partial y} \right] \frac{ \partial y}{\partial x} = y \frac{ \partial a}{\partial x} + 0 & \{(y,a) \mapsto b=ya\}\\ \frac{ \partial c}{\partial x} &= \left[ \frac{ \partial c}{\partial b} \right] \frac{ \partial b}{\partial x} = \frac{1}{2\sqrt{b}} \frac{ \partial b}{\partial x} & \{b \mapsto c=\sqrt{b}\} \\ \frac{ \partial f}{\partial x} &= \left[ \frac{ \partial f}{\partial b} \right] \frac{ \partial b}{\partial x} + \left[ \frac{ \partial f}{\partial c} \right] \frac{ \partial c}{\partial x} = 1 \frac{ \partial b}{\partial x} + 1 \frac{ \partial c}{\partial x} & \{(b,c) \mapsto f=b+c\} \end{aligned}

A second forward pass gives the derivative with respect to yy:

xy=0,yy=1ay=[ax]xy=0{xa=log(x)}by=[ba]ay+[by]yy=0+ayy{(y,a)b=ya}cy=[cb]by=12bby{bc=b}fy=[fb]by+[fc]cy=1by+1cy{(b,c)f=b+c}\begin{aligned} \frac{ \partial x}{\partial y} &= 0, \quad \frac{ \partial y}{\partial y} = 1 \\ \frac{ \partial a}{\partial y} &= \left[ \frac{ \partial a}{\partial x} \right] \frac{ \partial x}{\partial y} = 0 & \{x \mapsto a = \log(x)\}\\ \frac{ \partial b}{\partial y} &= \left[ \frac{ \partial b}{\partial a} \right] \frac{ \partial a}{\partial y} + \left[ \frac{ \partial b}{\partial y} \right] \frac{ \partial y}{\partial y} = 0 + a \frac{ \partial y}{\partial y} & \{(y,a) \mapsto b=ya\}\\ \frac{ \partial c}{\partial y} &= \left[ \frac{ \partial c}{\partial b} \right] \frac{ \partial b}{\partial y} = \frac{1}{2\sqrt{b}} \frac{ \partial b}{\partial y} & \{b \mapsto c=\sqrt{b}\} \\ \frac{ \partial f}{\partial y} &= \left[ \frac{ \partial f}{\partial b} \right] \frac{ \partial b}{\partial y} + \left[ \frac{ \partial f}{\partial c} \right] \frac{ \partial c}{\partial y} = 1 \frac{ \partial b}{\partial y} + 1 \frac{ \partial c}{\partial y} & \{(b,c) \mapsto f=b+c\} \end{aligned}

Figure 15.10. Example of a simple computational graph.

Dual numbers.

Dual numbers provide a convenient implementation of the forward pass. They form a real algebra whose elements have the form x+εxx + \varepsilon x' where ε\varepsilon is a symbol obeying the rule that ε2=0\varepsilon^2=0. Here (x,x)R2(x,x') \in \mathbb{R}^2 and xx' is intended to store a derivative with respect to some input variable. Multiplication and, when x0x\neq0, inversion are given by

(x+εx)(y+εy)=xy+ε(xy+yx)and1x+εx=1xεxx2.(x+\varepsilon x')(y+\varepsilon y') = xy + \varepsilon(x y' + y x') \quad \text{and} \quad \frac{1}{x+\varepsilon x'} = \frac{1}{x}-\varepsilon\frac{x'}{x^2}.

For polynomial or rational ff, the arithmetic rules imply

f(x+ε)=f(x)+εf(x).f(x+\varepsilon) = f(x) + \varepsilon f'(x).

For another differentiable elementary function ff, define its action on dual numbers by

f(x+εx):=f(x)+εf(x)x.f(x+\varepsilon x') \mathrel{:=}f(x) + \varepsilon f'(x) x'.

This definition gives

(fg)(x+ε)=f(g(x))+εf(g(x))g(x)(f \circ g)(x+\varepsilon) = f(g(x)) + \varepsilon f'(g(x))g'(x)

which is the chain rule. More generally, for f(x1,,xs)f(x_1,\ldots,x_s) built from these elementary operations,

f(x1+ε,x2,,xs)=f(x1,,xs)+εfx1(x1,,xs)f(x_1+\varepsilon,x_2,\ldots,x_s) = f(x_1,\ldots,x_s) + \varepsilon \frac{ \partial f}{\partial x_1} (x_1,\ldots,x_s)

the dual-number evaluation computes fx1(x1,,xs)\frac{ \partial f}{\partial x_1} (x_1,\ldots,x_s) by forward-mode differentiation. The other coordinates are treated identically.

15.3.4 Reverse Mode of Automatic Differentiation

Reverse mode computes the derivatives xtxk\frac{ \partial x_t}{\partial x_k} of the output with respect to the intermediate variables. For a scalar output and many input coordinates, this avoids the repeated forward traversals required to compute each xkxi\frac{ \partial x_k}{\partial x_i} separately.

Initialize the derivative of the output node by

xtxt=Idnt×nt,\frac{ \partial x_t}{\partial x_t} = \mathrm{Id}_{n_t \times n_t},

and apply the following recursion from the last node to the first:

k=t1,t2,,1,xtxk=mson(k)xtxm×[xmxk]=mson(k)xtxm×fm(x1,,xm1)xk.\forall \,k=t-1,t-2,\ldots,1, \quad \frac{ \partial x_t}{\partial x_k} = \sum_{m \in \text{son}(k)} \frac{ \partial x_t}{\partial x_m} \times \left[ \frac{ \partial x_m}{\partial x_k} \right] = \sum_{m \in \text{son}(k)} \frac{ \partial x_t}{\partial x_m} \times \frac{ \partial f_m(x_1,\ldots,x_{m-1})}{\partial x_k} .

The set son(k)\text{son}(k) contains the children m>km>k that depend directly on xkx_k, as shown in Figure 15.9, right. Contributions from every child must be added.

Back-propagation.

For a scalar output xtRx_t \in \mathbb{R}, we have xtxk=[xkf(x)]R1×nk\frac{ \partial x_t}{\partial x_k} = [\nabla_{x_k} f(x)]^\top \in \mathbb{R}^{1 \times n_k}. The reverse recursion can then be written for gradient vectors:

k=t1,t2,,1,xkf(x)=mson(k)(fm(x1,,xm1)xk)(xmf(x)).\forall \,k=t-1,t-2,\ldots,1, \quad \nabla_{x_k} f(x) = \sum_{m \in \text{son}(k)} \left( \frac{ \partial f_m(x_1,\ldots,x_{m-1})}{\partial x_k} \right)^\top \left( \nabla_{x_m} f(x) \right).

Here (fm(x1,,xm1)xk)Rnk×nm\left( \frac{ \partial f_m(x_1,\ldots,x_{m-1})}{\partial x_k} \right)^\top \in \mathbb{R}^{n_k \times n_m} is the adjoint Jacobian of fmf_m. This adjoint recursion is called backpropagation and is the standard form used in machine learning.

For a scalar output (nt=1n_t=1), reverse mode is usually the preferred way to compute the full gradient. It requires access to the intermediate variables (xk)k=s+1t(x_k)_{k=s+1}^t, which can be costly to store for a large graph. Checkpointing trades additional computation for reduced storage.

Simple example.

For the two-input example f(x,y)f(x,y) in (15.19), reverse mode gives

ff=1fc=ff[fc]=ff1{cf=b+c}fb=fc[cb]+ff[fb]=fc12b+ff1{bc=b,bf=b+c}fa=fb[ba]=fby{ab=ya}fy=fb[by]=fba{yb=ya}fx=fa[ax]=fa1x{xa=log(x)}\begin{aligned} \frac{ \partial f}{\partial f} &= 1 &\\ \frac{ \partial f}{\partial c} &= \frac{ \partial f}{\partial f} \left[ \frac{ \partial f}{\partial c} \right] = \frac{ \partial f}{\partial f} 1 & \{ c \mapsto f = b+c\}\\ \frac{ \partial f}{\partial b} &= \frac{ \partial f}{\partial c} \left[ \frac{ \partial c}{\partial b} \right] + \frac{ \partial f}{\partial f} \left[ \frac{ \partial f}{\partial b} \right] = \frac{ \partial f}{\partial c} \frac{1}{2\sqrt{b}} + \frac{ \partial f}{\partial f} 1 & \{ b \mapsto c=\sqrt{b}, b \mapsto f=b+c\} \\ \frac{ \partial f}{\partial a} &= \frac{ \partial f}{\partial b} \left[ \frac{ \partial b}{\partial a} \right] = \frac{ \partial f}{\partial b} y & \{ a \mapsto b=y a\} \\ \frac{ \partial f}{\partial y} &= \frac{ \partial f}{\partial b} \left[ \frac{ \partial b}{\partial y} \right] = \frac{ \partial f}{\partial b} a & \{ y \mapsto b=ya\} \\ \frac{ \partial f}{\partial x} &= \frac{ \partial f}{\partial a} \left[ \frac{ \partial a}{\partial x} \right] = \frac{ \partial f}{\partial a} \frac{1}{x} & \{ x \mapsto a=\log(x)\} \end{aligned}

A single reverse traversal computes both derivatives with respect to xx and yy, whereas coordinatewise forward mode requires two passes.

15.3.5 Feed-forward Compositions

For a feedforward chain, the computed function is the composition

f=ftft1f2f1(15.20)f = f_{t} \circ f_{t-1} \circ \ldots \circ f_2 \circ f_1 \tag{15.20}

for functions fk:Rnk1Rnkf_k : \mathbb{R}^{n_{k-1}} \rightarrow \mathbb{R}^{n_{k}}.

The forward evaluation starts from x0=xRn0x_0=x \in \mathbb{R}^{n_0} and computes

k=1,,t,xk=fk(xk1)\forall \,k=1, \ldots, t, \quad x_{k} = f_k(x_{k-1})

giving the output f(x)=xtf(x) = x_t.

Let Ak:=fk(xk1)Rnk×nk1A_k \mathrel{:=}\partial f_k(x_{k-1}) \in \mathbb{R}^{n_{k} \times n_{k-1}} be the Jacobian of the local map. The chain rule gives

f(x)=At×At1×A2×A1.\partial f(x) = A_{t} \times A_{t-1} \times \ldots A_2 \times A_1.

Forward mode multiplies the Jacobians from right to left, while reverse mode multiplies them from left to right

f(x)=At×(At1×(×(A3×(A2×A1)))),f(x)=((((At×At1)×At2)×)×A2)×A1.\begin{aligned} \partial f(x) &= A_{t} \times \left( A_{t-1} \times \left( \ldots \times \left( A_3 \times \left( A_2 \times A_1 \right) \right) \right) \right), \\ \partial f(x) &= \left( \left( \left( \left( A_{t} \times A_{t-1} \right) \times A_{t-2} \right) \times \ldots \right) \times A_2 \right) \times A_1. \end{aligned}

Figure 15.11. Matrix multiplication costs for forward mode (left) and reverse mode (right) along a chain.

We note that the computation of the product A×BA \times B of ARn×pA \in \mathbb{R}^{n \times p} with BRp×qB \in \mathbb{R}^{p \times q} requires O(npq)O(npq) arithmetic operations with the standard dense algorithm.

As shown on Figure 15.11, the arithmetic costs of the two parenthesizations are proportional to

n0k=1t1nknk+1andntk=0t2nknk+1n_0 \sum_{k=1}^{t-1} n_k n_{k+1} \quad \text{and} \quad n_t \sum_{k=0}^{t-2} n_k n_{k+1}

For roughly comparable intermediate widths, these costs favor reverse mode when ntn0n_t\ll n_0. A scalar learning objective typically has nt=1n_t=1, making reverse mode a natural choice; the exact cost comparison depends on all the intermediate dimensions.

15.3.6 Feed-forward Architecture

A parameterized feedforward architecture, such as a neural network, has the form

k=1,,t,xk=fk(xk1,θk1)(15.21)\forall \,k=1, \ldots, t, \quad x_{k} = f_k(x_{k-1},\theta_{k-1}) \tag{15.21}

where θk1\theta_{k-1} is the parameter vector for a layer and the input x0Rn0x_0 \in \mathbb{R}^{n_0} is fixed. The objective is

f(θ):=L(xt)(15.22)f(\theta) \mathrel{:=}L(x_t) \tag{15.22}

Here L:RntRL : \mathbb{R}^{n_t} \rightarrow \mathbb{R} is a loss, such as squared prediction error or logistic loss, and θ=(θk)k=0t1\theta=(\theta_k)_{k=0}^{t-1} collects the parameters. Figure 15.12 shows the computational graph.

Figure 15.12. Computational graph for a feedforward architecture.

Reverse mode computes the gradient of ff by propagating derivatives through the variables (xk,θk)(x_k,\theta_k). Initialize

xtf=L(xt)\nabla_{x_t} f = \nabla L(x_t)

and recurse from k=tk=t down to 1:

zk1=[xfk(xk1,θk1)]zkandθk1f=[θfk(xk1,θk1)](xkf)(15.23)z_{k-1} = [\partial_x f_k(x_{k-1},\theta_{k-1})]^\top z_k \quad \text{and} \quad \nabla_{\theta_{k-1}} f = [\partial_\theta f_k(x_{k-1},\theta_{k-1})]^\top (\nabla_{x_{k}} f) \tag{15.23}

where zk:=xkf(θ)z_k \mathrel{:=}\nabla_{x_{k}} f(\theta) is the gradient with respect to xkx_{k}.

Multilayer perceptrons.

For a fully connected network without biases, use

xk1Rnk1,fk(xk1,θk1)=ρ(θk1xk1)(15.24)\forall \,x_{k-1} \in \mathbb{R}^{n_{k-1}}, \quad f_k(x_{k-1},\theta_{k-1}) = \rho( \theta_{k-1} x_{k-1} ) \tag{15.24}

where θk1Rnk×nk1\theta_{k-1}\in\mathbb{R}^{n_k\times n_{k-1}} contains the weights and ρ\rho acts coordinatewise; see Figure 15.13. The derivative formulas below apply where ρ\rho is differentiable. At a ReLU kink, a chosen derivative convention defines the computed update, but the classical derivative need not exist.

For an adjoint vector zkRnkz_k \in \mathbb{R}^{n_k}, typically xkf\nabla_{x_{k}} f,

{[xfk(xk1,θk1)](zk)=θk1wkzk,[θfk(xk1,θk1)](zk)=(wkzk)xk1wherewk:=diag(ρ(θk1xk1)).\left\{ \begin{matrix} [\partial_x f_k(x_{k-1},\theta_{k-1})]^\top (z_k) = \theta_{k-1}^\top w_k z_k, \\ [\partial_\theta f_k(x_{k-1},\theta_{k-1})]^\top (z_k) =(w_kz_k)x_{k-1}^\top \end{matrix} \right. \quad \text{where} \quad w_k \mathrel{:=}\mathop{\mathrm{diag}}(\rho'(\theta_{k-1} x_{k-1})).

Figure 15.13. Multilayer-perceptron parameterization.

Link with adjoint state method.

A residual form of (15.21) can be interpreted as a time discretization of an ordinary differential equation.

Keep the state dimension fixed, nk=nn_k=n, and interpret xkx_k as an approximation of a continuous trajectory x(t)x(t) at time t=kτt=k\tau. The formal continuum limit takes τ0\tau\downarrow0 with kτk\tau approaching a fixed time.

Impose the residual structure

fk(xk1,θk1)=xk1+τu(xk1,θk1,kτ)(15.25)f_k(x_{k-1},\theta_{k-1}) = x_{k-1} + \tau u(x_{k-1},\theta_{k-1}, k\tau) \tag{15.25}

with a parameterized vector field u(x,θ,t)Rnu(x,\theta,t) \in \mathbb{R}^n. Formally, as τ0\tau \rightarrow 0, this approaches the nonlinear ODE

x˙(t)=u(x(t),θ(t),t)(15.26)\dot x(t) = u(x(t),\theta(t),t) \tag{15.26}

with x(t=0)=x0x(t=0)=x_0.

Writing z(t)=x(t)f(θ)z(t) = \nabla_{x(t)} f(\theta) for the adjoint, the discrete relations (15.23) become a linear backward ODE:

z˙(t)=[xu(x(t),θ(t),t)]z(t)andθ(t)f(θ)=[θu(x(t),θ(t),t)]z(t).\dot z(t) = - [\partial_x u(x(t),\theta(t),t)]^\top z(t) \quad \text{and} \quad \nabla_{\theta(t)} f(\theta) = [\partial_\theta u(x(t),\theta(t),t)]^\top z(t).

The adjoint has terminal condition z(T)=L(x(T))z(T)=\nabla L(x(T)). The parameter derivative is interpreted as the L2L^2 functional gradient with respect to the time-dependent control. Its discrete normalization is 1τθk1fθ(t)f(θ)\frac{1}{\tau} \nabla_{\theta_{k-1}} f \rightarrow \nabla_{\theta(t)} f(\theta).

15.3.7 Recurrent Architectures

A recurrent architecture reuses the parameter θ=θk\theta=\theta_k and map fk=hf_k=h at every step of (15.21):

k=1,,t,xk=h(xk1,θ).(15.27)\forall \,k=1, \ldots, t, \quad x_{k} = h(x_{k-1},\theta). \tag{15.27}

Consider a scalar objective

f(θ)=L(xt,θ)f(\theta) = L(x_t,\theta)

The loss now depends explicitly on θ\theta, extending (15.22). Figure 15.14 shows the corresponding graph.

Figure 15.14. Computational graph for a recurrent architecture.

Backpropagation gives

xk1f=[xh(xk1,θ)]xkfandθf=θL(xt,θ)+k[θh(xk1,θ)]xkf.(15.28)\nabla_{x_{k-1}} f = [\partial_x h(x_{k-1},\theta)]^\top \nabla_{x_{k}} f \quad \text{and} \quad \nabla_{\theta} f = \nabla_\theta L(x_t,\theta) + \sum_k [\partial_\theta h(x_{k-1},\theta)]^\top \nabla_{x_{k}} f. \tag{15.28}

Similarly, with h(x,θ)=x+τu(x,θ)h(x,\theta) = x + \tau u(x,\theta), the formal limit (k,kτ)(+,t)(k,k\tau) \rightarrow (+\infty,t) gives a forward nonlinear ODE with a time-independent vector field:

x˙(t)=u(x(t),θ)\dot x(t) = u(x(t),\theta)

and the following linear backward adjoint equation, for f(θ)=L(x(T),θ)f(\theta)=L(x(T),\theta)

z˙(t)=[xu(x(t),θ)]z(t)andθf(θ)=θL(x(T),θ)+0T[θu(x(t),θ)]z(t)dt.(15.29)\dot z(t) = - [\partial_x u(x(t),\theta)]^\top z(t) \quad \text{and} \quad \nabla_{\theta} f(\theta) = \nabla_\theta L(x(T),\theta) + \int_0^T[\partial_\theta u(x(t),\theta)]^\top z(t) \mathrm{d}t. \tag{15.29}

with terminal condition z(T)=xL(x(T),θ)z(T)=\nabla_xL(x(T),\theta).

**Residual recurrent networks. **

A residual recurrent network uses the update

h(x,θ)=x+W2ρ(W1x)h(x,\theta) = x + W_2^\top \rho( W_1 x )

as illustrated in Figure 15.15. Here θ=(W1,W2)(Rq×n)2\theta= (W_1, W_2) \in (\mathbb{R}^{q\times n})^2 contains the weights and ρ\rho is a pointwise activation. Increasing the hidden width qq enlarges the class of representable residual maps.

When W2=τW1W_2=-\tau W_1 and ρ=ψ\rho=\psi', this update is a gradient step for E(x,θ)=iψ((W1x)i)\mathcal{E}(x,\theta)=\sum_i\psi((W_1x)_i). Repeating it gives an iterative implementation of the argmin layer (15.31), provided the iterations converge to a minimizer.

The Jacobians θh\partial_\theta h and xh\partial_x h follow from the layer formulas in the multilayer-perceptron discussion.

Figure 15.15. Recurrent residual perceptron parameterization.

**Mitigating Memory Requirements. **

Backpropagation requires access to the iterates (xk)k=0t(x_k)_{k=0}^t, whose storage can dominate memory use. Checkpointing stores selected states and reruns parts of the forward computation to reconstruct missing values. Recursive schedules can use O(logt)O(\log t) stored states with an O(logt)O(\log t) computational overhead.

If the forward computation is invertible, stored states can sometimes be reconstructed instead. Assume maps gkg_k satisfy

xk=gk(xk+1,,xt).x_{k} = g_k(x_{k+1},\ldots,x_t).

These inverse updates may amplify numerical errors, so algebraic invertibility alone does not ensure stable reconstruction. In practice, the inverse can also depend on a few extra variables, in particular on the input values (x0,,xs)(x_0,\ldots,x_s).

For example, split the continuous state as x(t)=(r(t),s(t))x(t)=(r(t),s(t)) and suppose the vector field in (15.26) has the separated form u((r,s),θ,t)=(F(s,θ,t),G(r,θ,t))u((r,s),\theta,t)=(F(s,\theta,t),G(r,\theta,t)). An invertible staggered update is

rk+1=rk+τF(sk,θk,τk)andsk+1=sk+τG(rk+1,θk+1/2,τ(k+1/2)).r_{k+1} = r_k + \tau F(s_k,\theta_k,\tau k) \quad \text{and} \quad s_{k+1} = s_k + \tau G(r_{k+1},\theta_{k+1/2},\tau (k+1/2)).

In exact arithmetic, these updates can be inverted as

sk=sk+1τG(rk+1,θk+1/2,τ(k+1/2)).andrk=rk+1τF(sk,θk,τk).s_k = s_{k+1} - \tau G(r_{k+1},\theta_{k+1/2},\tau (k+1/2)). \quad \text{and} \quad r_k = r_{k+1} - \tau F(s_k,\theta_k,\tau k).

Fixed point maps

If hh is continuous and the iterates converge to x(θ)x^\star(\theta), their limit is a fixed point:

x(θ)=h(x(θ),θ).x^\star(\theta) = h(x^\star(\theta),\theta).

Backpropagation differentiates the finite computation f(θ)=L(xt,θ)f(\theta) = L(x_t,\theta). For the limiting objective f(θ)=L(x(θ),θ)f^\star(\theta) = L(x^\star(\theta),\theta), the implicit function theorem gives an alternative:

f(θ)=[x(θ)](xL(x(θ),θ))+θL(x(θ),θ).(15.30)\nabla f^\star(\theta) = [\partial x^\star(\theta)]^\top( \nabla_x L(x^\star(\theta),\theta) ) + \nabla_\theta L(x^\star(\theta),\theta). \tag{15.30}

Assume hh is continuously differentiable and Idxh\mathrm{Id}-\partial_xh is invertible at the fixed point. The implicit function theorem then gives

x(θ)=(Idxh(x(θ),θ))1θh(x(θ),θ).\partial x^\star(\theta)=\left(\mathrm{Id}-\partial_xh(x^\star(\theta),\theta)\right)^{-1}\partial_\theta h(x^\star(\theta),\theta).

In practice, one replaces in these formulas x(θ)x^\star(\theta) by xtx_t, which approximates the derivative of the converged objective ff^\star, rather than the derivative of the finite unrolling ff.

This approach replaces storage of the iteration history by a linear solve at the approximate equilibrium.

Argmin layers

An argmin layer maps a parameter θ\theta to a minimizer x(θ)x(\theta) of a parameterized objective. Assume a unique minimizer, or specify a branch when several exist:

x(θ)=argminx  E(x,θ).x(\theta) = \underset{x}{\mathop{\mathrm{argmin}}}\; \mathcal{E}(x,\theta).

One way to compute the layer is gradient descent, initialized here at x0=0x_0=0:

xk+1=xkτE(xk,θ).(15.31)x_{k+1} = x_k - \tau \nabla \mathcal{E}(x_k,\theta). \tag{15.31}

This has the form (15.25) when using the vector field u(x,θ)=xE(x,θ)u(x,\theta)=-\nabla_x\mathcal{E}(x,\theta).

Assume E\mathcal{E} is twice continuously differentiable near the selected minimizer and its Hessian with respect to xx is invertible. The implicit function theorem gives a locally differentiable minimizer branch; applying (15.30) to its stationarity equation yields

f(θ)=(2Exθ(x(θ),θ))(2Ex2(x(θ),θ))1(xL(x(θ),θ))+θL(x(θ),θ)\nabla f^\star(\theta) = -\left( \frac{\partial^2 \mathcal{E}}{\partial x \partial \theta}(x^\star(\theta),\theta) \right)^\top \left( \frac{ \partial^2 \mathcal{E}}{\partial x^2} (x^\star(\theta),\theta) \right)^{-1} ( \nabla_x L(x^\star(\theta),\theta) ) + \nabla_\theta L(x^\star(\theta),\theta)

If f(θ)f(\theta) is the minimized value itself, f(θ)=E(x(θ),θ)f(\theta)=\mathcal{E}(x^\star(\theta),\theta), then L=EL=\mathcal{E}. Formula (15.30) simplifies because xL(x(θ),θ)=0\nabla_x L(x^\star(\theta),\theta)=0, giving

f(θ)=θL(x(θ),θ).(15.32)\nabla f^\star(\theta) = \nabla_\theta L(x^\star(\theta),\theta). \tag{15.32}

This is the envelope theorem, also associated with Danskin’s theorem.

Sinkhorn’s algorithm

Let aRna\in\mathbb{R}^n and bRmb\in\mathbb{R}^m be strictly positive probability vectors, let CRn×mC\in\mathbb{R}^{n\times m} be a cost matrix, and let ε>0\varepsilon>0. Entropic optimal transport minimizes

ijCijPij+εijPij(logPij1)\sum_{ij}C_{ij}P_{ij}+\varepsilon\sum_{ij}P_{ij}(\log P_{ij}-1)

over P0P\geqslant 0 with row sums aa and column sums bb. Set Kij=eCij/ε>0K_{ij}=e^{-C_{ij}/\varepsilon}>0. Sinkhorn’s alternating updates, initialized with positive scaling vectors, are

uk+1=aKvk,vk+1=bKuk+1.u_{k+1}=\frac{a}{Kv_k},\qquad v_{k+1}=\frac{b}{K^\top u_{k+1}}.

All divisions are componentwise. The second update uses the newly computed uk+1u_{k+1}; this sequential dependence is part of Sinkhorn’s alternating scheme.

The regularized transport value is the maximum of the dual objective

E(u,v;a,b)=ε(a,logu+b,logvu,Kv).\mathcal{E}(u,v;a,b)=\varepsilon\left(\langle a,\,\log u\rangle+\langle b,\,\log v\rangle-\langle u,\,Kv\rangle\right).

Sinkhorn performs alternating maximization of this objective. A finite number of iterations defines a differentiable recurrent map on positive inputs. Its Jacobian products can be computed by chaining the two scaling steps. For example, for u=a/(Kv)u=a/(Kv),

vu=diag(a(Kv)2)K,au=diag(1Kv),\partial_vu=-\mathop{\mathrm{diag}}\left(\frac{a}{(Kv)^2}\right)K,\qquad \partial_au=\mathop{\mathrm{diag}}\left(\frac1{Kv}\right),

and analogous formulas apply to the vv update, with the dependence through the newly computed uu included.

At convergence, the envelope theorem gives marginal derivatives represented by the dual potentials

af=εlogu,bf=εlogv.\nabla_a f^\star=\varepsilon\log u^\star,\qquad \nabla_b f^\star=\varepsilon\log v^\star.

The scalings have the invariance (u,v)(cu,v/c)(u,v)\mapsto(cu,v/c), so these potentials are defined up to opposite additive constants. On the probability simplices, derivatives act on zero-sum perturbations and are therefore independent of this gauge. An implicit differentiation formula must fix the gauge before inverting a Jacobian; the unmodified fixed-point Jacobian is singular in that direction.