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.
The steps and the Gaussians of the notes before this one end in the normal equations of a function of a vector that is half a sum of squared affine residuals, plus a linear term,
which is to be minimized, integrated as , or reduced to a function of some of its variables. Forming the matrix 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 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 , minimizing (1) is the linear least-squares problem. Its minimizer solves the normal equations
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 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 is orthogonal if . It preserves lengths, so it can be applied to the residual without changing the problem, , and its condition number is one, so applying it amplifies no error. The orthogonal matrices used here are reflections: below fixes every vector orthogonal to and sends to , so it mirrors space in the hyperplane orthogonal to . A tuple of vectors, such as , stands for the column vector that stacks them, above .
For a nonzero , the Householder reflection
is symmetric and orthogonal. For a nonzero , let , with , and let equal except in its first entry, . Then , and
the vector with first entry and every other entry zero.
is symmetric because is, and
For the second part, differs from only in its first entry, by , and , so and
The product is , which is not negative, so , which is positive. Then
Either sign of would do, as long as ; the one chosen makes a sum of two numbers of the same sign. The other sign subtracts them, and when is already close to a multiple of the first coordinate vector they nearly cancel, and 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.
Let , with and nonzero. Then
so that
for every and . In particular, leaves the first entries of every vector unchanged, and fixes every vector whose other entries are zero:
The norms agree, , and the leading zeros of meet , so
Therefore
Read column by column, with each coordinate vector in turn, this is the block form.
∎The triangular root#
Let be an matrix of rank and . There is an orthogonal matrix with
an upper-triangular matrix with a nonzero diagonal, and . For every , , and .
The matrix is built from reflections, one for each column of , each of them made by Lemma 3 to reduce one column, and each leaving the columns already reduced alone by Lemma 4. Let and for , with chosen as follows. Suppose that each of the first columns of is zero below its diagonal entry, which holds for since there are none. Let be the entries of column of in rows to . Then : otherwise the first columns of would all lie in the span of the first coordinate vectors, and so be linearly dependent, but they are the first columns of , which has rank since each is invertible. Take and for from Lemma 3, and let with , its first entries zero. By Lemma 4, leaves rows to of unchanged, and its first columns too, since each is zero below row ; and it maps column ’s entries in rows to to followed by zeros. So the first columns of are zero below their diagonal entries.
After steps, has the form of the theorem, with upper triangular with diagonal entries , each nonzero. Each is symmetric and orthogonal, so is orthogonal and . Then
and
The minimizer of therefore solves the triangular system , and the minimum is . is a square root of the normal equations’ matrix, , computed without forming that matrix, and . 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 ,
the sum being empty for , in about operations, and backward stably; a lower-triangular one, such as , by forward substitution, from the first unknown down. A zero diagonal entry means does not have rank : 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
The first column is , with and , so and , with . maps each column of to , so the first column goes to , as Lemma 3 says, and the others follow with and :
Together,
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 , with and , so and , with , and for . By Lemma 4, leaves the first row, , alone, and the first column, , which is of the form . On the rest it acts as , which maps to :
Together,
So , and . Back substitution gives the minimizer,
and the minimum of is . Indeed, and with the root as the theorem says,
The second diagonal entry of is negative, which the sign rule of Lemma 3 allows and the theorem does not mind. Changing the sign of a row of , which is multiplying by a diagonal matrix of signs, changes nothing in the theorem, so a positive diagonal can be had when it is wanted.
Neither nor any is formed. A reflection is applied to a vector of entries as , with , in about operations, and only the vectors are kept, if is needed again at all. Step applies one to the last columns of , in rows to , so the reduction takes about operations. Forming and factoring it takes about , so when is much larger than the reflections cost twice as much, which is the price of the digits kept. Applying them to alongside gives and in the same pass.
Linear terms#
A linear term in (1) is not a squared residual, but it can be carried along. With and from Theorem 5 and , the solution of the forward substitution , so that , completing the square gives
So is minimized at , which solves , and the decrease from is
since . Two things change with the linear term.
- It needs every direction determined. When has rank , is bounded below whatever is. When it does not, is bounded below only if lies in the row space of , and the minimizer is then not unique. The rank condition is checked on the diagonal of , as before.
- It is solved at . The part of that comes from is , one triangular solve at . The part that comes from is , two, and is as sensitive as a solve of the normal equations: only the factor was computed at . A linear term known to be for some vector is better folded into , as , before factoring.
With empty, is linear and the problem is unbounded unless ; with and 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 , with block the vector .
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 is therefore described by three things:
- the set of the blocks it involves, those whose columns are not all zero in its rows;
- its rows , keeping only the columns of the blocks it involves;
- its right-hand side .
Its residual is , where stacks the blocks of . Stacking the rows of every factor, with zeros put back in the columns of the blocks it does not involve, gives back and . The odometry in the example at the end of this section, , is a factor with , and .
The linear term needs no factors. It splits into one piece for each block, , and each piece involves a single block, so it never ties two blocks together. It is kept as a vector for each block, and the problem (1) is
The linearization of a sum of squares is such a problem, with one factor for each term: the rows over the blocks of the term’s variables , the right-hand side , and the linear term , 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 is zero. Its block is the sum, over the factors that involve both and , of the product of their columns for , transposed, with their columns for . It is zero when no factor involves both blocks.
Eliminating a block removes it from the problem. Apart from the linear term , only the factors that involve depend on . The other blocks that those factors involve form the separator of . Stack the rows of those factors into one matrix , where holds their columns for , their columns for the blocks of (zero where a factor does not involve one of them), and their right-hand sides. The lemma concerns these factors together with the linear terms of and of , where stacks the vectors of the blocks of .
Let
with of rows and of rank , and let an orthogonal bring the rows to
with a upper-triangular matrix with a nonzero diagonal. With ,
where
and . Consequently:
- for every , , attained only at ;
- for every , ;
- with in blocks, the matrix of is the Schur complement, , and its gradient at zero is , with the gradient of at zero.
Since preserves lengths, the squares are
Write . Since ,
and completing the square in ,
which together give the decomposition. Only its first term depends on ; it is zero exactly at the point of part 1, since is nonsingular, which proves part 1, and the substitution turns its integral into that of a standard normal density’s kernel, of volume , times , which proves part 2. For part 3, is orthogonal, so is also the product of the reduced columns with themselves: , and , whence
In the same way and , so
which is the gradient of at zero, since .
∎The first term of the decomposition is a conditional: it says what is once is known. The second, , is a new factor on the separator, with the linear term pushed onto the separator’s blocks, and it replaces every factor that involved . The constant , and when is reduced further, depend on nothing. The problem now has one block fewer and the same form. Minimizing over and integrating over it leave the same new factor, and differ only in a constant, . Part 3 says that the new factor is what Gaussian elimination of block from the normal equations would have produced, reached through square roots instead: the matrix is never formed, and nothing is inverted but triangular blocks.
The new factor has rows, which may be more than the separator’s dimension . A further QR of leaves at most 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 for some vector . Write , split as the rows of the reduced matrix are. Then
so , and the new factor’s linear term is . 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 and an odometry , both of unit variance: the factors and , with no linear term. Eliminating reduces their rows to
The first row is the conditional , the second the new factor on , minimized at , which gives . Its matrix, , is the Schur complement of , so the marginal variance of is : 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 removes 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.
- Variable
- Factor
- involves
In the star, eliminating the hub first creates a factor over all the leaves at once, and with leaves everything after it is dense work, of order . Eliminating the leaves first creates, for each, a new factor on alone, and the hub is eliminated last in a problem of one block: order . 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 a parent: the block of its separator that is eliminated first after , 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.
- Variable
- parent of
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 is eliminated, its factors are joined to all of , its separator, and they leave a new factor on the whole of . So every two blocks of are joined: it is a clique, in the sense of graph theory, and it is the set of blocks that the rows of ’s conditional involve.
Now let be a child of in the elimination tree. The new factor of involves all of , which contains , and is collected when is eliminated, so . When the two are equal,
the clique of , , is the clique of , , without . It adds no block to it. Eliminating and together, as one block by Lemma 10, then has the separator 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 ’s columns leave unchanged the rows that are zero there, and what remains in ’s columns afterwards is exactly the rows that ’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 both satisfy (11), 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 and two landmarks . A prior fixes , odometry joins consecutive poses, a loop closure joins to , and each landmark is seen from two poses.
- Variable
- Factor
- involves
Eliminating in the order gives the separators and the elimination tree below. Eliminating joins and , which already were, and joins and , so the order creates no fill.
- Clique of
- Clique of
- Clique of
- parent of
Both and have the separator , which is , and is with removed, so (11) holds for with either child, and for with . Taking the child makes the chain one group. The landmarks stay groups of one block. The junction tree has three cliques.
- Clique of
- Clique of
- Clique of
- parent of
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 , 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 with in that order, and right-hand sides ; every computation with becomes a traversal of the elimination tree.
| computes | traversal | what it is for |
|---|---|---|
| the minimizer | from the roots to the leaves: each block solves its conditional given its separator’s values | the minimum of (9) |
| from the leaves to the roots | a linear term’s pushes , and the first half of a normal-equations solve | |
| from the roots to the leaves | a draw from when is standard normal | |
| none |
The minimum is the sum of the constants, and the decrease from is by (8). Eliminating by integration instead, by part 2, gives
Partial elimination. Eliminating only some blocks and keeping the rest, , leaves the conditionals of and the factors on , old and new. The order is then constrained to put last, and only the factors joined to a block of , directly or through new factors, are ever read.
Let be a sum of factors over blocks whose rows have rank , the number of their columns, so that is proportional to a normal density on . Eliminate the blocks of one at a time by part 2 of Lemma 10, in any order, and let be the sum of the factors left on . Then is proportional to the marginal density of on : its precision is the matrix of , the Schur complement of in , and its mean is the minimizer of .
By part 2 of Lemma 10, applied once for each block of , the integral of over is a constant times , and the marginal density is that integral normalized. is quadratic with the matrix of part 3, applied repeatedly, which is the Schur complement of in , positive definite since is; a normal density’s kernel with precision and minimizer is up to a constant.
∎The marginal’s precision, covariance and mean follow from one more factorization of the factors on , which brings them to a single triangular root with a right-hand side: the precision is , the covariance , and 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 ’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 , with , and a change of sign is a diagonal orthogonal matrix, so the result has 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 out of it: which single factor on can replace those joined to , without changing the minimum, or the integral, over ? Split into the factors joined to and the rest. Since the rest does not involve ,
so the replacement is the elimination of from alone, with the linear terms of ’s blocks and the separator’s linear terms that came from those factors. Eliminating from the whole of would instead fold 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 . Damping penalizes the step’s length, adding for a and a positive diagonal , so that the minimizer solves . The penalty is a sum of squares of its own,
one factor on each block with its part of , 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 .
Built on by
- Linearization and elimination A density query is linearized at a batch of points into factored least-squares problems over its free quantities, by its residuals or by its information roots, and each problem is eliminated in square-root form on the host into a step, marginals, an evidence, draws, or a retirement's replacement; the Levenberg–Marquardt method iterates the steps to the mode.
- What elimination leaves Integrating a block of variables out of an improper Gaussian factor, by the elimination of its rows, leaves an improper Gaussian factor on the blocks it was tied to, of any rank and exactly; it is a normal when it determines them, and the factor is the exact answer when it does not.
- The Levenberg–Marquardt method A Gauss–Newton step is trusted only as far as the linearization is; damping shortens it, the ratio of the decrease obtained to the decrease promised says whether to trust it more or less, and a stopping rule on the promise alone tells convergence from rounding.
- The Laplace approximation A Laplace approximation replaces a density near a point by a Gaussian in the chart there; taken in a chart it approximates the density times the chart's volume, its mean, marginals, draws and evidence are computations on the linearization's rows, and its covariance omits curvature of the order of the noise's variance on a curved space.
- Examples that run: Mathematics The model the examples share, a trajectory of poses on SE(3) with landmarks, odometry and sightings, generated from its own joint law and queried for the rest; a Levenberg–Marquardt method on its linearization, with its damping, schedule and stopping rule; the calibration of a Laplace approximation that data drawn from the model lets an example check; and a sliding window that retires a pose and the landmarks it alone sees at every tick.
- Linearization and elimination: Mathematics How a query of a model is linearized at a point into factors of whitened rows and linear terms over its free quantities' tangent coordinates, and how eliminating those factors gives the step of a Gauss–Newton or Levenberg–Marquardt method, a Laplace approximation's marginals, and a retirement's replacement, an improper Gaussian that is the update and prediction of a Kalman filter when it determines the blanket; and how the roots of the expected information give a second assembly, for Fisher scoring of free scales.
- Linearization and elimination: Implementation Two crates, `skoro-elimination`, which eliminates factored least-squares problems in square-root form on the host, and `skoro-linearize`, which linearizes a query at a batch of points into such problems, by its residuals or by its information roots, and computes a retirement's replacement as an improper Gaussian; with the few additions to the core and the normal that they need.