RL Theory
GraphSLAM and Factor Graphs
SLAM as graph optimization: poses as nodes, constraints as edges, factor graph representation, MAP estimation via nonlinear least squares, and the sparsity structure that makes large-scale mapping tractable.
Why This Matters
Simultaneous Localization and Mapping (SLAM) is the problem of building a map of an unknown environment while simultaneously tracking the agent's position within it. It is one of the most important problems in robotics: every autonomous vehicle, delivery robot, and AR headset solves some form of SLAM.
GraphSLAM reformulates SLAM as a graph optimization problem. Instead of maintaining a probability distribution over all poses (which is what filter-based SLAM does), GraphSLAM collects all constraints (odometry, landmark observations, loop closures) and solves for all poses simultaneously via nonlinear least squares. This batch approach produces more accurate results than filtering and naturally exploits sparsity in the constraint structure.
Mental Model
Imagine you walk through a building while recording your position at each step and noting observations of landmarks. Each step gives you a noisy estimate of the displacement (odometry). Each landmark observation gives you a noisy constraint between your current position and the landmark.
Build a graph: nodes are your poses at each time step plus landmark positions. Edges are the constraints from odometry and observations. Now find the configuration of all nodes that best satisfies all constraints simultaneously. This is a least-squares optimization problem, and its structure makes it efficiently solvable.
Formal Setup and Notation
SLAM as a Graphical Model
Let be the robot's poses and be the landmark positions. The SLAM problem seeks the maximum a posteriori (MAP) estimate:
where are observations and are odometry inputs.
Factor Graph
A factor graph is a bipartite graph with two types of nodes:
- Variable nodes: represent unknown quantities ()
- Factor nodes: represent probabilistic constraints between variables
Each factor connects to the variables it depends on. The joint distribution factorizes as:
where is the set of variables connected to factor .
SLAM Factors
The standard SLAM factor graph contains three types of factors:
- Prior factor: anchoring the initial pose
- Odometry factors: constraining consecutive poses via motion model
- Observation factors: constraining a pose and a landmark via observation model
Main Theorems
GraphSLAM as Nonlinear Least Squares
Statement
Under Gaussian noise assumptions, the MAP estimation problem is equivalent to a nonlinear least-squares problem:
where is the error function for factor , is the Mahalanobis norm, and is the noise covariance for factor .
Intuition
Taking the negative log of the posterior (which is a product of Gaussians) converts multiplication into summation and Gaussian exponents into squared Mahalanobis norms. Maximizing the posterior becomes minimizing the sum of squared errors. Each factor contributes one error term, weighted by the inverse of its noise covariance.
Why It Matters
This equivalence transforms SLAM from a probabilistic inference problem into an optimization problem, giving access to the entire toolbox of nonlinear least squares: Gauss-Newton, Levenberg-Marquardt, and their sparse variants. These are well-understood algorithms with convergence guarantees for well-conditioned problems.
Failure Mode
The equivalence requires Gaussian noise. Non-Gaussian noise (e.g., heavy-tailed sensor errors, outlier measurements from incorrect data associations) breaks the least-squares formulation. Robust variants use M-estimators (Huber, Cauchy kernels) instead of squared error to downweight outliers, but lose the clean Gaussian interpretation.
Solving the Optimization
Gauss-Newton Method
Linearize each error function around the current estimate :
where is the Jacobian. Substituting into the cost function and setting the gradient to zero gives the normal equations:
where:
is the approximate Hessian (also called the information matrix). Update: .
Levenberg-Marquardt
Add a damping term: . When is large, the step is small and steepest-descent-like (safe but slow). When is small, the step is Gauss-Newton (fast but may overshoot). Adaptive interpolates between the two regimes.
Sparsity Structure
Sparsity of the SLAM Information Matrix
Statement
The information matrix (where ) has a nonzero entry only if variables and appear together in at least one factor. For SLAM:
- Odometry factors create a block-tridiagonal structure in the pose-pose block
- Observation factors create sparse connections between poses and landmarks
- The total number of nonzero entries is where is the number of observations, compared to the dense matrix size
Solving via sparse Cholesky factorization costs to depending on the graph structure, compared to for dense factorization.
Intuition
Each factor connects only a small number of variables (typically 2). The information matrix inherits this sparse connectivity: most variable pairs never appear in the same factor, so . A robot that has visited 1000 poses and observed 500 landmarks has a state vector of dimension 4500 (in 3D), but the information matrix has only 10,000 nonzero entries out of 20 million possible.
Why It Matters
Sparsity is what makes large-scale SLAM tractable. EKF-SLAM maintains a dense covariance matrix, which requires storage and per update. GraphSLAM exploits sparsity to solve problems with millions of poses and landmarks. The key insight: the information (inverse covariance) matrix is sparse even though the covariance matrix is dense. This is why GraphSLAM works in the information form.
Loop Closure
Loop closure occurs when the robot revisits a previously mapped location and recognizes it. This adds a constraint between the current pose and a distant past pose, creating a long-range edge in the factor graph.
Loop closure is critical because odometry drift accumulates over time. Without loop closures, the map becomes increasingly distorted. A single correct loop closure can correct drift accumulated over thousands of poses, because the optimization distributes the correction across the entire trajectory.
The danger of incorrect loop closure: A false positive (incorrectly believing you have revisited a location) introduces a constraint between unrelated poses. The optimizer satisfies this constraint by distorting the map, often catastrophically. Robust loop closure detection is one of the hardest problems in SLAM.
Practical Systems
Modern SLAM systems (ORB-SLAM, RTAB-Map, Google Cartographer) all use factor-graph-based backends. The frontend extracts features and detects loop closures. The backend (typically iSAM2 or g2o) solves the nonlinear least squares problem incrementally: when new factors arrive, the solution is updated efficiently without re-solving from scratch.
Incremental solving (iSAM2): Maintains a Bayes tree (a data structure encoding the sparse factorization) and updates only the affected portion of the tree when new factors are added. This gives amortized cost per new variable for chain-like graphs.
Common Confusions
GraphSLAM is batch, not filtering
EKF-SLAM processes observations one at a time and maintains a running state estimate. GraphSLAM collects all constraints and optimizes over the entire trajectory simultaneously. Incremental solvers (iSAM2) blur this distinction by updating the batch solution efficiently, but the formulation is still batch optimization, not filtering.
The information matrix is sparse but the covariance matrix is dense
In SLAM, the information matrix is sparse because each measurement connects only a few variables. But the covariance matrix is dense because every variable is correlated with every other variable through the chain of constraints. This is why information-form algorithms (like GraphSLAM) are efficient while covariance-form algorithms (like EKF-SLAM) are not.
SLAM is not just localization
Localization assumes the map is known and estimates only the robot's pose. Mapping assumes the robot's poses are known and builds the map. SLAM solves both simultaneously, which creates the chicken-and-egg difficulty: you need the map to localize, and you need to be localized to build the map.
Summary
- SLAM as graph: nodes are poses and landmarks, edges are constraints
- Factor graph factorizes the joint posterior as a product of local factors
- MAP estimation under Gaussian noise reduces to nonlinear least squares
- Solve with Gauss-Newton or Levenberg-Marquardt on the normal equations
- The information matrix is sparse: nonzeros, not
- Sparsity enables solving SLAM with millions of variables
- Loop closure corrects accumulated drift but false positives are catastrophic
- Incremental solvers (iSAM2) update the solution efficiently as new data arrives
Exercises
Problem
A robot takes 100 steps, observing 20 landmarks along the way. Each pose is 3D () and each landmark is 2D (). What is the dimension of the state vector ? If the robot makes 80 landmark observations (some landmarks are seen from multiple poses), how many factors are in the factor graph (including the prior and odometry)?
Problem
Explain why a single loop closure observation can dramatically improve the map quality even though it is just one additional factor in a graph with hundreds of factors. What happens to the information matrix structure when a loop closure is added?
References
Canonical:
- Thrun & Montemerlo, "The Graph-SLAM Algorithm with Applications to Large-Scale Mapping of Urban Structures" (2006)
- Dellaert & Kaess, "Factor Graphs for Robot Perception" (2017)
Current:
- Kaess et al., "iSAM2: Incremental Smoothing and Mapping Using the Bayes Tree" (2012)
- Cadena et al., "Past, Present, and Future of Simultaneous Localization and Mapping" (2016)
Next Topics
The natural next steps from GraphSLAM and factor graphs:
- Particle filters: the sequential alternative for nonlinear state estimation
- Convex optimization basics: the optimization tools underlying least-squares solvers
Last reviewed: April 2026
Builds on This
- Active SLAM and POMDPsLayer 4
- Visual and Semantic SLAMLayer 4