---
title: 'Ceres Solver: Nonlinear Optimization'
url: https://www.emergentmind.com/topics/ceres-solver
type: topic
---

# Ceres Solver: Nonlinear Optimization

Ceres Solver is an optimization library widely used in robotics and computer vision for solving nonlinear least-squares problems, particularly in scenarios requiring efficient, accurate pose estimation. Within the Cartographer framework for Simultaneous Localization and Mapping (SLAM), Ceres operates as the default backend for 2D scan matching, providing robust and precise solutions for real-time mapping tasks by optimizing pose estimates based on lidar scan data and occupancy grid maps [2507.07142].

## 1. Mathematical Formulation in Cartographer Scan Matching

Cartographer formulates scan matching as a nonlinear least squares optimization over a 2D pose parameter vector $ x \in \mathbb{R}^3 $, where $ x = [t_x, t_y, \theta]^\top $ denotes translation and yaw. For a set of $ N $ lidar scan points $ \{p_i\}_{i=1}^N $ in the scanner frame, and a submap occupancy probability function $ M(\cdot) \in [0,1] $, the residual for point $ p_i $ under pose hypothesis $ x $ is:

$$
r_i(x) = 1 - M(R(\theta)p_i + t)
$$

where $ R(\theta) $ is the $ 2 \times 2 $ rotation matrix and $ t = [t_x, t_y]^\top $. The cost function minimized by Ceres is the sum of squared residuals:

$$
J(x) = \sum_{i=1}^N (1 - M(R(\theta)p_i + t))^2
$$

This objective penalizes alignment of lidar points with occupied regions in the submap, steering $ x $ toward maximal scan-map congruence. Optionally, robust loss functions (e.g., Huber or Cauchy) can be wrapped around each block for outlier robustness, but Cartographer’s default configuration employs plain squares.

## 2. Optimization Algorithm and Solution Process

Cartographer integrates Ceres using the Levenberg–Marquardt (LM) algorithm with a Gauss–Newton Hessian approximation. The parameter update at each iteration $ k $ involves solving the normal equations with LM damping:

$$
(J_k^\top J_k + \lambda_k D)\,\delta x = -J_k^\top r_k
$$

where $ J_k $ is the Jacobian at $ x_k $, $ r_k $ is the residual vector, $ D $ is typically $ \operatorname{diag}(J_k^\top J_k) $, and $ \lambda_k $ is the damping factor adjusted per iteration. The updated pose is computed on the $ \mathrm{SE}(2) $ manifold as $ x_{k+1} = x_k \oplus \delta x $, ensuring correct handling of angular variables. The small dimensionality of the pose-only subproblem allows for direct dense Cholesky decomposition as the linear solver for rapid per-iteration performance.

## 3. Jacobian Computation and Automatic Differentiation

The computation of Jacobians in Cartographer/Ceres leverages automatic differentiation using “Jet” types (Ceres’s internal JetA<Eigen>), which enables analytic calculation of all $ \partial r_i/\partial x $ without resorting to finite differences. Each cost-function functor is encapsulated in an `AutoDiffCostFunction<>`, producing a dense Jacobian per residual block. The global normal equations $ J^\top J $ and $ J^\top r $ are assembled in memory at each iteration; no explicit sparse-matrix representation is stored for these local scan-matching problems due to their compact size.

## 4. Solver Configuration and Parameterization

Key configuration parameters of Ceres within Cartographer are as follows:

| Parameter                | Value/Setting                     | Purpose                                   |
|--------------------------|-----------------------------------|-------------------------------------------|
| Parameter block size     | 3 ($x$, $y$, $\theta$)            | State space for 2D pose update            |
| Local parameterization   | $\mathrm{SE}(2)$ manifold         | Correct handling of translation and angle |
| Linear solver            | DENSE_QR, DENSE_NORMAL_CHOLESKY   | Cartographer defaults to Cholesky         |
| Convergence criteria     | $1\text{e}{-10}$ (cost), $1\text{e}{-20}$ (gradient) | Tight convergence                         |
| Maximum iterations       | 50 (typically 10–20 to converge)  | Upper bound on optimizer steps            |
| Time budget per scan     | $\approx1$ ms                     | Ensures real-time execution               |

The SE(2) manifold parameterization manages angular wrap-around. Dense Cholesky decomposition is chosen as the default for speed in the small pose-only regime. Function and gradient tolerances are set at $1\text{e}{-10}$ and $1\text{e}{-20}$, respectively, to encourage strong convergence. In practice, most problems are solved in under 20 iterations and within the real-time budget of 1 millisecond per scan.

## 5. Empirical Comparison with g2o

Extensive experimental comparisons demonstrate Ceres Solver’s superior performance relative to g2o for Cartographer’s scan-matching problem. In synthetic random point-cloud tests (20 runs, 5 points each):

- RMSE (translation+rotation):
  - Ceres: 0.49624
  - g2o:   0.51640
- Convergence iterations (mean ± std.):
  - Ceres: 13 ± 2
  - g2o:   23 ± 4
- Total solve time per run:
  - Ceres: 1.14 ms (≈0.088 ms/iteration)
  - g2o:   1.59 ms (≈0.069 ms/iteration)

Both solvers satisfied the stringent residual-reduction tolerance of $1\text{e}{-10}$ on all runs. In real-robot mapping (AgileX LIMO, 30-second path), Ceres produced maps with cleaner wall contours and robust loop closures, whereas g2o’s results had weaker closure at geometric corners but occasionally delivered sharper localized obstacle delineation.

## 6. Analysis of Trade-offs and Applicability

Ceres Solver’s design is highly efficient for the small, dense SLAM scan-matching problem in Cartographer. Notable strengths include:

- Native integration and hand-tuned LM parameters in Cartographer yield approximately half the iterations and about 30% faster total solver runtime compared to g2o.
- Slightly lower RMSE and superior loop-closure accuracy in synthetic and real-world mapping tasks.
- Efficient Jacobian computation with analytic automatic differentiation and dense linear solves.

g2o, while requiring more iterations, showed per-iteration times similar to Ceres and achieved better local obstacle edge sharpness in limited regions. It remains attractive for scenarios needing custom constraint designs or high-fidelity obstacle-space cost modeling, albeit with significant additional solver engineering needed to approach Ceres’s default performance.

## 7. Context and Significance in SLAM

In Cartographer-based SLAM, the adoption of Ceres Solver as the default scan-matching backend is motivated by its rapid convergence, high accuracy, and tight integration with lossless manifold parameterization and automated Jacobian calculation. These features make Ceres well-suited for real-time, incremental mapping pipelines where latency and solution precision are critical. While alternative approaches such as g2o offer special utility in domains requiring highly customized factorization, Ceres’s out-of-the-box robustness and efficiency enable high-quality SLAM deployments with minimal algorithmic tuning [2507.07142].

Source: https://www.emergentmind.com/topics/ceres-solver