SLAM: Factor Graphs and Sparsity

A robot drives a 100 m loop past 12 landmarks: 147 unknowns and 98 measurements. One loop closure moves every pose at once and takes the map from 2.35 m to 0.14 m off. Only 150 of the 1,431 blocks of the matrix are non-zero, so a good order solves it in about 11,500 operations instead of a million.

Switch the loop closure off and on. Then pick an elimination order and watch the factor L fill in. Then we build it piece by piece: MAP and factors, the graph, the matrix, the anchor, elimination, ordering, marginalization and the back ends.

You need Lecture 9 (Gauss-Newton and the normal equations) and Lecture 12 (loop closures). We build the rest from zero.

Lecture 13 of 14 in our follow-along of MIT 16.485, Visual Navigation for Autonomous Vehicles (VNAV, taught by Luca Carlone). Every idea is re-taught here in our own words and devices. Previous: Lecture 12, place recognition. Next: Lecture 14, robust SLAM.

Close the loop, then order the solve

Illustrative toy: the drive of Lecture 12 (41 poses, odometry with 3 cm noise and a 0.4° heading bias per step). 12 landmarks are seen within 6.5 m by range (10 cm noise) and bearing (1°). Gauss-Newton runs in your browser. One cell per variable; operation counts are the sum of squared column counts of L.

Chapter 0

One Closure Moves Every Pose

Add the loop closure and measure how far each old pose moves

Lecture 12 ended with a robot back at its start. Its odometry says it is 4.64 m away. Place recognition says it is home. The back end must make both true at once, and the only way is to move poses the robot left minutes ago.

Close the loop, measure every move

The pink dashed rectangle is the true route. The purple path is the map. Close the loop, then read the bars: one bar per pose, its height the distance that pose moved.

Illustrative toy, the same drive as the hero. Both maps are full Gauss-Newton solutions over all 41 poses and 12 landmarks. A prior pins pose 0 (Chapter 4).

Every pose moves, not only the last one. Pose 10 moves 0.61 m, pose 20 moves 1.85 m and pose 40 moves 4.64 m. The gap at the start shrinks from 4.64 m to 4 mm.

So the back end keeps every pose and every landmark as an unknown, and solves for all of them from every measurement. Estimating the whole past this way is called smoothing. It is a maximum a posteriori (MAP) problem: find the map that is most probable given all the data.

That sounds expensive. A city map with 1,000 poses in 3D (6 numbers each) and 5,000 landmarks (3 numbers each) has 21,000 unknowns. A dense Cholesky solve of that system costs about N3/3 = 3.1 × 1012 operations. At 10 billion operations a second, that is about 5 minutes for one Gauss-Newton step.

Real back ends solve problems of this size far faster. The reason is one fact: each measurement touches only two unknowns. The rest of this lesson turns that fact into speed.

Symptom: the solve time grows much faster than the map.

Measure: count the non-zeros of the Cholesky factor L against those of the matrix H (Chapter 5).

Fix: keep the problem sparse and pick a good elimination order (Chapters 5 and 6).

The road

  1. MAP: multiply the factors, or add the squared residuals.
  2. The graph: variables, factors and the edges between them.
  3. Sparsity: the matrix H has the shape of the graph (the hero's purple cells).
  4. The anchor: why the map needs a prior on its first pose.
  5. Fill-in: eliminating a variable links its neighbours (the hero's warm cells).
  6. Ordering: the order decides the cost (the hero's four buttons).
  7. Marginalization: forget a variable and keep what it knew.
  8. Back ends: filter, fixed lag, full smoother, incremental.
  9. Showcase: drive the loop with each back end.
  10. Field guide: the formulas, the numbers, the code and the credit.
A verified loop closure arrives after a long drive. What does a smoothing back end do with it?

Chapter 1

SLAM Is a Product of Factors

Drag two positions and watch the product of factors and the sum of squares move together

Call everything we want to know X: every pose and every landmark. Call all the measurements Z. The best map is the X that makes p(X | Z), the probability of X given Z, largest.

Bayes' rule splits that probability into pieces. Each measurement gives one factor: a function of the few unknowns it depends on, large when they agree with it. Call factor number k φk, and the unknowns it touches Xk.

Say it aloud

X-hat equals the X that makes the product over k of phi-k of X-k largest.

X̂
X-hat the best map: all 41 poses and 12 landmarks of our toy, 147 numbers.
argmaxX
the X that makes it largest try maps X and return the map itself, not the value.
∏k
the product over k multiply one term for each factor: 98 factors in the toy.
φk(Xk)
phi-k of X-k factor k: how well its few unknowns Xk agree with its measurement, between 0 and 1.
In plain words

For a candidate map X, evaluate each factor phi-k on the few unknowns X-k it touches. Multiply all the results. The map with the largest product is X-hat.

With numbers

The device's guess x1 = 1.0 m, x2 = 2.0 m makes both odometry factors 1.000 and the closure factor 0.135. The product is 0.135.

Multiply three factors

A robot drives along a line: x0 = 0 is fixed, x1 and x2 are unknown. Two odometry steps say 1.0 m each; a closure says x2 is 1.8 m from x0. Drag the positions, or press Solve.

1.00
2.00

Illustrative: every factor has noise σ = 0.1 m. The sum is of squared residuals divided by σ2.

Each factor in SLAM is Gaussian: φk = exp(−½ ‖rk‖2), where the residual rk is the prediction minus the measurement, divided by the noise. Take minus the log of the product. The product becomes a sum, and the exponentials go away.

Say it aloud

X-hat equals the X that makes the sum over k of r-k of X-k squared, in the Sigma-k norm, smallest.

X̂
X-hat the same best map as above.
argminX
the X that makes it smallest minus a log turns largest into smallest.
Σk
the sum over k one term for each factor.
‖rk‖2Σk
r-k squared in the Sigma-k norm the residual rk (prediction minus measurement) weighted by its covariance Σk: rkT Σk−1 rk. For one number with noise σ, it is (r/σ)2.
In plain words

For each factor, compute the residual r-k, divide it by its noise and square it. Add these. The map with the smallest total is X-hat, the same map the product picked.

With numbers

With σ = 0.1 m: at the guess the residuals are 0, 0 and 0.2 m, so the total is (0.2/0.1)2 = 4, and exp(−4/2) = 0.135, the product above. At the best map, x1 = 0.933 m and x2 = 1.867 m, every residual is 0.067 m: the total is 1.33 and the product 0.513. The 0.2 m conflict splits three ways.

This is the weighted nonlinear least squares of Lecture 9, solved on the manifold of Lecture 10. SLAM adds size and structure, not a new objective.

Symptom: after the solve, the closure residual stays large while the odometry residuals are tiny.

Measure: the residuals divided by their σ, per factor type. Each should be about 1.

Fix: correct the covariances. A sensor with a σ that is too small wins every disagreement.

Why does maximizing the product of Gaussian factors give the same map as minimizing the sum of squared, noise-weighted residuals?

Chapter 2

Variables, Factors, Edges

Switch each kind of factor on and count what the solver must handle

A factor graph draws the product as a picture. It has two kinds of node. Variable nodes are the unknowns: poses as circles, landmarks as squares. Factor nodes are the measurements, drawn as small diamonds. An edge joins a factor to each variable it touches.

SLAM uses four kinds of factor:

Build the factor graph

Circles are poses, squares are landmarks, diamonds are factors. Switch each kind of factor on or off and read the counts.

Illustrative toy, the hero's drive. A pose has 3 unknowns (x, y, heading), a landmark 2. A landmark factor has 2 residual rows, the others 3.

Odometry and loop closures share one form, the between factor. Pose i has a position ti and a heading θi. The measurement z says where pose j sits as seen from pose i: an offset zt and a turn zθ.

Say it aloud

r-i-j equals R of theta-i transpose, times t-j minus t-i, minus z-t; stacked on theta-j minus theta-i minus z-theta.

rij
r-i-j the residual of the factor between poses i and j: three numbers, two in metres and one in radians.
R(θi)T
R of theta-i transpose turns a world vector into pose i's own frame (a turn by minus θi).
tj − ti
t-j minus t-i the step from pose i to pose j in world coordinates.
zt
z-t the measured step, in pose i's frame.
θj − θi − zθ
theta-j minus theta-i minus z-theta the heading part, wrapped to between minus 180° and 180°.
In plain words

Take the step from pose i to pose j in the world. Turn it into pose i's frame with R-transpose and subtract the measured step z-t. Do the same for the heading. The three numbers are the residual.

With numbers

With made-up numbers: pose i at (2, 1) m facing 90°, pose j at (2.3, 3.4) m facing 95°, and z = (2.5 m, 0 m, 0°). The step tj − ti is (0.3, 2.4). Turned by −90° it is (2.4, −0.3). The residual is (−0.1 m, −0.3 m, 5°), and 5° is 0.087 rad.

Read the counts in the device. Our toy has 53 variable nodes (41 poses and 12 landmarks) and 98 factors: 1 prior, 40 odometry, 56 landmark and 1 loop closure. They give 238 residual rows for 147 unknowns, so Gauss-Newton has more equations than unknowns. In 3D the same factor uses a pose in SE(3) and the log map of Lecture 10.

Symptom: the solver reports a singular system the moment a new landmark appears.

Measure: count the residual rows that touch each variable. A camera that sees a 3D landmark from one pose gives 2 rows for 3 unknowns: its depth is free.

Fix: add a landmark only after a second view, or give it a weak prior.

A SLAM problem has 5 poses and 3 landmarks. Each pose sees 2 landmarks. There is 1 loop closure and 1 prior. How many factors does the graph have?

Chapter 3

The Matrix Has the Shape of the Graph

Pick a factor and see the four blocks it writes into H

Gauss-Newton (Lecture 9) linearizes every residual and solves the normal equations Hδ = −g for a step δ. The matrix H is the information matrix. Each factor adds one piece to it. Call the Jacobian of factor k Jk: how its residual changes when each unknown moves. Call its weight, the inverse of its covariance, Wk.

Say it aloud

H equals the sum over k of J-k transpose, times W-k, times J-k.

H
H the information matrix: 147 by 147 in our toy, one row and column per unknown.
Σk
the sum over k add one piece for each of the 98 factors.
JkT
J-k transpose the Jacobian of factor k, turned on its side.
Wk
W-k the weight of factor k: the inverse of its covariance, 1/σ2 for one number.
Jk
J-k one row per residual of factor k, one column per unknown, and zero outside the columns of the variables it touches.
In plain words

For each factor, take its Jacobian J-k. It is zero except in the columns of its own variables. Multiply J-k transpose by W-k by J-k and add the result into H. It lands only where those variables meet.

With numbers

The odometry factor between x5 and x6 has a 3 × 147 Jacobian with two non-zero 3 × 3 blocks. Its piece fills 4 blocks of H: (x5, x5), (x5, x6), (x6, x5) and (x6, x6). The other 2,805 of the 53 × 53 block positions get nothing from it.

So block (a, b) of H is non-zero only if some factor touches both a and b. The matrix is the factor graph written as a table.

Write one factor into H

The grid is H, one cell per variable: poses 0 to 40, then the 12 landmarks. Pick a factor, or tap a cell, to see which factor wrote it.

Illustrative toy, the hero's drive with the loop closure. Cells are variable blocks: 3 × 3 for two poses, 2 × 2 for two landmarks.

Count them in our toy. The lower half of H, with the diagonal, has 1,431 blocks. 150 are non-zero: 53 on the diagonal, 40 from odometry, 56 from landmarks and 1 from the loop closure, 10.5%. The share falls as the map grows, because each new pose brings a few factors but a whole new row. A loop of 1,280 poses and 424 landmarks has 5,104 non-zero blocks out of 1.45 million: 0.35%.

Symptom: H looks dense and the solve is slow.

Measure: count the non-zero blocks in each row of H.

Fix: find the factor that touches many variables. It is often a dense prior left by marginalization (Chapter 7).

A pose graph has 6 poses and only odometry factors. How many blocks of H are non-zero, counting the diagonal and each off-diagonal pair once?

Chapter 4

Anchor the Map

Slide and turn the whole map, and watch the cost refuse to change

Slide the whole map 1 m east. Every measurement still agrees: each odometry step, each range and bearing, the closure. They all compare two things that moved together. So the problem has a whole family of best maps, one for each rigid move. This freedom is called gauge freedom.

Call the cost F: the sum of squared, noise-weighted residuals of Chapter 1. Call a rigid motion of the plane g: a shift and a turn.

Say it aloud

F of g applied to X equals F of X, for every rigid motion g.

F
F the cost: the sum of squared, noise-weighted residuals, with no prior.
g
g a rigid motion of the plane: a shift (2 numbers) and a turn (1 number).
g ∘ X
g applied to X move and turn every pose and every landmark by the same g.
X
X a map: all poses and landmarks.
In plain words

Move and turn every pose and landmark of X by the same g. Each residual compares two things that moved together, so none changes. F stays the same.

With numbers

The device's small graph has 9 poses and 3 landmarks (33 unknowns). Without a prior, F = 12.69 at the solution, and still 12.69 after a 1 m shift or a 10° turn.

Slide the whole map

Move both sliders. Then switch the prior on and move them again. The bars are the six smallest eigenvalues of H, on a log scale.

0.0
0

Illustrative: the hero's first 9 poses and the 3 landmarks they see. The prior holds x0 with σ = 1 mm and 0.06°. Eigenvalues are of H at the solution, computed in your browser.

In the matrix, a direction that does not change the cost is a direction u with Hu = 0. A plane has three independent rigid motions, so H has three zero eigenvalues. The small graph shows 3 eigenvalues below 10−11; the next one is 47.0. H then has no inverse, and Cholesky stops at a zero pivot.

The fix is a prior factor on the first pose: x0 = (0, 0, 0°) with a tiny σ. It picks one map out of the family. With it, the smallest eigenvalue is 2.54 and the solve works. The prior changes where the map sits, not its shape. In 3D a pose graph has 6 gauge directions. Monocular bundle adjustment has 7, because the scale is free too.

Symptom: Cholesky fails, or Gauss-Newton takes huge steps along the whole map.

Measure: the smallest eigenvalues of H. In 2D, three near zero means the gauge is free.

Fix: put a prior on one pose, or hold that pose fixed.

Monocular bundle adjustment has no prior. How many directions leave its cost unchanged?

Chapter 5

Eliminate One Variable, Link Its Neighbours

Step through a Cholesky factorization and watch each elimination add links

Never invert H. Its inverse is dense: in our toy all 1,431 blocks of H−1 are non-zero, against 150 in H. Instead, split H into a lower triangle L times its transpose. This is the Cholesky factorization.

Say it aloud

H equals L times L transpose.

H
H the information matrix of Chapter 3: symmetric, and positive definite once a prior anchors the map.
L
L the Cholesky factor: lower-triangular, zero above the diagonal.
LT
L transpose the same numbers mirrored: upper-triangular.
In plain words

Find the lower-triangular L whose product with L-transpose is H. Then solve L y = −g from the top row down, and L-transpose δ = y from the bottom row up. Each pass touches only the non-zeros of L.

With numbers

With made-up numbers: H = [[4, 2], [2, 5]] gives L = [[2, 0], [1, 2]]. Check: 2 × 2 = 4, 1 × 2 = 2, and 1 × 1 + 2 × 2 = 5.

Cholesky works one variable at a time. Eliminating a variable writes its column of L. In the graph it does one thing: it joins all of that variable's remaining neighbours to each other. A link that was not there before is fill-in, a new non-zero in L.

Eliminate, one variable at a time

Six poses drive a small loop and see two landmarks, A and B. Pick an order, then press Step. Warm links are fill-in.

Illustrative graph. Counts are blocks in the lower half of L with the diagonal, from symbolic elimination, checked against a numeric Cholesky.

The order matters. In the small graph, H has 19 non-zero blocks. Time order gives an L with 26 blocks: 7 fill-in. Eliminating x3 first gives 27. Always eliminating the variable with the fewest links gives 22: 3 fill-in.

Why does the busy one hurt? x3 touches x2, x4, A and B. Eliminating it links all six pairs of them. Two pairs had a link already, so one step adds 4 new blocks. Each new link then spreads as the elimination goes on.

Symptom: two maps of the same size solve at speeds ten times apart.

Measure: the non-zeros of L divided by the non-zeros of H.

Fix: change the elimination order (Chapter 6).

Why does a SLAM solver factor H as L LT instead of computing H−1?

Chapter 6

The Order Decides the Cost

Grow the loop and watch each order's cost pull away from the others

How much work is a sparse Cholesky? Each column of L updates the columns after it once for every pair of its non-zeros. Call the number of non-zeros below the diagonal in column j cj.

Say it aloud

The cost is about the sum over j of c-j squared.

cost
cost the number of multiply-adds in the factorization.
Σj
the sum over j one term for each column of L: 147 in our toy.
cj2
c-j squared cj is the number of non-zeros in column j below the diagonal.
In plain words

For each column of L, count its non-zeros under the diagonal and square the count. Add the squares. A dense N by N matrix has c-j = N − j, and the sum comes to about N3/3.

With numbers

Our toy has N = 147 unknowns, so a dense factor costs about 1.06 million. The four orders of the hero cost 11,503 (fewest links), 21,424 (landmarks first), 27,543 (random) and 56,630 (landmarks last).

The order with the least fill is NP-hard to find (Yannakakis, 1981). Solvers use fast greedy rules instead. Minimum degree always eliminates the variable with the fewest links next. AMD and COLAMD (Davis and co-authors, 2004) are fast approximate versions. COLAMD orders the columns of the Jacobian, so it never forms H. SciPy's COLAMD on our toy gives an L with 1,357 non-zero numbers; poses first, then landmarks, gives 2,717.

Grow the map

Each curve is one order. Drag the size slider; the ring marks that size on every curve.

1,280

Illustrative family of loops: n poses, a landmark every 3 poses seen by 5 poses in a row, one loop closure. Counts come from symbolic elimination in your browser.

Grow the loop and the orders separate. At 1,280 poses and 424 landmarks (4,688 unknowns), a dense factor costs 3.4 × 1010. Minimum degree costs 3.9 × 105, and doubling the map roughly doubles it. Landmarks last costs 1.2 × 109. Eliminating every pose first links all 424 landmarks to each other, and that dense block grows like the cube of their number.

The same rules hold for QR on the Jacobian, the route of square-root SAM (Dellaert and Kaess, 2006). Its triangle R has the pattern of LT.

Symptom: memory grows with the square of the number of landmarks.

Measure: the non-zeros in the landmark block of L.

Fix: eliminate landmarks before poses, or let COLAMD choose.

You eliminate every pose before any landmark. What happens to the cost as the map gets larger?

Chapter 7

Forget With the Schur Complement

Remove a variable and watch its neighbours become one dense prior

A long drive keeps adding poses. To bound the work, remove old ones but keep what they told us. That is marginalization: their information stays as a factor on the variables that remain.

Split the unknowns into the ones we keep, a, and the ones we remove, b. Split H the same way into four blocks: Haa, Hab, Hba and Hbb.

Say it aloud

S equals H-a-a minus H-a-b, times H-b-b inverse, times H-b-a.

S
S the Schur complement: the information on the kept variables a after b is gone.
Haa
H-a-a the block of H among the kept variables.
Hab
H-a-b the coupling from the kept variables to the removed ones; Hba is its transpose.
Hbb−1
H-b-b inverse the inverse of the removed variables' own block: small, so cheap.
Hba
H-b-a the coupling back from the removed variables to the kept ones.
In plain words

Start from the kept block H-a-a. Subtract what flowed through b: out along H-b-a, through H-b-b inverse, back along H-a-b. What is left, S, is a prior on a that holds everything b knew.

With numbers

With made-up numbers: three positions on a line, a prior on x1 and two odometry steps, each with σ = 1 m, give H = [[2, −1, 0], [−1, 2, −1], [0, −1, 1]]. Remove x2: Haa = [[2, 0], [0, 1]], Hab = (−1, −1), Hbb = 2. Then S = [[1.5, −0.5], [−0.5, 0.5]]. The new −0.5 links x1 and x3 directly: one step of variance 2 m2, the two 1 m2 steps added. S−1 gives x3 a variance of 3 m2, the same as the full problem.

S is what elimination leaves (Chapter 5), so marginalizing a variable links all its neighbours.

Marginalize a variable

Tap a variable, or use the buttons. It leaves the graph, and its neighbours get a warm prior that links all of them. Remove several and watch the prior grow.

Illustrative graph, the same as Chapter 5. The device draws only the pattern; the numbers of a prior follow the Schur complement above.

Marginalize x3: it touches x2, x4, A and B, so the prior links all 6 pairs, 4 of them new. Do this to every past pose and you get a filter, like EKF-SLAM. In our toy, after the drive, only pose 40 and the 12 landmarks remain, and all 91 blocks of their matrix are non-zero. The forgotten path ties every landmark to every other.

Bundle adjustment runs the Schur complement the other way. Each landmark touches only poses, so Hbb for all landmarks is block-diagonal and its inverse is cheap. Eliminate the landmarks first and solve the smaller reduced camera system on the poses (Triggs and co-authors, 2000). GraphSLAM (Thrun and Montemerlo, 2006) also removes the map first.

Symptom: a sliding-window solver gets slower the longer it runs.

Measure: the non-zero blocks of the marginal prior.

Fix: marginalize fewer links: drop weak observations of a pose before you marginalize it, or keep only keyframes.

An old pose sees 5 landmarks and nothing else. You marginalize it. How many new links appear among the 5 landmarks?

Chapter 8

Filter, Fixed Lag or Full Smoother

Choose what the back end keeps, then see whether the loop closure can still help

Three back ends differ in what they keep:

Choose what to keep

The loop closure arrives at pose 40. Choose a back end and read its map and its matrix: purple cells come from factors, warm cells from marginalizing.

Illustrative toy, the hero's drive. Each pose keeps the estimate it had when it left the window. We compute that estimate as the batch solve on the data so far. For a linear problem this equals exact marginalization; real fixed-lag smoothers also freeze the linearization point.

At the end of the drive the filter holds 13 variables, and 78 of its 91 blocks come from marginalizing. The fixed-lag smoother (W = 10) holds 22 variables, with 44 such blocks. The full smoother holds all 53, with 150 blocks and none from marginalizing. Only the full smoother still has pose 0, so only it can use the closure. Its map ends 0.14 m off; the other two end 2.35 m off.

A filter that keeps landmarks can still close a loop when it sees an old landmark again. It pays for that with its dense landmark block.

Does the full smoother slow down as it grows? Not if it updates its factor instead of rebuilding it. iSAM (Kaess and co-authors, 2008) updates the triangular factor with Givens rotations as measurements arrive. From time to time it reorders the variables. iSAM2 (2012) stores the factor as a Bayes tree. It re-eliminates only the part a new factor touches, and relinearizes only the variables that moved enough.

Our toy shows why this pays. With variables in creation order, a normal step re-eliminates 2 to 7 variables: 378 operations on average. The loop closure touches pose 0, so that step re-eliminates all 53: 11,503 operations. Over the drive the incremental solver spends 26,252 operations; solving the whole graph again at every step spends 109,286.

Symptom: a verified closure arrives and the map does not move.

Measure: check whether the old pose is still a variable in the back end.

Fix: keep keyframes in a full smoother, or close the loop through landmarks the state still holds.

A fixed-lag smoother keeps the last 10 poses. A loop closure links the newest pose to pose 0. What happens?

Chapter 9

Showcase: Drive the Back End

Play the drive with each back end and watch the map, the matrix and the cost per step

Here is the whole back end on the whole drive. At each step the robot adds a pose, its odometry and its landmark sightings. The back end you choose keeps what it keeps, solves, and pays for its factorization. At step 40 the loop closure arrives.

Run the back end

Press play. Try the incremental smoother, then the batch smoother, then the filter. Switch the closure off and see the last step change.

40

Illustrative toy, the hero's drive. Operations are the sum of squared column counts. The batch smoother re-factors everything in minimum-degree order. The incremental one re-eliminates only the affected part, in creation order, and reorders at the closure. The filter and fixed lag factor what they hold, prior included.

Three things to see. The incremental bars stay low until step 40, then one tall bar pays for the closure. The batch bars grow with the map at every step. The filter's bars are flat but high, because every pair of its 13 variables shares a link. At step 40 its map cannot close.

Chapter 10

Field Guide

Keep the formulas, the numbers and the code side by side

SLAM is MAP estimation over every pose and landmark. Gaussian factors turn it into a sum of squared residuals, and the factor graph shows which unknowns each one ties. H has the shape of that graph, so it is sparse. Anchor one pose, factor H in a fill-reducing order, and the cost grows about linearly with the map. Marginalize to forget, and pay with dense priors; keep the poses you need to close loops.

PieceFormulaNumber on this pageWatch out
MAPargmax ∏ φk = argmin Σ ‖rk‖2Σproduct 0.135 to 0.513honest covariances
Between factorR(θi)T(tj − ti) − zt(−0.1, −0.3) m, 5°wrap the angle
Information matrixΣ JkT Wk Jk150 of 1,431 blocksdense priors
GaugeF(g ∘ X) = F(X)3 zero eigenvalues; 2.54 with a prior7 for monocular BA
CholeskyH = L LTH−1 has all 1,431 blocksnever invert
Orderingcost ≈ Σ cj211,503 against 56,630; dense 1.06 millionposes first is cubic
MarginalizationHaa − Hab Hbb−1 Hbafilter: 91 of 91 blocksold poses are gone
Incrementalre-eliminate the affected part26,252 against 109,286a closure touches all

The core, as code

python
import numpy as np, scipy.sparse as sp
from scipy.sparse.linalg import splu

def gauss_newton_step(factors, X, offs, N):
    # factors: objects with .vars, .linearize(X) -> (r, [J_a for each var], W)
    rows, cols, vals, g = [], [], [], np.zeros(N)
    for f in factors:
        r, Js, W = f.linearize(X)
        for a, Ja in zip(f.vars, Js):
            g[offs[a]:offs[a] + Ja.shape[1]] += Ja.T @ W @ r
            for b, Jb in zip(f.vars, Js):          # only blocks where a and b meet
                blk = Ja.T @ W @ Jb
                i, j = np.meshgrid(np.arange(blk.shape[0]) + offs[a],
                                   np.arange(blk.shape[1]) + offs[b], indexing='ij')
                rows += list(i.ravel()); cols += list(j.ravel()); vals += list(blk.ravel())
    H = sp.csc_matrix((vals, (rows, cols)), shape=(N, N))  # duplicates add up
    lu = splu(H, permc_spec='COLAMD', diag_pivot_thresh=0,
              options=dict(SymmetricMode=True))  # fill-reducing order
    return lu.solve(-g), lu.L.nnz                         # step, and the fill you paid

We ran this on our toy at its solution. With COLAMD, L has 1,357 non-zero numbers; with the natural order (poses, then landmarks), 2,717. For production, GTSAM builds the same factor graph and runs iSAM2 for you.

Where it sits

Lecture 9 gave Gauss-Newton and Lecture 10 the steps on poses. Lecture 11 gave the drifting odometry and the sliding window, and Lecture 12 the verified loop closure. This lecture solves them together. Lecture 14 makes the back end survive a false closure.

Keep going

The takeaway. Each measurement touches two unknowns, so H has the shape of the graph and stays sparse. Anchor the map, factor H in a fill-reducing order, and update it incrementally: a loop closure then costs one re-solve of the loop, not a dense inverse of the world.

Now press Present or Teach. Explain why the product of factors becomes a sum of squares and why block (a, b) of H needs a factor on both. Say why the map needs a prior, and why the order changes the cost. Work the Schur complement on three positions. Then go back to the hero and say why landmarks last fills L and fewest links does not.

Credit

VNAV Lecture 13: SLAM, Factor Graphs and Sparsity
MIT 16.485 VNAV · Previous: place recognition · Next: robust SLAM · Back to Gleams