skoro v0.0.0

Elimination in square-root form

A sum of squared linear residuals and linear terms is minimized, integrated or marginalized one block of variables at a time by orthogonal factorizations of its rows, without ever forming its normal equations; each elimination leaves a conditional and a smaller problem of the same form.

Updated 2026-11-25 · 20 min read

The steps and the Gaussians of the notes before this one end in the normal equations of a function of a vector v∈Rd\tangent \in \R^\dimension that is half a sum of squared affine residuals, plus a linear term,

ϕ(v)=12∣Av−b∣2+η⊤v,(1) \phi(\tangent) = \tfrac12 \lvert A \tangent - b \rvert^2 + \eta\transpose \tangent , \tag{1}
(1)

which is to be minimized, integrated as e−ϕe^{-\phi}, or reduced to a function of some of its variables. Forming the matrix A⊤AA\transpose A of those equations squares the condition number, and can lose every digit. This note shows how to do each of the three without forming it, and how to do it one block of variables at a time when AA is sparse. It is a note about numbers and matrices alone, and nothing in it depends on where the rows came from.

Linear least squares#

With η=0\eta = 0, minimizing (1) is the linear least-squares problem. Its minimizer solves the normal equations

A⊤A v=A⊤b,(2) A\transpose A\, \tangent = A\transpose b , \tag{2}
(2)

and the example of what forming them costs is one whose matrix, as computed, is singular, though the problem is well within double precision. The cure is to work with AA itself, by transformations that preserve the residual’s length and so amplify no error. The factorization below returns that example’s solution to full precision.

Householder reflections#

A square matrix QQ is orthogonal if Q⊤Q=IQ\transpose Q = I. It preserves lengths, so it can be applied to the residual without changing the problem, ∣Av−b∣=∣Q⊤(Av−b)∣\lvert A \tangent - b \rvert = \lvert Q\transpose(A \tangent - b) \rvert, and its condition number is one, so applying it amplifies no error. The orthogonal matrices used here are reflections: HwH_w below fixes every vector orthogonal to ww and sends ww to −w-w, so it mirrors space in the hyperplane orthogonal to ww. A tuple of vectors, such as (v,u)(v, u), stands for the column vector that stacks them, vv above uu.

Lemma 3(Householder reflections).

For a nonzero w∈Rpw \in \R^p, the Householder reflection

Hw=I−2 ww⊤∣w∣2 H_w = I - \frac{2\, w w\transpose}{\lvert w \rvert^2}

is symmetric and orthogonal. For a nonzero x∈Rpx \in \R^p, let α=−sgn⁡(x1)∣x∣\alpha = -\operatorname{sgn}(x_1) \lvert x \rvert, with sgn⁡(0)=1\operatorname{sgn}(0) = 1, and let ww equal xx except in its first entry, w1=x1−αw_1 = x_1 - \alpha. Then w≠0w \neq 0, and

Hwx=[α0], H_w x = \begin{bmatrix} \alpha \\ 0 \end{bmatrix} ,

the vector with first entry α\alpha and every other entry zero.

Proof.

HwH_w is symmetric because ww⊤w w\transpose is, and

Hw⊤Hw=Hw2=I−4ww⊤∣w∣2+4w (w⊤w) w⊤∣w∣4=I. \begin{aligned} H_w\transpose H_w &= H_w^2 \\ &= I - 4 \frac{w w\transpose}{\lvert w \rvert^2} + 4 \frac{w\, (w\transpose w)\, w\transpose}{\lvert w \rvert^4} \\ &= I . \end{aligned}

For the second part, ww differs from xx only in its first entry, by −α-\alpha, and α2=∣x∣2\alpha^2 = \lvert x \rvert^2, so w⊤x=∣x∣2−αx1w\transpose x = \lvert x \rvert^2 - \alpha x_1 and

∣w∣2=∣x∣2−2αx1+α2=2(∣x∣2−αx1)=2 w⊤x. \begin{aligned} \lvert w \rvert^2 &= \lvert x \rvert^2 - 2 \alpha x_1 + \alpha^2 \\ &= 2 \bigl( \lvert x \rvert^2 - \alpha x_1 \bigr) \\ &= 2\, w\transpose x . \end{aligned}

The product −αx1-\alpha x_1 is ∣x1∣∣x∣\lvert x_1 \rvert \lvert x \rvert, which is not negative, so ∣w∣2≥2∣x∣2\lvert w \rvert^2 \ge 2 \lvert x \rvert^2, which is positive. Then

Hwx=x−2w⊤x∣w∣2 w=x−w=[α0]. \begin{aligned} H_w x &= x - 2 \frac{w\transpose x}{\lvert w \rvert^2}\, w \\ &= x - w \\ &= \begin{bmatrix} \alpha \\ 0 \end{bmatrix} . \end{aligned}
∎

Either sign of α\alpha would do, as long as w≠0w \neq 0; the one chosen makes w1=x1+sgn⁡(x1)∣x∣w_1 = x_1 + \operatorname{sgn}(x_1) \lvert x \rvert a sum of two numbers of the same sign. The other sign subtracts them, and when xx is already close to a multiple of the first coordinate vector they nearly cancel, and ww is computed with a large relative error.

A reflection built from a vector whose leading entries are zero touches only the trailing entries of what it is applied to.

Lemma 4(Reflections that leave a leading block alone).

Let w=(0,w′)∈Rpw = (0, w') \in \R^p, with 0∈Ri0 \in \R^i and w′∈Rp−iw' \in \R^{p - i} nonzero. Then

Hw=[I00Hw′], H_w = \begin{bmatrix} I & 0 \\ 0 & H_{w'} \end{bmatrix} ,

so that

Hw[vu]=[vHw′u] H_w \begin{bmatrix} v \\ u \end{bmatrix} = \begin{bmatrix} v \\ H_{w'} u \end{bmatrix}

for every v∈Riv \in \R^i and u∈Rp−iu \in \R^{p - i}. In particular, HwH_w leaves the first ii entries of every vector unchanged, and fixes every vector whose other entries are zero:

Hw[v0]=[v0]. H_w \begin{bmatrix} v \\ 0 \end{bmatrix} = \begin{bmatrix} v \\ 0 \end{bmatrix} .
Proof.

The norms agree, ∣w∣=∣w′∣\lvert w \rvert = \lvert w' \rvert, and the leading zeros of ww meet vv, so

w⊤[vu]=w′⊤u. w\transpose \begin{bmatrix} v \\ u \end{bmatrix} = w'^\top u .

Therefore

Hw[vu]=[vu]−2w′⊤u∣w′∣2[0w′]=[vHw′u]. \begin{aligned} H_w \begin{bmatrix} v \\ u \end{bmatrix} &= \begin{bmatrix} v \\ u \end{bmatrix} - 2 \frac{w'^\top u}{\lvert w' \rvert^2} \begin{bmatrix} 0 \\ w' \end{bmatrix} \\ &= \begin{bmatrix} v \\ H_{w'} u \end{bmatrix} . \end{aligned}

Read column by column, with (v,u)(v, u) each coordinate vector in turn, this is the block form.

∎

The triangular root#

Theorem 5(The triangular root).

Let AA be an m×nm \times n matrix of rank nn and b∈Rmb \in \R^m. There is an orthogonal m×mm \times m matrix QQ with

Q⊤[Ab]=[Rd0e], Q\transpose \begin{bmatrix} A & b \end{bmatrix} = \begin{bmatrix} R & d \\ 0 & e \end{bmatrix},

RR an n×nn \times n upper-triangular matrix with a nonzero diagonal, d∈Rnd \in \R^n and e∈Rm−ne \in \R^{m - n}. For every v∈Rn\tangent \in \R^n, ∣Av−b∣2=∣Rv−d∣2+∣e∣2\lvert A \tangent - b \rvert^2 = \lvert R \tangent - d \rvert^2 + \lvert e \rvert^2, and R⊤R=A⊤AR\transpose R = A\transpose A.

Proof.

The matrix QQ is built from nn reflections, one for each column of AA, each of them made by Lemma 3 to reduce one column, and each leaving the columns already reduced alone by Lemma 4. Let M0=[A   b]M_0 = [A \;\, b] and Mj=HjMj−1M_j = H_j M_{j-1} for j=1,…,nj = 1, \dots, n, with HjH_j chosen as follows. Suppose that each of the first j−1j - 1 columns of Mj−1M_{j-1} is zero below its diagonal entry, which holds for j=1j = 1 since there are none. Let xx be the entries of column jj of Mj−1M_{j-1} in rows jj to mm. Then x≠0x \neq 0: otherwise the first jj columns of Mj−1M_{j-1} would all lie in the span of the first j−1j - 1 coordinate vectors, and so be linearly dependent, but they are the first jj columns of Hj−1⋯H1AH_{j-1} \cdots H_1 A, which has rank nn since each HiH_i is invertible. Take αj\alpha_j and w′w' for xx from Lemma 3, and let Hj=HwH_j = H_w with w=(0,w′)w = (0, w'), its first j−1j - 1 entries zero. By Lemma 4, HjH_j leaves rows 11 to j−1j - 1 of Mj−1M_{j-1} unchanged, and its first j−1j - 1 columns too, since each is zero below row j−1j - 1; and it maps column jj’s entries in rows jj to mm to αj\alpha_j followed by zeros. So the first jj columns of MjM_j are zero below their diagonal entries.

After nn steps, Mn=Hn⋯H1[A   b]M_n = H_n \cdots H_1 [A \;\, b] has the form of the theorem, with RR upper triangular with diagonal entries α1,…,αn\alpha_1, \dots, \alpha_n, each nonzero. Each HjH_j is symmetric and orthogonal, so Q=H1⋯HnQ = H_1 \cdots H_n is orthogonal and Q⊤=Hn⋯H1Q\transpose = H_n \cdots H_1. Then

∣Av−b∣2=∣Q⊤(Av−b)∣2=∣[Rv−d−e]∣2=∣Rv−d∣2+∣e∣2, \begin{aligned} \lvert A \tangent - b \rvert^2 &= \bigl\lvert Q\transpose (A \tangent - b) \bigr\rvert^2 \\ &= \left\lvert \begin{bmatrix} R \tangent - d \\ -e \end{bmatrix} \right\rvert^2 \\ &= \lvert R \tangent - d \rvert^2 + \lvert e \rvert^2 , \end{aligned}

and

A⊤A=A⊤QQ⊤A=[R0]⊤[R0]=R⊤R. \begin{aligned} A\transpose A &= A\transpose Q Q\transpose A \\ &= \begin{bmatrix} R \\ 0 \end{bmatrix}\transpose \begin{bmatrix} R \\ 0 \end{bmatrix} \\ &= R\transpose R . \end{aligned}
∎

The minimizer of ∣Av−b∣2\lvert A \tangent - b \rvert^2 therefore solves the triangular system Rv=dR \tangent = d, and the minimum is ∣e∣2\lvert e \rvert^2. RR is a square root of the normal equations’ matrix, R⊤R=A⊤AR\transpose R = A\transpose A, computed without forming that matrix, and κ(R)=κ(A)\kappa(R) = \kappa(A). Read as the precision of a Gaussian, it is the square-root information matrix. A triangular system is solved by back substitution, from the last unknown up: for i=n,n−1,…,1i = n, n - 1, \dots, 1,

vi=1Rii(di−∑j>iRij vj),(6) \tangent_i = \frac{1}{R_{ii}} \Bigl( d_i - \sum_{j > i} R_{ij}\, \tangent_j \Bigr) , \tag{6}
(6)

the sum being empty for i=ni = n, in about n2n^2 operations, and backward stably; a lower-triangular one, such as R⊤y=cR\transpose y = c, by forward substitution, from the first unknown down. A zero diagonal entry means AA does not have rank nn: some direction is not determined by the rows, and a diagonal entry small against the others means a direction determined poorly. Either is reported, not divided by.

For example, take

A=[−201525],b=[−716−3]. A = \begin{bmatrix} -2 & 0 \\ 1 & 5 \\ 2 & 5 \end{bmatrix} , \qquad b = \begin{bmatrix} -7 \\ 16 \\ -3 \end{bmatrix} .

The first column is x=(−2,1,2)x = (-2, 1, 2), with ∣x∣=3\lvert x \rvert = 3 and x1<0x_1 < 0, so α1=3\alpha_1 = 3 and w=(−5,1,2)w = (-5, 1, 2), with ∣w∣2=30\lvert w \rvert^2 = 30. H1H_1 maps each column yy of [A   b][A \;\, b] to y−(w⊤y/15) wy - (w\transpose y / 15)\, w, so the first column goes to (3,0,0)(3, 0, 0), as Lemma 3 says, and the others follow with w⊤y=15w\transpose y = 15 and w⊤b=45w\transpose b = 45:

H1[−212]=[−212]−1515[−512]=[300],H1[055]=[055]−1515[−512]=[543],H1[−716−3]=[−716−3]−4515[−512]=[813−9]. \begin{gathered} H_1 \begin{bmatrix} -2 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} -2 \\ 1 \\ 2 \end{bmatrix} - \frac{15}{15} \begin{bmatrix} -5 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} 3 \\ 0 \\ 0 \end{bmatrix} , \\ H_1 \begin{bmatrix} 0 \\ 5 \\ 5 \end{bmatrix} = \begin{bmatrix} 0 \\ 5 \\ 5 \end{bmatrix} - \frac{15}{15} \begin{bmatrix} -5 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} 5 \\ 4 \\ 3 \end{bmatrix} , \\ H_1 \begin{bmatrix} -7 \\ 16 \\ -3 \end{bmatrix} = \begin{bmatrix} -7 \\ 16 \\ -3 \end{bmatrix} - \frac{45}{15} \begin{bmatrix} -5 \\ 1 \\ 2 \end{bmatrix} = \begin{bmatrix} 8 \\ 13 \\ -9 \end{bmatrix} . \end{gathered}

Together,

H1[Ab]=[358041303−9]. H_1 \begin{bmatrix} A & b \end{bmatrix} = \begin{bmatrix} 3 & 5 & 8 \\ 0 & 4 & 13 \\ 0 & 3 & -9 \end{bmatrix} .

The first row and the first column are now final. The second step works on what is left, rows 2 and 3 of the last two columns. There x=(4,3)x = (4, 3), with ∣x∣=5\lvert x \rvert = 5 and x1>0x_1 > 0, so α2=−5\alpha_2 = -5 and w′=(9,3)w' = (9, 3), with ∣w′∣2=90\lvert w' \rvert^2 = 90, and H2=HwH_2 = H_w for w=(0,9,3)w = (0, 9, 3). By Lemma 4, H2H_2 leaves the first row, [3   5   8][3 \;\, 5 \;\, 8], alone, and the first column, (3,0,0)(3, 0, 0), which is of the form (v,0)(v, 0). On the rest it acts as Hw′H_{w'}, which maps yy to y−(w′⊤y/45) w′y - (w'^\top y / 45)\, w':

Hw′[43]=[43]−4545[93]=[−50],Hw′[13−9]=[13−9]−9045[93]=[−5−15]. \begin{gathered} H_{w'} \begin{bmatrix} 4 \\ 3 \end{bmatrix} = \begin{bmatrix} 4 \\ 3 \end{bmatrix} - \frac{45}{45} \begin{bmatrix} 9 \\ 3 \end{bmatrix} = \begin{bmatrix} -5 \\ 0 \end{bmatrix} , \\ H_{w'} \begin{bmatrix} 13 \\ -9 \end{bmatrix} = \begin{bmatrix} 13 \\ -9 \end{bmatrix} - \frac{90}{45} \begin{bmatrix} 9 \\ 3 \end{bmatrix} = \begin{bmatrix} -5 \\ -15 \end{bmatrix} . \end{gathered}

Together,

H2H1[Ab]=[3580−5−500−15]. H_2 H_1 \begin{bmatrix} A & b \end{bmatrix} = \begin{bmatrix} 3 & 5 & 8 \\ 0 & -5 & -5 \\ 0 & 0 & -15 \end{bmatrix} .

So R=[350−5]R = \left[\begin{smallmatrix} 3 & 5 \\ 0 & -5 \end{smallmatrix}\right], d=(8,−5)d = (8, -5) and e=−15e = -15. Back substitution gives the minimizer,

v2=−5−5=1,v1=8−5v23=1, \begin{gathered} \tangent_2 = \frac{-5}{-5} = 1 , \\ \tangent_1 = \frac{8 - 5 \tangent_2}{3} = 1 , \end{gathered}

and the minimum of ∣Av−b∣2\lvert A \tangent - b \rvert^2 is e2=225e^2 = 225. Indeed, and with the root as the theorem says,

b−A[11]=[−510−10],R⊤R=[9151550]=A⊤A. \begin{gathered} b - A \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} -5 \\ 10 \\ -10 \end{bmatrix} , \\ R\transpose R = \begin{bmatrix} 9 & 15 \\ 15 & 50 \end{bmatrix} = A\transpose A . \end{gathered}

The second diagonal entry of RR is negative, which the sign rule of Lemma 3 allows and the theorem does not mind. Changing the sign of a row of [R   d][R \;\, d], which is multiplying QQ by a diagonal matrix of signs, changes nothing in the theorem, so a positive diagonal can be had when it is wanted.

Neither QQ nor any HjH_j is formed. A reflection is applied to a vector yy of pp entries as y−β (w⊤y) wy - \beta\, (w\transpose y)\, w, with β=2/∣w∣2\beta = 2 / \lvert w \rvert^2, in about 4p4p operations, and only the vectors ww are kept, if QQ is needed again at all. Step jj applies one to the last n−jn - j columns of AA, in rows jj to mm, so the reduction takes about ∑j4(m−j)(n−j)≈2mn2−23n3\sum_j 4 (m - j)(n - j) \approx 2 m n^2 - \tfrac23 n^3 operations. Forming A⊤AA\transpose A and factoring it takes about mn2+13n3m n^2 + \tfrac13 n^3, so when mm is much larger than nn the reflections cost twice as much, which is the price of the digits kept. Applying them to bb alongside AA gives dd and ee in the same pass.

Linear terms#

A linear term η⊤v\eta\transpose \tangent in (1) is not a squared residual, but it can be carried along. With RR and dd from Theorem 5 and y=R−⊤ηy = R^{-\top} \eta, the solution of the forward substitution R⊤y=ηR\transpose y = \eta, so that η⊤v=y⊤Rv\eta\transpose \tangent = y\transpose R \tangent, completing the square gives

ϕ(v)=12∣Rv−(d−y)∣2+12∣e∣2+y⊤d−12∣y∣2.(7) \phi(\tangent) = \tfrac12 \bigl\lvert R \tangent - (d - y) \bigr\rvert^2 + \tfrac12 \lvert e \rvert^2 + y\transpose d - \tfrac12 \lvert y \rvert^2 . \tag{7}
(7)

So ϕ\phi is minimized at v∗=R−1(d−y)\tangent^* = R^{-1}(d - y), which solves A⊤A v∗=A⊤b−ηA\transpose A\, \tangent^* = A\transpose b - \eta, and the decrease from v=0\tangent = 0 is

ϕ(0)−ϕ(v∗)=12∣d−y∣2=12∣Rv∗∣2,(8) \phi(0) - \phi(\tangent^*) = \tfrac12 \lvert d - y \rvert^2 = \tfrac12 \lvert R \tangent^* \rvert^2 , \tag{8}
(8)

since ϕ(0)=12∣d∣2+12∣e∣2\phi(0) = \tfrac12 \lvert d \rvert^2 + \tfrac12 \lvert e \rvert^2. Two things change with the linear term.

  • It needs every direction determined. When AA has rank nn, ϕ\phi is bounded below whatever η\eta is. When it does not, ϕ\phi is bounded below only if η\eta lies in the row space of AA, and the minimizer is then not unique. The rank condition is checked on the diagonal of RR, as before.
  • It is solved at κ(A)2\kappa(A)^2. The part of v∗\tangent^* that comes from bb is R−1dR^{-1} d, one triangular solve at κ(A)\kappa(A). The part that comes from η\eta is R−1R−⊤ηR^{-1} R^{-\top} \eta, two, and is as sensitive as a solve of the normal equations: only the factor was computed at κ(A)\kappa(A). A linear term known to be A⊤cA\transpose c for some vector cc is better folded into bb, as b−cb - c, before factoring.

With AA empty, ϕ\phi is linear and the problem is unbounded unless η=0\eta = 0; with b=0b = 0 and η\eta a gradient, the minimizer is the solution of the normal equations with that gradient on the right, which is the form of every method whose rows come without a residual.

Eliminating one block#

The variables of a large problem usually fall into blocks, one for each unknown, holding that unknown’s coordinates: in a map built along a robot’s path, a block for each pose and one for each landmark. Write v=(v1,…,vn)\tangent = (\tangent_1, \dots, \tangent_n), with block kk the vector vk∈Rdk\tangent_k \in \R^{d_k}.

The rows fall into factors in the same way, one for each measurement. A measurement concerns only a few of the unknowns, so the rows it gives are zero in the columns of every other block. A factor ff is therefore described by three things:

  • the set KfK_f of the blocks it involves, those whose columns are not all zero in its rows;
  • its rows AfA_f, keeping only the columns of the blocks it involves;
  • its right-hand side bfb_f.

Its residual is AfvKf−bfA_f \tangent_{K_f} - b_f, where vKf\tangent_{K_f} stacks the blocks of KfK_f. Stacking the rows of every factor, with zeros put back in the columns of the blocks it does not involve, gives back AA and bb. The odometry in the example at the end of this section, v2−v1=1\tangent_2 - \tangent_1 = 1, is a factor with Kf={1,2}K_f = \{1, 2\}, Af=[ −1   1 ]A_f = [\,{-1} \;\, 1\,] and bf=1b_f = 1.

The linear term needs no factors. It splits into one piece for each block, η⊤v=∑kηk⊤vk\eta\transpose \tangent = \sum_k \eta_k\transpose \tangent_k, and each piece involves a single block, so it never ties two blocks together. It is kept as a vector ηk\eta_k for each block, and the problem (1) is

ϕ(v)=∑f12∣Af vKf−bf∣2+∑kηk⊤vk.(9) \phi(\tangent) = \sum_f \tfrac12 \bigl\lvert A_f\, \tangent_{K_f} - b_f \bigr\rvert^2 + \sum_k \eta_k\transpose \tangent_k . \tag{9}
(9)

The linearization of a sum of squares is such a problem, with one factor for each term: the rows Af=JtA_f = J_t over the blocks of the term’s variables KtK_t, the right-hand side bf=−(rt+c^t)b_f = -(r_t + \hat c_t), and the linear term η\eta, split by block. Each piece of the linear term involves a single block, so the factor structure is that of the terms alone.

The factors say where the matrix A⊤AA\transpose A is zero. Its block (j,k)(j, k) is the sum, over the factors that involve both jj and kk, of the product of their columns for jj, transposed, with their columns for kk. It is zero when no factor involves both blocks.

Eliminating a block kk removes it from the problem. Apart from the linear term ηk\eta_k, only the factors that involve kk depend on vk\tangent_k. The other blocks that those factors involve form the separator SS of kk. Stack the rows of those factors into one matrix [Ak   AS   b][A_k \;\, A_S \;\, b], where AkA_k holds their columns for kk, ASA_S their columns for the blocks of SS (zero where a factor does not involve one of them), and bb their right-hand sides. The lemma concerns these factors together with the linear terms of kk and of SS, where ηS\eta_S stacks the vectors ηj\eta_j of the blocks jj of SS.

Lemma 10(Eliminating one block).

Let

ϕ(vk,vS)=12∣Akvk+ASvS−b∣2+ηk⊤vk+ηS⊤vS, \phi(\tangent_k, \tangent_S) = \tfrac12 \lvert A_k \tangent_k + A_S \tangent_S - b \rvert^2 + \eta_k\transpose \tangent_k + \eta_S\transpose \tangent_S ,

with AkA_k of mm rows and of rank dkd_k, and let an orthogonal QQ bring the rows to

Q⊤[AkASb]=[RTd0A′b′], Q\transpose \begin{bmatrix} A_k & A_S & b \end{bmatrix} = \begin{bmatrix} R & T & d \\ 0 & A' & b' \end{bmatrix},

with RR a dk×dkd_k \times d_k upper-triangular matrix with a nonzero diagonal. With y=R−⊤ηky = R^{-\top} \eta_k,

ϕ(vk,vS)=12∣Rvk+TvS−(d−y)∣2+ϕ′(vS)+γ, \phi(\tangent_k, \tangent_S) = \tfrac12 \bigl\lvert R \tangent_k + T \tangent_S - (d - y) \bigr\rvert^2 + \phi'(\tangent_S) + \gamma ,

where

ϕ′(vS)=12∣A′vS−b′∣2+(ηS−T⊤y)⊤vS \phi'(\tangent_S) = \tfrac12 \lvert A' \tangent_S - b' \rvert^2 + (\eta_S - T\transpose y)\transpose \tangent_S

and γ=y⊤d−12∣y∣2\gamma = y\transpose d - \tfrac12 \lvert y \rvert^2. Consequently:

  1. for every vS\tangent_S, min⁡vkϕ=ϕ′(vS)+γ\min_{\tangent_k} \phi = \phi'(\tangent_S) + \gamma, attained only at vk=R−1(d−y−TvS)\tangent_k = R^{-1}(d - y - T \tangent_S);
  2. for every vS\tangent_S, ∫Rdke−ϕ(vk,vS) dvk=(2π)dk/2 ∣det⁡R∣−1 e−ϕ′(vS)−γ\int_{\R^{d_k}} e^{-\phi(\tangent_k, \tangent_S)}\, \dd \tangent_k = (2\pi)^{d_k / 2}\, \lvert \det R \rvert^{-1}\, e^{-\phi'(\tangent_S) - \gamma};
  3. with Λ=[Ak   AS]⊤[Ak   AS]\Lambda = [A_k \;\, A_S]\transpose [A_k \;\, A_S] in blocks, the matrix of ϕ′\phi' is the Schur complement, A′⊤A′=ΛSS−ΛSkΛkk−1ΛkSA'^\top A' = \Lambda_{SS} - \Lambda_{Sk} \Lambda_{kk}^{-1} \Lambda_{kS}, and its gradient at zero is gS−ΛSkΛkk−1gkg_S - \Lambda_{Sk} \Lambda_{kk}^{-1} g_k, with gg the gradient of ϕ\phi at zero.
Proof.

Since QQ preserves lengths, the squares are

12∣Akvk+ASvS−b∣2=12∣[Rvk+TvS−dA′vS−b′]∣2=12∣Rvk+TvS−d∣2+12∣A′vS−b′∣2. \begin{aligned} \tfrac12 \lvert A_k \tangent_k + A_S \tangent_S - b \rvert^2 &= \tfrac12 \left\lvert \begin{bmatrix} R \tangent_k + T \tangent_S - d \\ A' \tangent_S - b' \end{bmatrix} \right\rvert^2 \\ &= \tfrac12 \lvert R \tangent_k + T \tangent_S - d \rvert^2 + \tfrac12 \lvert A' \tangent_S - b' \rvert^2 . \end{aligned}

Write w=Rvk+TvS−dw = R \tangent_k + T \tangent_S - d. Since R⊤y=ηkR\transpose y = \eta_k,

ηk⊤vk=y⊤Rvk=y⊤w−y⊤TvS+y⊤d, \eta_k\transpose \tangent_k = y\transpose R \tangent_k = y\transpose w - y\transpose T \tangent_S + y\transpose d ,

and completing the square in ww,

12∣w∣2+y⊤w=12∣w+y∣2−12∣y∣2, \tfrac12 \lvert w \rvert^2 + y\transpose w = \tfrac12 \lvert w + y \rvert^2 - \tfrac12 \lvert y \rvert^2 ,

which together give the decomposition. Only its first term depends on vk\tangent_k; it is zero exactly at the point of part 1, since RR is nonsingular, which proves part 1, and the substitution s=Rvks = R \tangent_k turns its integral into that of a standard normal density’s kernel, of volume (2π)dk/2(2\pi)^{d_k/2}, times ∣det⁡R∣−1\lvert \det R \rvert^{-1}, which proves part 2. For part 3, QQ is orthogonal, so Λ\Lambda is also the product of the reduced columns with themselves: Λkk=R⊤R\Lambda_{kk} = R\transpose R, ΛkS=R⊤T\Lambda_{kS} = R\transpose T and ΛSS=T⊤T+A′⊤A′\Lambda_{SS} = T\transpose T + A'^\top A', whence

ΛSS−ΛSkΛkk−1ΛkS=T⊤T+A′⊤A′−T⊤R (R⊤R)−1R⊤T=A′⊤A′. \begin{aligned} \Lambda_{SS} - \Lambda_{Sk} \Lambda_{kk}^{-1} \Lambda_{kS} &= T\transpose T + A'^\top A' - T\transpose R\, (R\transpose R)^{-1} R\transpose T \\ &= A'^\top A' . \end{aligned}

In the same way gk=ηk−R⊤dg_k = \eta_k - R\transpose d and gS=ηS−T⊤d−A′⊤b′g_S = \eta_S - T\transpose d - A'^\top b', so

gS−ΛSkΛkk−1gk=ηS−T⊤d−A′⊤b′−T⊤R−⊤(ηk−R⊤d)=ηS−A′⊤b′−T⊤R−⊤ηk, \begin{aligned} g_S - \Lambda_{Sk} \Lambda_{kk}^{-1} g_k &= \eta_S - T\transpose d - A'^\top b' - T\transpose R^{-\top} (\eta_k - R\transpose d) \\ &= \eta_S - A'^\top b' - T\transpose R^{-\top} \eta_k , \end{aligned}

which is the gradient of ϕ′\phi' at zero, since R−⊤ηk=yR^{-\top} \eta_k = y.

∎

The first term of the decomposition is a conditional: it says what vk\tangent_k is once vS\tangent_S is known. The second, ϕ′\phi', is a new factor on the separator, with the linear term −T⊤y-T\transpose y pushed onto the separator’s blocks, and it replaces every factor that involved kk. The constant γ\gamma, and 12∣e∣2\tfrac12 \lvert e \rvert^2 when A′A' is reduced further, depend on nothing. The problem now has one block fewer and the same form. Minimizing over vk\tangent_k and integrating over it leave the same new factor, and differ only in a constant, dk2log⁡2π−log⁡∣det⁡R∣\tfrac{d_k}{2} \log 2\pi - \log \lvert \det R \rvert. Part 3 says that the new factor is what Gaussian elimination of block kk from the normal equations would have produced, reached through square roots instead: the matrix Λ\Lambda is never formed, and nothing is inverted but triangular blocks.

The new factor has m−dkm - d_k rows, which may be more than the separator’s dimension dSd_S. A further QR of [A′   b′][A' \;\, b'] leaves at most dSd_S rows and a scalar residual, a constant, and is worth doing when the factor is to be stored or eliminated again.

A linear term in the row space stays there. Suppose the linear term of the eliminated factors is of the form (ηk,ηS)=[Ak   AS]⊤u(\eta_k, \eta_S) = [A_k \;\, A_S]\transpose u for some vector uu. Write Q⊤u=(u1,u2)Q\transpose u = (u_1, u_2), split as the rows of the reduced matrix are. Then

[ηkηS]=[RT0A′]⊤[u1u2]=[R⊤u1T⊤u1+A′⊤u2], \begin{bmatrix} \eta_k \\ \eta_S \end{bmatrix} = \begin{bmatrix} R & T \\ 0 & A' \end{bmatrix}\transpose \begin{bmatrix} u_1 \\ u_2 \end{bmatrix} = \begin{bmatrix} R\transpose u_1 \\ T\transpose u_1 + A'^\top u_2 \end{bmatrix} ,

so y=R−⊤ηk=u1y = R^{-\top} \eta_k = u_1, and the new factor’s linear term is ηS−T⊤y=A′⊤u2\eta_S - T\transpose y = A'^\top u_2. It is again in the row space of the factor’s rows, and it can be folded into the right-hand side, as Linear terms says. Elimination never creates a linear term that cannot be folded. One that cannot be folded was there from the start.

For example, take two scalars with a prior v1=1\tangent_1 = 1 and an odometry v2−v1=1\tangent_2 - \tangent_1 = 1, both of unit variance: the factors [ 1   0∣1 ][\,1 \;\, 0 \mid 1\,] and [ −1   1∣1 ][\,{-1} \;\, 1 \mid 1\,], with no linear term. Eliminating v1\tangent_1 reduces their rows to

[2−1/2001/22]. \begin{bmatrix} \sqrt2 & -1/\sqrt2 & 0 \\ 0 & 1/\sqrt2 & \sqrt2 \end{bmatrix} .

The first row is the conditional v1=v2/2\tangent_1 = \tangent_2 / 2, the second the new factor 12(v2/2−2)2\tfrac12 (\tangent_2 / \sqrt2 - \sqrt2)^2 on v2\tangent_2, minimized at v2=2\tangent_2 = 2, which gives v1=1\tangent_1 = 1. Its matrix, 12\tfrac12, is the Schur complement 1−1⋅12⋅11 - 1 \cdot \tfrac12 \cdot 1 of Λ=[2−1−11]\Lambda = \left[\begin{smallmatrix} 2 & -1 \\ -1 & 1 \end{smallmatrix}\right], so the marginal variance of v2\tangent_2 is 22: one unit from the prior, one from the odometry.

Order, fill and the elimination tree#

Which factors involve which blocks is recorded by the factor structure, a bipartite graph with a node for each block of variables and each factor, and an edge between a factor and every block it involves. Eliminating kk removes kk and the factors joined to it, and adds one factor joined to the whole separator. Blocks that shared no factor may now share one, and the new nonzero blocks of the matrix this creates are its fill. The answer does not depend on the order of elimination; the cost does, entirely.

The factor structure of a star
f0f_0 hh f1f_1 f2f_2 f3f_3 l1l_1 l2l_2 l3l_3
  • Variable
  • Factor
  • involves
The factor structure of a star. Each variable is a circle and each factor a square, with a line from a factor to every variable it involves. Eliminating hh first would join l1l_1, l2l_2 and l3l_3 in one new factor; eliminating each leaf first joins it to nothing new.

In the star, eliminating the hub hh first creates a factor over all the leaves at once, and with nn leaves everything after it is dense work, of order n3n^3. Eliminating the leaves first creates, for each, a new factor on hh alone, and the hub is eliminated last in a problem of one block: order nn. Finding the order with the least fill is NP-hard, but cheap heuristics do well. Minimum degree eliminates, at each step, a block whose separator is then smallest, and its approximate variants work on the factor structure without forming the matrix. An order may also be constrained to eliminate chosen blocks last, which the reductions below need.

The separators depend on the factor structure and the order alone, not on any number, so the elimination can be planned before it is performed. Give each block kk a parent: the block of its separator that is eliminated first after kk, which is the block its new factor will be collected with next. The elimination tree has a node for each block and an edge from each block’s parent to the block. Its roots, which have no parent, are the blocks eliminated last, one in each connected part of the factor structure; its leaves, which are no block’s parent, are eliminated before anything joined to them. The elimination of a block waits only on the blocks below it in the elimination tree, so disjoint subtrees can be eliminated independently.

The elimination tree of a star
hh rootl1l_1 l2l_2 l3l_3
  • Variable
  • parent of
The elimination tree of a star. The order l1,l2,l3,hl_1, l_2, l_3, h. Each leaf's separator is {h}\{h\}, so hh is the parent of all three, and an arrow runs from a parent to each of its children. The root hh, eliminated last, has no incoming arrow; the leaves of the tree, eliminated first, have no outgoing one.

The order, the elimination tree and the separators together are the symbolic factorization: everything about the elimination that does not depend on the numbers in the rows. It is computed once and reused for as long as the factor structure stays the same. An optimizer that relinearizes at every iteration changes the numbers in every factor but not which factors involve which blocks, so it plans the elimination once; so does a program that solves many problems of the same shape.

Cliques and the junction tree#

Eliminating one small block at a time does the arithmetic in many small pieces. Some blocks can be eliminated together, as one larger block, with no more fill and the same result.

Call two blocks joined when some factor involves both, counting the new factors that elimination creates as well as the original ones. When a block kk is eliminated, its factors are joined to all of SkS_k, its separator, and they leave a new factor on the whole of SkS_k. So every two blocks of {k}∪Sk\{k\} \cup S_k are joined: it is a clique, in the sense of graph theory, and it is the set of blocks that the rows of kk’s conditional involve.

Now let cc be a child of kk in the elimination tree. The new factor of cc involves all of ScS_c, which contains kk, and is collected when kk is eliminated, so Sc∖{k}⊆SkS_c \setminus \{k\} \subseteq S_k. When the two are equal,

Sk=Sc∖{k},(11) S_k = S_c \setminus \{k\} , \tag{11}
(11)

the clique of kk, {k}∪Sk\{k\} \cup S_k, is the clique of cc, {c}∪Sc\{c\} \cup S_c, without cc. It adds no block to it. Eliminating cc and kk together, as one block (c,k)(c, k) by Lemma 10, then has the separator SkS_k and leaves the same new factor and the same conditionals as eliminating them in turn. In fact it performs the same reflections: those that triangularize cc’s columns leave unchanged the rows that are zero there, and what remains in kk’s columns afterwards is exactly the rows that kk’s own elimination would have stacked. A chain of blocks, each related to the next by (11), is eliminated as one block in the same way. If two children of kk both satisfy (11), kk joins either one.

Grouping the blocks along such chains gives the maximal cliques: each group, together with its separator, is a clique that no other contains. The junction tree has a node for each group and an edge from the group that contains the parent of its last block to the group. Each node eliminates its frontal blocks, the group, and shares its separator with its parent: a block that two cliques contain is contained in every clique on the path between them, so what a clique shares with any clique outside its own subtree lies in its separator. The groups must be eliminated in an order that keeps each one’s blocks consecutive, children before parents, which a postorder of the junction tree does.

For example, take a small map of three poses x1,x2,x3x_1, x_2, x_3 and two landmarks l1,l2l_1, l_2. A prior fixes x1x_1, odometry joins consecutive poses, a loop closure joins x1x_1 to x3x_3, and each landmark is seen from two poses.

The factor structure of a small mapprior on x1odometry x1 to x2odometry x2 to x3loop closure x1 to x3l1 seen from x1l1 seen from x2l2 seen from x2l2 seen from x3
x1x_1 x2x_2 x3x_3 l1l_1 l2l_2
  • Variable
  • Factor
  • involves
The factor structure of a small map. Three poses x1,x2,x3x_1, x_2, x_3 and two landmarks l1,l2l_1, l_2. Each variable is a circle and each factor a square, with a line from a factor to every variable it involves: a prior on x1x_1, odometry between consecutive poses, a loop closure between x1x_1 and x3x_3, and two sightings of each landmark.

Eliminating in the order l1,l2,x1,x2,x3l_1, l_2, x_1, x_2, x_3 gives the separators and the elimination tree below. Eliminating l1l_1 joins x1x_1 and x2x_2, which already were, and l2l_2 joins x2x_2 and x3x_3, so the order creates no fill.

The elimination tree of the map, grouped into cliques
x3x_3 S=∅S = \varnothingx2x_2 S={x3}S = \{x_3\}x1x_1 S={x2,x3}S = \{x_2, x_3\}l2l_2 S={x2,x3}S = \{x_2, x_3\}l1l_1 S={x1,x2}S = \{x_1, x_2\}
  • Clique of x1,x2,x3x_1, x_2, x_3
  • Clique of l1l_1
  • Clique of l2l_2
  • parent of
The elimination tree of the map, grouped into cliques. The order l1,l2,x1,x2,x3l_1, l_2, x_1, x_2, x_3, with each block's separator beside it and an arrow from each parent to its children. The colours are the cliques: x2x_2 and x3x_3 each have a child whose separator is their own with themselves added, so the chain x1,x2,x3x_1, x_2, x_3 is one clique, eliminated as one block; l1l_1 and l2l_2 are cliques of one block each.

Both x1x_1 and l2l_2 have the separator {x2,x3}\{x_2, x_3\}, which is {x2}∪Sx2\{x_2\} \cup S_{x_2}, and Sx2={x3}S_{x_2} = \{x_3\} is {x3}∪Sx3\{x_3\} \cup S_{x_3} with x3x_3 removed, so (11) holds for x2x_2 with either child, and for x3x_3 with x2x_2. Taking the child x1x_1 makes the chain x1,x2,x3x_1, x_2, x_3 one group. The landmarks stay groups of one block. The junction tree has three cliques.

The junction tree of the map
{x1,x2}\{x_1, x_2\}{x2,x3}\{x_2, x_3\} x1,x2,x3x_1, x_2, x_3 rootl1∣x1,x2l_1 \mid x_1, x_2 l2∣x2,x3l_2 \mid x_2, x_3
  • Clique of x1,x2,x3x_1, x_2, x_3
  • Clique of l1l_1
  • Clique of l2l_2
  • parent of
The junction tree of the map. Each clique is a box listing the blocks it eliminates, then, after the bar, its separator. An arrow runs from each clique to its children, labelled with the child's separator: the blocks the two cliques share. Each clique is eliminated by one factorization, the children before the root.

Eliminating it takes three factorizations instead of five. Each landmark’s is unchanged: the rows of its two sightings, reduced to a conditional and a new factor on its separator. The root’s stacks the prior, the odometry, the loop closure and the two new factors into rows over (x1,x2,x3)(x_1, x_2, x_3), and triangularizes them in one dense factorization, where eliminating the poses one at a time would have taken three smaller ones. The arithmetic is the same; done in fewer, larger dense operations, it runs faster.

What the eliminated problem answers#

Eliminating every block in turn, by part 1 of Lemma 10, leaves only conditionals and a constant. Stacked in the order of elimination, the conditionals’ rows form one block upper-triangular matrix RR with R⊤R=A⊤AR\transpose R = A\transpose A in that order, and right-hand sides d−yd - y; every computation with RR becomes a traversal of the elimination tree.

computestraversalwhat it is for
the minimizer v∗\tangent^*from the roots to the leaves: each block solves its conditional given its separator’s valuesthe minimum of (9)
R−⊤cR^{-\top} cfrom the leaves to the rootsa linear term’s pushes yy, and the first half of a normal-equations solve
R−1zR^{-1} zfrom the roots to the leavesa draw from N(0,(A⊤A)−1)\mathcal N(0, (A\transpose A)^{-1}) when zz is standard normal
∑ilog⁡∣Rii∣\sum_i \log \lvert R_{ii} \rvertnone12log⁡det⁡A⊤A\tfrac12 \log \det A\transpose A

The minimum is the sum of the constants, and the decrease from v=0\tangent = 0 is 12∣Rv∗∣2\tfrac12 \lvert R \tangent^* \rvert^2 by (8). Eliminating by integration instead, by part 2, gives

∫Rde−ϕ(v) dv=(2π)d/2 e−ϕ(v∗)∏i∣Rii∣−1.(12) \int_{\R^\dimension} e^{-\phi(\tangent)} \, \dd \tangent = (2\pi)^{\dimension / 2}\, e^{-\phi(\tangent^*)} \prod_i \lvert R_{ii} \rvert^{-1} . \tag{12}
(12)

Partial elimination. Eliminating only some blocks EE and keeping the rest, KK, leaves the conditionals of EE and the factors on KK, old and new. The order is then constrained to put KK last, and only the factors joined to a block of EE, directly or through new factors, are ever read.

Corollary 13(Marginals by elimination).

Let ϕ\phi be a sum of factors over blocks E∪KE \cup K whose rows have rank d\dimension, the number of their columns, so that e−ϕe^{-\phi} is proportional to a normal density pp on Rd\R^\dimension. Eliminate the blocks of EE one at a time by part 2 of Lemma 10, in any order, and let ϕK\phi_K be the sum of the factors left on KK. Then e−ϕKe^{-\phi_K} is proportional to the marginal density of pp on KK: its precision is the matrix of ϕK\phi_K, the Schur complement of ΛEE\Lambda_{EE} in Λ\Lambda, and its mean is the minimizer of ϕK\phi_K.

Proof.

By part 2 of Lemma 10, applied once for each block of EE, the integral of e−ϕe^{-\phi} over vE\tangent_E is a constant times e−ϕKe^{-\phi_K}, and the marginal density is that integral normalized. ϕK\phi_K is quadratic with the matrix of part 3, applied repeatedly, which is the Schur complement of ΛEE\Lambda_{EE} in Λ\Lambda, positive definite since Λ\Lambda is; a normal density’s kernel with precision PP and minimizer μ\mu is e−12(v−μ)⊤P(v−μ)e^{-\frac12 (\tangent - \mu)\transpose P (\tangent - \mu)} up to a constant.

∎

The marginal’s precision, covariance and mean follow from one more factorization of the factors on KK, which brings them to a single triangular root WW with a right-hand side: the precision is W⊤WW\transpose W, the covariance W−1W−⊤W^{-1} W^{-\top}, and ∑ilog⁡∣Wii∣\sum_i \log \lvert W_{ii} \rvert is half the log-determinant of the precision. A root that is to be read as a whitening must often be lower triangular, with a positive diagonal, which QR does not give directly: factor the rows with the order of KK’s coordinates reversed, reverse both the rows and the columns of the upper-triangular result, and change the sign of every row whose diagonal entry is negative. Reversal is a permutation PP, with P⊤P=IP\transpose P = I, and a change of sign is a diagonal orthogonal matrix, so the result WW has W⊤WW\transpose W equal to the original matrix.

Eliminating from some factors only. The reductions above eliminate from the whole of (9). A different question keeps the factors not joined to EE out of it: which single factor on KK can replace those joined to EE, without changing the minimum, or the integral, over EE? Split ϕ=ϕ∋E+ϕ∌E\phi = \phi_{\ni E} + \phi_{\not\ni E} into the factors joined to EE and the rest. Since the rest does not involve vE\tangent_E,

min⁡vEϕ=(min⁡vEϕ∋E)+ϕ∌E,∫e−ϕ dvE=e−ϕ∌E∫e−ϕ∋E dvE,(14) \begin{gathered} \min_{\tangent_E} \phi = \Bigl(\min_{\tangent_E} \phi_{\ni E}\Bigr) + \phi_{\not\ni E} , \\ \int e^{-\phi} \, \dd \tangent_E = e^{-\phi_{\not\ni E}} \int e^{-\phi_{\ni E}} \, \dd \tangent_E , \end{gathered} \tag{14}
(14)

so the replacement is the elimination of EE from ϕ∋E\phi_{\ni E} alone, with the linear terms of EE’s blocks and the separator’s linear terms that came from those factors. Eliminating EE from the whole of ϕ\phi would instead fold ϕ∌E\phi_{\not\ni E} into the new factors, and a problem that kept those factors as well would count them twice.

Damping#

A step computed from (1) is the minimizer of a model, and a model is often trusted only near v=0\tangent = 0. Damping penalizes the step’s length, adding 12λ v⊤Dv\tfrac12 \lambda\, \tangent\transpose D \tangent for a λ≥0\lambda \ge 0 and a positive diagonal DD, so that the minimizer solves (A⊤A+λD) v=A⊤b−η(A\transpose A + \lambda D)\, \tangent = A\transpose b - \eta. The penalty is a sum of squares of its own,

12λ v⊤Dv=∑k12∣λ Dk1/2vk−0∣2,(15) \tfrac12 \lambda\, \tangent\transpose D \tangent = \sum_k \tfrac12 \bigl\lvert \sqrt\lambda\, D_k^{1/2} \tangent_k - 0 \bigr\rvert^2 , \tag{15}
(15)

one factor on each block kk with DkD_k its part of DD, so damping appends rows and nothing else: each new factor is joined to one block, creates no fill, and leaves the factor structure, and so the symbolic factorization, unchanged. It also makes every block’s rows of full rank when λ>0\lambda > 0.

Built on by