Phase I — Mathematical Foundations | Week 2 | 2.5 hours A well-conditioned problem is half-solved; an ill-conditioned one fights you at every step.
When AMR SLAM’s Hessian has eigenvalues spanning $10^6$, gradient descent crawls along narrow valleys while overshooting across ridges. The condition number $\kappa(H)$ quantifies this. Preconditioning and variable scaling transform the problem into a rounder landscape where solvers converge fast. Ceres’s JACOBI scaling and CLUSTER_JACOBI preconditioner exist for exactly this reason.
For a symmetric positive definite matrix $H$:
Meaning: A perturbation of $\delta$ in the input (RHS) causes up to $\kappa \cdot \delta$ perturbation in the solution.
| $\kappa(H)$ | Interpretation |
|---|---|
| $\approx 1$ | Perfectly conditioned (circular contours) |
| $10^3$ | Moderately ill-conditioned |
| $10^6$ | Ill-conditioned (common in SLAM) |
| $> 10^{15}$ | Effectively singular ($\approx \frac{1}{\epsilon_{\text{mach}}}$) |
For $f(x) = \frac{1}{2} x^T H x$: - $\kappa = 1$: circular contours → all directions have equal curvature → gradient points to minimum - $\kappa \gg 1$: highly elliptical contours → gradient zig-zags → slow convergence
Gradient descent iterations ∝ $\kappa$ for quadratic problems.
Transform $Hx = g$ into $M^{-1}Hx = M^{-1}g$ where $M \approx H$.
Common preconditioners: | Preconditioner | $M$ | Cost | Effectiveness | |---------------|-----|------|---------------| | Jacobi | $\text{diag}(H)$ | $O(n)$ | Moderate | | Block Jacobi | Block-diagonal of $H$ | $O(n \cdot b^2)$ | Good for block-structured problems | | Incomplete Cholesky | Sparse approximate $LL^T$ | $O(n \cdot \text{nnz})$ | Very good | | Exact | $H$ itself | $O(n^3)$ | Perfect (but defeats the purpose) |
Before optimizing, scale variables so all have similar magnitude:
where $s_i$ is a characteristic scale. This is equivalent to preconditioning with $M = \text{diag}(s_1^2, \ldots, s_n^2)$.
Ceres: Uses ParameterBlockLocalParameterization and ScaledLoss to handle scaling. The JACOBI scaling option divides each column of the Jacobian by its norm.
An ill-conditioned Hessian means: - Direct solvers lose digits of precision: $\log_{10}(\text{digits lost}) \approx \log_{10}(\kappa)$ - Iterative solvers converge slowly: CG needs $O(\sqrt{\kappa})$ iterations - Gradient descent needs $O(\kappa)$ iterations - The solver may report convergence but the solution is inaccurate
# See: code/week02/conditioning.py
Create quadratic functions with $\kappa = 1, 10, 100, 1000$. Plot contours and gradient descent paths.
Solve $Hx = g$ for matrices with various $\kappa$. Measure actual digits of precision in the solution.
Implement Jacobi preconditioning. Show it reduces the effective condition number and speeds up CG convergence.
Take a SLAM-like problem with mixed translation/rotation parameters. Show that scaling improves convergence.
Problem: Design an automatic variable-scaling scheme for a pose-graph SLAM problem. Given the Jacobian structure (some columns correspond to x/y translation, some to θ rotation), propose and implement a scaling that brings all columns to similar norm.
Solution: Column scaling: $\tilde{J}_{\cdot,j} = J_{\cdot,j} / \|J_{\cdot,j}\|$. This is what Ceres JACOBI scaling does. For SLAM: translation columns have norm $\propto 1/\sigma_t$ (measurement noise), rotation columns have norm $\propto r/\sigma_\theta$ where $r$ is the range. If $\sigma_t = 0.01$m and $\sigma_\theta = 0.001$rad at $r = 10$m, the norms differ by $\sim 100\times$. After column scaling, $\kappa(J^TJ)$ drops dramatically. Caveat: the scaled solution $\tilde{x}$ must be unscaled: $x_j = \tilde{x}_j / s_j$.
Problem: Show that $\kappa(J^T J) = \kappa(J)^2$. Why does this mean you should avoid forming the normal equations explicitly when the Jacobian is moderately ill-conditioned?
Solution: $J^T J$ has singular values $\sigma_i^2$ where $\sigma_i$ are the singular values of $J$. So $\kappa(J^TJ) = \sigma_{\max}^2/\sigma_{\min}^2 = \kappa(J)^2$. If $\kappa(J) = 10^4$ (fine), then $\kappa(J^TJ) = 10^8$ (losing 8 digits). Alternatives: (1) QR factorization of $J$ directly ($O(mn^2)$ but numerically stable), (2) use the augmented system $\begin{pmatrix}I & J \\ J^T & 0\end{pmatrix}\begin{pmatrix}r\\x\end{pmatrix}=\begin{pmatrix}b\\0\end{pmatrix}$ which has $\kappa = \kappa(J)$. In practice, for SLAM’s sparse $J^TJ$ the sparsity advantage of normal equations usually outweighs the conditioning cost, especially with LM regularization $J^TJ + \lambda I$.
Problem: In bundle adjustment, the Schur complement $S$ is a dense camera-only matrix. Design a good preconditioner for $S$. Hint: consider the block structure where each camera contributes a $6 \times 6$ diagonal block.
Solution: Block Jacobi preconditioner: $M = \text{blockdiag}(S_{11}, S_{22}, \ldots, S_{kk})$ where $S_{ii}$ is the $6 \times 6$ block corresponding to camera $i$. This is cheap to compute ($k$ inversions of $6 \times 6$ matrices) and captures the dominant diagonal structure. Ceres calls this CLUSTER_JACOBI. For even better preconditioning, cluster nearby cameras and use the block for each cluster (Ceres CLUSTER_TRIDIAGONAL). The ideal preconditioner would be $S$ itself, but that defeats the purpose of using CG on $S$.