Once the frontend gives us a set of poses and constraints, we have a probability problem.
We have a graph where nodes are poses xi and edges are measurements zij.

The Probability Formulation

We want to find the trajectory X={x0,,xn} that maximizes the likelihood of the measurements Z.
Assuming Gaussian noise, this is equivalent to minimizing the negative log-likelihood, which turns into a NLS problem.

The Error Function

An edge zij represents the measured transformation from pose xi to xj.
The expected measurement based on our current nodes is h(xi,xj)=xi1xj.

The error (residual) vector eij is the difference between the measurement and the expectation.
Crucial Note: We are on a manifold. We cannot just subtract matrices. We calculate the error in the tangent space se(3) using the Log map.

eij(xi,xj)=ln(zij1(xi1xj))

This gives us a 6x1 error vector for each edge.

The Cost Function

We minimize the Mahalanobis distance (weighted sum of squares):

F(X)=<i,j>∈CeijTΩijeij

Where Ωij is the Information Matrix (inverse of the covariance matrix Σij). If we trust the odometry less, Σ is large, so Ω is small (low weight).

Solving the Optimization

This is solved using Gauss-Newton or Levenberg-Marquardt
We linearize the error term around the current guess x by adding a perturbation Δx.

eij(xΔx)eij(x)+JijΔx

We solve the normal equation:

HΔx=b(JTΩJ)Δx=JTΩe
  1. Build H and b: Iterate over all edges, compute Jacobians, add to the sparse matrix H.
  2. Solve: Use a sparse Cholesky solver (standard) or Preconditioned Conjugate Gradient (for massive maps).
  3. Update: xnew=xoldΔx.

Why is this efficient?

The H matrix is sparse.
Node i is only connected to Node i1, i+1, and maybe a few loop closures. It is not fully connected.
We exploit this sparsity to solve systems with 100,000+ variables in real-time.