Algorithm Search⌘K

Algorithmresearch

SE-Sync

Also called certifiably correct pose graph optimization.

Solves pose graph optimization through a semidefinite relaxation and the Riemannian staircase, and certifies a global optimum when the relaxation is tight.

Time
O(r (n + m)) certificate · local_search_sweepO(n^3) jacobi_sweep_denseO(r^2 n + r^3) rounding
Space
O(r n) iterateO(n + m) sparse_q
Where
m = the number of edges; n = the number of poses; r = the rank of the current step of the staircase
Properties
certifies global optimumdeterministicnot exactneeds tight relaxation
Origin
David M. Rosen, Luca Carlone, Afonso S. Bandeira, John J. Leonard, 2019

SE-Sync solves pose graph optimization and returns a proof that the answer is the global optimum when it can. Pose graph optimization is nonconvex because rotations live on the curved set SO(d)SO(d), so Gauss-Newton and similar local methods can stop at a wrong local minimum and cannot tell. SE-Sync first removes the translations in closed form. What is left is a problem over the rotations alone, min⁡tr(Q~R⊤R)\min \mathrm{tr}(\tilde Q R^\top R) with R∈SO(d)nR \in SO(d)^n. It relaxes this problem to a semidefinite program and solves the relaxation in the low rank form Z=Y⊤YZ = Y^\top Y of Burer and Monteiro, where YY has only rr rows. A local search finds a critical point YY. A matrix SS built from YY and the data is the certificate: if SS is positive semidefinite, Y⊤YY^\top Y solves the relaxation. If not, the eigenvector of the least eigenvalue of SS points downhill in a space with one more row, and the search goes up one step of this "Riemannian staircase". At the end, SE-Sync rounds YY to rotations. The relaxation value is a lower bound, and the cost of the rounded answer is an upper bound. When the relaxation is tight, the two are equal, and the rounded answer is a certified global optimum. Rosen et al. prove that this happens when the noise is below a level that depends on the graph.

In plain words

Many poses must agree with many measurements of how they relate. A normal solver walks downhill from a guess and stops at the first low point, which may not be the lowest. SE-Sync loosens the problem so that it has no false low points, solves the loose version, and then checks a simple condition that proves the loose answer is the best one. If the check fails, the check itself shows a way down, and the search continues with one more degree of freedom. At the end, the loose answer is turned back into real rotations. If the loose problem and the real problem give the same value, the answer is proved to be the best possible. When the measurements are very noisy, the two values can differ. Then the gap still tells how far from the best the answer can be.

The problem

The input is a connected graph on nn poses. Each edge (i,j)(i, j) has a measured relative rotation R~ij\tilde R_{ij}, a measured relative translation t~ij\tilde t_{ij}, and weights κij,τij>0\kappa_{ij}, \tau_{ij} > 0. The problem is

min⁡Ri∈SO(d), ti∈Rd∑(i,j)κij∥Rj−RiR~ij∥F2+τij∥tj−ti−Rit~ij∥22.\min_{R_i \in SO(d),\ t_i \in \mathbb{R}^d} \sum_{(i,j)} \kappa_{ij} \|R_j - R_i \tilde R_{ij}\|_F^2 + \tau_{ij} \|t_j - t_i - R_i \tilde t_{ij}\|_2^2.

For fixed rotations the cost is a linear least squares problem in the translations, so the translations can be eliminated. The result is min⁡tr(Q~R⊤R)\min \mathrm{tr}(\tilde Q R^\top R) over R=[R1⋯Rn]∈SO(d)nR = [R_1 \cdots R_n] \in SO(d)^n, for a symmetric positive semidefinite matrix Q~\tilde Q of size dndn. With rotation edges only, Q~\tilde Q is the connection Laplacian QQ, with blocks Qii=∑j∼iκijIQ_{ii} = \sum_{j \sim i} \kappa_{ij} I and Qij=−κijR~ijQ_{ij} = -\kappa_{ij} \tilde R_{ij}. Its scalar analogue is the Laplacian matrix of the graph.

The code is the planar rotation case: d=2d = 2 and the matrix QQ of the rotation edges. It is the core of SE-Sync without the translation step. The same steps apply to Q~\tilde Q and to d=3d = 3.

The algorithm

The relaxation replaces Ri∈SO(d)R_i \in SO(d) by Yi∈Rr×dY_i \in \mathbb{R}^{r \times d} with Yi⊤Yi=IY_i^\top Y_i = I. The set of such YiY_i is the Stiefel manifold St(d,r)\mathrm{St}(d, r). For r≥dr \ge d, min⁡tr(QY⊤Y)\min \mathrm{tr}(Q Y^\top Y) is a lower bound on the original problem. Burer and Monteiro showed that for rr large enough it equals the semidefinite program min⁡tr(QZ)\min \mathrm{tr}(QZ) with Z⪰0Z \succeq 0 and Zii=IZ_{ii} = I.

  1. SE-SYNC(Q, initial rotations R⁰)
  2. 1r ← d; Y ← [R⁰_1 ... R⁰_n]
  3. 2loop
  4. 3Y ← a first order critical point of tr(Q YᵀY) on St(d, r)^n, by local search from Y
  5. 4Λ ← the block diagonal matrix with Λ_ii = Sym((Q YᵀY)_ii); S ← Q - Λ
  6. 5(λ, v) ← the least eigenvalue of S and a unit eigenvector
  7. 6if λ ≥ -ε then leave the loop
  8. 7r ← r + 1; Y ← a descent step from [Y; 0] along the new row vᵀ, with a line search
  9. 8R̂ ← ROUND(Y): the top d rows of UᵀY from the SVD of Y, sign fix, nearest rotation per block
  10. 9return R̂, the lower bound tr(Q YᵀY) and the upper bound tr(Q R̂ᵀR̂)

Local search (line L3). Rosen et al. use a Riemannian trust region method. The code uses block coordinate descent. With all blocks except YiY_i fixed, the cost is 2 tr(Yi⊤Gi)2\,\mathrm{tr}(Y_i^\top G_i) plus a constant, with Gi=∑j≠iYjQjiG_i = \sum_{j \ne i} Y_j Q_{ji}. Its minimizer over St(d,r)\mathrm{St}(d, r) is the polar factor of −Gi-G_i. Each step can only decrease the cost. The search stops when a full sweep changes the cost by less than a relative 10−1210^{-12}.

The certificate (lines L4 to L6). The Riemannian gradient at YY is 2YS2YS, so at a critical point YS=0YS = 0. If also S⪰0S \succeq 0, then for any feasible ZZ, tr(QZ)=tr(SZ)+tr(Λ)≥tr(Λ)=tr(QY⊤Y)\mathrm{tr}(QZ) = \mathrm{tr}(SZ) + \mathrm{tr}(\Lambda) \ge \mathrm{tr}(\Lambda) = \mathrm{tr}(Q Y^\top Y). So Y⊤YY^\top Y solves the semidefinite program, and Λ\Lambda is the dual solution. The code finds the least eigenvalue with the Jacobi eigenvalue algorithm on the dense SS. Rosen et al. use a sparse Lanczos method. The tolerance ε\varepsilon is 10−610^{-6} times the largest entry of QQ.

The staircase step (line L7). If v⊤Sv=λ<0v^\top S v = \lambda < 0, then the step [Y;0]+α[0;v⊤][Y; 0] + \alpha [0; v^\top], mapped back to St(d,r+1)\mathrm{St}(d, r + 1) by the polar factor of each block, changes the cost by α2λ+O(α4)\alpha^2 \lambda + O(\alpha^4). The code starts at α=1\alpha = 1 and halves α\alpha until the cost decreases.

Rounding (line L8). If YY has rank dd, the top dd rows of U⊤YU^\top Y give RR with R⊤R=Y⊤YR^\top R = Y^\top Y and Ri∈O(d)R_i \in O(d). If most blocks have a negative determinant, the code changes the sign of one row. Then each block goes to the nearest rotation, and the result is multiplied by R^1⊤\hat R_1^\top so that R^1=I\hat R_1 = I.

Example

A wrong critical point. Take a cycle of 9 rotations whose 9 measurements are all the identity, with weights 1. The global optimum has all rotations equal and cost 0. Start at the "twisted" state Ri=Rot(2πi/9)R_i = \mathrm{Rot}(2\pi i / 9). Each edge then has the error ∥Rot(40°)−I∥F2=4−4cos⁡40°=0.9358\|\mathrm{Rot}(40°) - I\|_F^2 = 4 - 4\cos 40° = 0.9358, so the cost is 8.42248.4224. Every rotation sits halfway between its two neighbors, so the gradient is zero, and block coordinate descent does not move. A local solver stops here. The certificate does not. The eigenvalues of SS at this point are −0.4679-0.4679 (twice), 00 (four times), 1.18481.1848, 2.53212.5321 and 3.41153.4115 (four times each). The staircase runs as follows.

rank rr cost after the local search least eigenvalue of SS sweeps
2 8.4224 -0.4679 1
3 4.2112 -0.4679 35
4 7.4×10−137.4 \times 10^{-13} −8×10−14-8 \times 10^{-14} 41

At rank 4 the certificate holds, and rounding gives all rotations equal with cost about 0.

A random problem. Ten rotations at random angles, a path through them plus 10 random extra edges, and Gaussian angle noise with σ=0.1\sigma = 0.1 rad on each measurement (seed 4). The start composes the measurements along a breadth-first spanning tree. It has cost 1.0634 and a largest angle error of 0.264 rad. The truth has cost 0.6213. After 14 sweeps the certificate holds at rank 2 with λmin⁡=−2.1×10−15\lambda_{\min} = -2.1 \times 10^{-15}. The lower bound and the upper bound are both 0.248577, so the answer is a certified global optimum. Its largest angle error against the truth is 0.130 rad.

More noise. On five random problems for each noise level, with 10 rotations and 10 extra edges, the relaxation was tight at rank 2 for all problems at σ=0.3\sigma = 0.3 and 0.60.6 rad. At σ=1.0\sigma = 1.0 rad it was tight for three of the five. The other two stopped at rank 4 with gaps of 0.875 and 3.42 between the upper and the lower bound. At σ=1.5\sigma = 1.5 and 2.02.0 rad, some problems again had gaps. One problem at σ=2.0\sigma = 2.0 went up to rank 3 and was still tight. These are measurements on small problems, and they agree with the guarantee: below a noise level the relaxation is exact, and above it a gap can appear.

Correctness

The correctness proof shows that the cost equals tr(QR⊤R)\mathrm{tr}(Q R^\top R), that the Riemannian gradient is 2YS2YS, that YS=0YS = 0 and S⪰0S \succeq 0 make Y⊤YY^\top Y optimal for the semidefinite program, and that the staircase step decreases the cost when SS has a negative eigenvalue. It also shows that the lower bound is at most the optimum and the upper bound at least the optimum, and that a rank dd certified YY with the right determinants rounds to a global minimizer. It does not show that the relaxation is tight; that is the theorem of Rosen et al. for small noise. The tests check the trace form, exact recovery without noise, the certificate and a zero gap at low noise, the first order condition, a brute force search over three rotations, and the twisted cycle.

Proof: The SE-Sync certificate proves optimality for the semidefinite relaxation, the staircase step descends, and a tight relaxation gives a global optimumfull

Setting. The unknowns are R1,…,Rn∈SO(2)R_1, \dots, R_n \in SO(2), written as R=[R1⋯Rn]∈R2×2nR = [R_1 \cdots R_n] \in \mathbb{R}^{2 \times 2n}. Each edge (i,j)(i, j) has a measurement R~ij∈SO(2)\tilde R_{ij} \in SO(2) and a weight κij>0\kappa_{ij} > 0. The cost is F(R)=∑(i,j)κij∥Rj−RiR~ij∥F2F(R) = \sum_{(i,j)} \kappa_{ij} \|R_j - R_i \tilde R_{ij}\|_F^2. The connection Laplacian Q∈R2n×2nQ \in \mathbb{R}^{2n \times 2n} has the diagonal blocks Qii=∑j∼iκijIQ_{ii} = \sum_{j \sim i} \kappa_{ij} I and, for each edge, Qij=−κijR~ijQ_{ij} = -\kappa_{ij} \tilde R_{ij} and Qji=Qij⊤Q_{ji} = Q_{ij}^\top. In SE-Sync for poses, the translations are removed in closed form, and the rotations face a problem of the same form, min⁡tr(Q~R⊤R)\min \mathrm{tr}(\tilde Q R^\top R), with a different symmetric matrix Q~\tilde Q. Claims 2 to 5 use only that QQ is symmetric, so they hold for Q~\tilde Q too.

The problems are:

  • (P) min⁡tr(QR⊤R)\min \mathrm{tr}(Q R^\top R) over R∈SO(2)nR \in SO(2)^n;
  • (SDP) min⁡tr(QZ)\min \mathrm{tr}(Q Z) over symmetric Z⪰0Z \succeq 0 with Zii=I2Z_{ii} = I_2 for each ii;
  • (BMr_r) min⁡f(Y)=tr(QY⊤Y)\min f(Y) = \mathrm{tr}(Q Y^\top Y) over Y=[Y1⋯Yn]Y = [Y_1 \cdots Y_n] with Yi∈Rr×2Y_i \in \mathbb{R}^{r \times 2} and Yi⊤Yi=I2Y_i^\top Y_i = I_2.

For YY in (BMr_r), let Λ(Y)\Lambda(Y) be block diagonal with Λii=Sym((QY⊤Y)ii)\Lambda_{ii} = \mathrm{Sym}\big((Q Y^\top Y)_{ii}\big), where Sym(A)=(A+A⊤)/2\mathrm{Sym}(A) = (A + A^\top)/2, and let S(Y)=Q−Λ(Y)S(Y) = Q - \Lambda(Y).

Assumptions. (A1) Exact arithmetic. In the code, "zero" and "positive semidefinite" are checked with small tolerances.

Claim 1 (the cost). F(R)=tr(QR⊤R)F(R) = \mathrm{tr}(Q R^\top R) for R∈O(2)nR \in O(2)^n.

Proof. For one edge, ∥Rj−RiR~∥F2=tr(Rj⊤Rj)+tr(R~⊤Ri⊤RiR~)−2 tr(Rj⊤RiR~)\|R_j - R_i \tilde R\|_F^2 = \mathrm{tr}(R_j^\top R_j) + \mathrm{tr}(\tilde R^\top R_i^\top R_i \tilde R) - 2\,\mathrm{tr}(R_j^\top R_i \tilde R). The trace form collects κ tr(Ri⊤Ri)+κ tr(Rj⊤Rj)\kappa\,\mathrm{tr}(R_i^\top R_i) + \kappa\,\mathrm{tr}(R_j^\top R_j) from the diagonal blocks, and tr(QijRj⊤Ri)+tr(QjiRi⊤Rj)=−2κ tr(R~Rj⊤Ri)\mathrm{tr}(Q_{ij} R_j^\top R_i) + \mathrm{tr}(Q_{ji} R_i^\top R_j) = -2\kappa\,\mathrm{tr}(\tilde R R_j^\top R_i) from the two off-diagonal blocks. Since R~\tilde R is orthogonal, tr(R~⊤Ri⊤RiR~)=tr(Ri⊤Ri)\mathrm{tr}(\tilde R^\top R_i^\top R_i \tilde R) = \mathrm{tr}(R_i^\top R_i), and the two sums agree term by term. □\square

Claim 2 (the chain of bounds). min⁡(SDP)≤min⁡(P)\min(\mathrm{SDP}) \le \min(\mathrm{P}), and f(Y)≥min⁡(SDP)f(Y) \ge \min(\mathrm{SDP}) for every YY in (BMr_r).

Proof. For R∈SO(2)nR \in SO(2)^n or for any feasible YY, Z=Y⊤YZ = Y^\top Y is positive semidefinite and Zii=Yi⊤Yi=IZ_{ii} = Y_i^\top Y_i = I, so it is feasible for (SDP), with the same cost. □\square

Claim 3 (the gradient). The Riemannian gradient of ff at YY is 2 YS(Y)2\,Y S(Y). So YY is a first order critical point if and only if YS(Y)=0Y S(Y) = 0.

Proof. The Euclidean gradient of ff is 2YQ2 Y Q, and its block ii is ξi=2∑jYjQji\xi_i = 2 \sum_j Y_j Q_{ji}. The tangent space of {Yi⊤Yi=I}\{Y_i^\top Y_i = I\} at YiY_i is {Y˙i:Yi⊤Y˙i+Y˙i⊤Yi=0}\{\dot Y_i : Y_i^\top \dot Y_i + \dot Y_i^\top Y_i = 0\}, and the projection onto it is ξi↦ξi−YiSym(Yi⊤ξi)\xi_i \mapsto \xi_i - Y_i \mathrm{Sym}(Y_i^\top \xi_i). Here Yi⊤ξi=2(Y⊤YQ)iiY_i^\top \xi_i = 2 (Y^\top Y Q)_{ii}, which is the transpose of 2(QY⊤Y)ii2 (Q Y^\top Y)_{ii}, so Sym(Yi⊤ξi)=2Λii\mathrm{Sym}(Y_i^\top \xi_i) = 2 \Lambda_{ii}. The projected block is 2((YQ)i−YiΛii)=2(YS)i2\big((Y Q)_i - Y_i \Lambda_{ii}\big) = 2 (Y S)_i. □\square

Claim 4 (the certificate). If YS(Y)=0Y S(Y) = 0 and S(Y)⪰0S(Y) \succeq 0, then Z⋆=Y⊤YZ^\star = Y^\top Y solves (SDP), and f(Y)=min⁡(SDP)f(Y) = \min(\mathrm{SDP}).

Proof. Let Λ=Λ(Y)\Lambda = \Lambda(Y) and S=S(Y)S = S(Y). For any feasible ZZ, since Λ\Lambda is block diagonal with symmetric blocks and Zii=IZ_{ii} = I, tr(ΛZ)=∑itr(Λii)=tr(Λ)\mathrm{tr}(\Lambda Z) = \sum_i \mathrm{tr}(\Lambda_{ii}) = \mathrm{tr}(\Lambda). So tr(QZ)=tr(SZ)+tr(Λ)≥tr(Λ)\mathrm{tr}(Q Z) = \mathrm{tr}(S Z) + \mathrm{tr}(\Lambda) \ge \mathrm{tr}(\Lambda), because the trace of the product of two positive semidefinite matrices is nonnegative. At Z⋆Z^\star, tr(SY⊤Y)=tr(YSY⊤)=0\mathrm{tr}(S Y^\top Y) = \mathrm{tr}(Y S Y^\top) = 0, so tr(QZ⋆)=tr(Λ)\mathrm{tr}(Q Z^\star) = \mathrm{tr}(\Lambda), the smallest value. This is weak duality with the dual variable Λ\Lambda of the constraints Zii=IZ_{ii} = I. □\square

Claim 5 (the staircase step). Let YY be in (BMr_r) with YS(Y)=0Y S(Y) = 0, and let v∈R2nv \in \mathbb{R}^{2n} be a unit vector with v⊤Sv=λ<0v^\top S v = \lambda < 0. Let Y+=[Y;0]∈Y^+ = [Y; 0] \in (BMr+1_{r+1}), Y˙=[0;v⊤]\dot Y = [0; v^\top], and Y′(α)Y'(\alpha) the blockwise polar factor of Y++αY˙Y^+ + \alpha \dot Y. Then f(Y′(α))=f(Y)+α2λ+O(α4)f(Y'(\alpha)) = f(Y) + \alpha^2 \lambda + O(\alpha^4), so a small enough step decreases the cost.

Proof. Y+Y^+ has the same cost as YY and lies in (BMr+1_{r+1}). Each block Y˙i\dot Y_i is nonzero only in the new row, where Yi+Y^+_i is zero, so (Y+)⊤Y˙=0(Y^+)^\top \dot Y = 0 and Y˙\dot Y is tangent. Let viv_i be the two entries of vv for block ii, and DD block diagonal with Dii=vivi⊤D_{ii} = v_i v_i^\top. Then (Yi++αY˙i)⊤(Yi++αY˙i)=I+α2Dii(Y^+_i + \alpha \dot Y_i)^\top (Y^+_i + \alpha \dot Y_i) = I + \alpha^2 D_{ii}, so the polar factor is (Y++αY˙)M(Y^+ + \alpha \dot Y) M with M=I−α22D+O(α4)M = I - \tfrac{\alpha^2}{2} D + O(\alpha^4). With W=(Y++αY˙)⊤(Y++αY˙)=Y⊤Y+α2vv⊤W = (Y^+ + \alpha \dot Y)^\top (Y^+ + \alpha \dot Y) = Y^\top Y + \alpha^2 v v^\top,

f(Y′)=tr(QMWM)=f(Y)+α2v⊤Qv−α22tr(D(Y⊤YQ+QY⊤Y))+O(α4).f(Y') = \mathrm{tr}(Q M W M) = f(Y) + \alpha^2 v^\top Q v - \tfrac{\alpha^2}{2}\mathrm{tr}\big(D (Y^\top Y Q + Q Y^\top Y)\big) + O(\alpha^4).

DD is block diagonal and symmetric, so the middle trace is ∑itr(Dii⋅2Λii)=2v⊤Λv\sum_i \mathrm{tr}\big(D_{ii} \cdot 2\Lambda_{ii}\big) = 2 v^\top \Lambda v. Hence f(Y′)=f(Y)+α2v⊤(Q−Λ)v+O(α4)=f(Y)+α2λ+O(α4)f(Y') = f(Y) + \alpha^2 v^\top (Q - \Lambda) v + O(\alpha^4) = f(Y) + \alpha^2 \lambda + O(\alpha^4). The line search halves α\alpha until the cost decreases, which happens after finitely many halvings. □\square

Claim 6 (rounding and global optimality). Let YY satisfy the conditions of Claim 4. If YY has rank 2, let R=U2⊤YR = U_2^\top Y, where U2U_2 holds the two top left singular vectors of YY. Then R⊤R=Y⊤YR^\top R = Y^\top Y and every RiR_i is in O(2)O(2). If, after the sign fix of the code, every det⁡Ri=1\det R_i = 1, then RR is a global minimizer of (P) and F(R)=f(Y)F(R) = f(Y). In all cases, f(Y)≤min⁡(P)≤F(R^)f(Y) \le \min(\mathrm{P}) \le F(\hat R) for the rounded R^\hat R.

Proof. The columns of YY lie in the span of U2U_2, so U2U2⊤Y=YU_2 U_2^\top Y = Y and R⊤R=Y⊤U2U2⊤Y=Y⊤YR^\top R = Y^\top U_2 U_2^\top Y = Y^\top Y. Then Ri⊤Ri=(Y⊤Y)ii=IR_i^\top R_i = (Y^\top Y)_{ii} = I. Changing the sign of the second row of RR multiplies every det⁡Ri\det R_i by −1-1 and does not change R⊤RR^\top R. If all determinants are 1, then RR is feasible for (P), and by Claims 1, 2 and 4, F(R)=tr(QR⊤R)=f(Y)=min⁡(SDP)≤min⁡(P)≤F(R)F(R) = \mathrm{tr}(Q R^\top R) = f(Y) = \min(\mathrm{SDP}) \le \min(\mathrm{P}) \le F(R). The last statement follows from Claims 2 and 4 and the feasibility of R^\hat R. The projection of each block onto SO(2)SO(2) and the multiplication by R^1⊤\hat R_1^\top keep R^\hat R feasible and, for the second, do not change FF. □\square

What this does not show. It does not show that the relaxation is tight. Rosen et al. prove that it is tight when the noise is below a level that depends on the graph; above that level, the rank of the certified YY can exceed 2, and the gap F(R^)−f(Y)F(\hat R) - f(Y) only bounds the suboptimality of R^\hat R. It does not show that the local search reaches a critical point; block coordinate descent decreases ff at every step, and the code checks the gradient and the eigenvalue with tolerances. It does not bound the rank at which the staircase stops; Boumal, Voroninski and Bandeira give such a bound for generic problems, and the code stops at a fixed largest rank.

Complexity

Let nn be the number of poses, mm the number of edges and rr the current rank.

  • One sweep of block coordinate descent costs O(r(n+m))O(r (n + m)): each block reads its neighbors and takes the polar factor of an r×dr \times d matrix.
  • Forming SS and the gradient costs O(r(n+m))O(r (n + m)) with a sparse QQ.
  • The least eigenvalue costs O(n3)O(n^3) per Jacobi sweep with the dense SS of the code. A sparse Lanczos method needs only products with SS, at O(n+m)O(n + m) each.
  • Rounding costs O(r2n+r3)O(r^2 n + r^3).
  • The number of local search iterations and of staircase steps depends on the data. In practice the staircase stops at r=dr = d or one step above when the noise is moderate.

Properties

  • Certifiable. A tight run returns a proof of global optimality that anyone can check with one eigenvalue computation.
  • Bounds. Every run returns a lower and an upper bound on the optimum.
  • Exact below a noise level. Rosen et al. prove that the relaxation is exact when the noise is small enough.
  • Independent of the start. The certificate does not depend on the initial guess. The start changes only the run time.
  • No translations in the search. The translations are recovered in closed form after the rotations.

Variants and improvements

  • Other local solvers. A Riemannian trust region method converges faster than block coordinate descent.
  • Verification only. Carlone and colleagues earlier used Lagrangian duality to verify a candidate from a local solver. SE-Sync makes the same kind of check part of the solver.
  • Other synchronization problems. The same relaxation and certificate work for rotation averaging in structure from motion.
  • Distributed and incremental versions. Later work splits the problem across robots or keeps the certificate up to date as the graph grows.
  • Robust costs. Wrong loop closures break the noise assumption. Robust versions combine certifiable relaxations with outlier models such as switchable constraints.

When to use it

Use SE-Sync when a wrong local minimum is costly and the measurements have moderate noise, for example to check a map before a long mission, or to start a local solver from a good point. For online use with frequent updates, iSAM2 is faster, and SE-Sync can check its result from time to time. With outliers in the loop closures, first remove them or use a robust method.

Pitfalls

  • Outliers. A wrong loop closure is not small noise. The relaxation can then be loose, and a certified optimum of the wrong cost is still wrong.
  • The tolerance on λ\lambda. The least eigenvalue of SS is zero at a solution, because the rows of YY are in its null space. A test against an exact zero fails because of rounding. Scale the tolerance by the size of QQ.
  • Rank above dd. If the staircase stops at a rank above dd, the rounded answer is not certified. Report the gap, not a claim of optimality.
  • The gauge. The cost does not change when all rotations are multiplied by one rotation. Fix one pose, as the code does with R^1=I\hat R_1 = I, before comparing results.
  • A disconnected graph. The cost then has more than one gauge freedom, and the spanning tree start fails.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

se_sync.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/se-sync/. The authors are listed in prov/ZTRAGF.jsonl.

"""The SE-Sync pipeline (Rosen, Carlone, Bandeira and Leonard 2019) on small
planar rotation synchronization problems.

The unknowns are n rotations R_i in SO(2). Each edge (i, j, Rt, kappa) is a
measurement Rt of R_i^T R_j with the weight kappa > 0. The cost is

    F(R) = sum over the edges of kappa || R_j - R_i Rt ||_F^2 = tr(Q R^T R),

where R = [R_1 ... R_n] is 2 x 2n and Q is the 2n x 2n connection Laplacian.
In SE-Sync the translations of a pose graph are removed in closed form, which
leaves a problem of this same form with a matrix Q that also holds the
translation terms; the code starts from Q, so it covers the rotation part.

The pipeline:
  1. Relax SO(2) to the Stiefel manifold St(2, r): Y = [Y_1 ... Y_n] is
     r x 2n with Y_i^T Y_i = I. min tr(Q Y^T Y) is the Burer-Monteiro form of
     the semidefinite relaxation min tr(Q Z), Z >= 0, Z_ii = I.
  2. Find a critical point Y by a local search (here block coordinate descent:
     each Y_i has a closed form minimizer, the polar factor).
  3. Certificate: Lambda_i = Sym(sum_j Q_ij Y_j^T Y_i), S = Q - Lambda.
     If S is positive semidefinite, Z = Y^T Y solves the relaxation.
  4. If not, the eigenvector v of the least eigenvalue of S gives a descent
     direction at [Y; 0] in St(2, r + 1): go up one step of the staircase.
  5. Round: take the top 2 rows of U^T Y from the SVD of Y, fix the sign of
     the determinant, and project each block onto SO(2).
The lower bound tr(Q Y^T Y) and the upper bound F(R) bracket the optimum.
"""

import math

# ------------------------------------------------------------- small algebra


def rot(a):
    c, s = math.cos(a), math.sin(a)
    return [[c, -s], [s, c]]


def angle(r):
    return math.atan2(r[1][0], r[0][0])


def matmul(a, b):
    bt = list(zip(*b))
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def transpose(a):
    return [list(r) for r in zip(*a)]


def symmetric_eigen(a, tol=1e-14, max_sweeps=100):
    """Cyclic Jacobi: return (eigenvalues ascending, eigenvectors as columns)."""
    n = len(a)
    a = [list(r) for r in a]
    v = [[1.0 if i == j else 0.0 for j in range(n)] for i in range(n)]
    for _ in range(max_sweeps):
        off = sum(a[i][j] ** 2 for i in range(n) for j in range(n) if i != j)
        if off <= tol * tol * max(1.0, sum(a[i][i] ** 2 for i in range(n))):
            break
        for p in range(n - 1):
            for q in range(p + 1, n):
                if abs(a[p][q]) < 1e-300:
                    continue
                th = (a[q][q] - a[p][p]) / (2.0 * a[p][q])
                t = (1.0 if th >= 0 else -1.0) / (abs(th) + math.sqrt(th * th + 1.0))
                c = 1.0 / math.sqrt(t * t + 1.0)
                s = t * c
                for k in range(n):
                    akp, akq = a[k][p], a[k][q]
                    a[k][p], a[k][q] = c * akp - s * akq, s * akp + c * akq
                for k in range(n):
                    apk, aqk = a[p][k], a[q][k]
                    a[p][k], a[q][k] = c * apk - s * aqk, s * apk + c * aqk
                for k in range(n):
                    vkp, vkq = v[k][p], v[k][q]
                    v[k][p], v[k][q] = c * vkp - s * vkq, s * vkp + c * vkq
    idx = sorted(range(n), key=lambda i: a[i][i])
    return [a[i][i] for i in idx], [[v[k][i] for i in idx] for k in range(n)]


def polar_factor(g):
    """The r x 2 matrix with orthonormal columns nearest to g: g (g^T g)^(-1/2)."""
    a = sum(row[0] * row[0] for row in g)
    b = sum(row[0] * row[1] for row in g)
    d = sum(row[1] * row[1] for row in g)
    mean, half = 0.5 * (a + d), math.hypot(0.5 * (a - d), b)
    l1, l2 = mean + half, mean - half
    if l2 <= 1e-24 * max(1.0, l1):
        raise ValueError("the block has rank below 2")
    if abs(b) > 1e-300 or abs(a - d) > 1e-300:
        phi = 0.5 * math.atan2(2.0 * b, a - d)
    else:
        phi = 0.0
    c, s = math.cos(phi), math.sin(phi)
    # g^T g = V diag(l1, l2) V^T with V = [[c, -s], [s, c]]
    w1, w2 = 1.0 / math.sqrt(l1), 1.0 / math.sqrt(l2)
    m = [[c * c * w1 + s * s * w2, c * s * (w1 - w2)], [c * s * (w1 - w2), s * s * w1 + c * c * w2]]
    return [[row[0] * m[0][0] + row[1] * m[1][0], row[0] * m[0][1] + row[1] * m[1][1]] for row in g]


# ----------------------------------------------------------- the problem


def connection_laplacian(n, edges):
    q = [[0.0] * (2 * n) for _ in range(2 * n)]
    for i, j, rt, kappa in edges:
        for a in range(2):
            q[2 * i + a][2 * i + a] += kappa
            q[2 * j + a][2 * j + a] += kappa
            for b in range(2):
                q[2 * i + a][2 * j + b] -= kappa * rt[a][b]
                q[2 * j + b][2 * i + a] -= kappa * rt[a][b]
    return q


def objective(edges, rs):
    """F(R) = sum kappa || R_j - R_i Rt ||_F^2."""
    tot = 0.0
    for i, j, rt, kappa in edges:
        p = matmul(rs[i], rt)
        tot += kappa * sum((rs[j][a][b] - p[a][b]) ** 2 for a in range(2) for b in range(2))
    return tot


def block(y, i):
    return [[row[2 * i], row[2 * i + 1]] for row in y]


def set_block(y, i, b):
    for row, br in zip(y, b):
        row[2 * i], row[2 * i + 1] = br[0], br[1]


def relaxed_cost(q, y):
    """tr(Q Y^T Y)."""
    yq = matmul(y, q)
    return sum(yq[k][c] * y[k][c] for k in range(len(y)) for c in range(len(q)))


def neighbors(q, n):
    return [[j for j in range(n) if j != i and any(q[2 * i + a][2 * j + b] != 0.0 for a in range(2) for b in range(2))] for i in range(n)]


def local_search(q, y, n, tol=1e-12, max_sweeps=20000):
    """Block coordinate descent on St(2, r)^n. Each step minimizes over one Y_i.

    With the others fixed, tr(Q Y^T Y) = 2 tr(Y_i^T G_i) + const, with
    G_i = sum_{j != i} Y_j Q_ji, so the minimizer is Y_i = polar(-G_i).
    """
    nb = neighbors(q, n)
    r = len(y)
    last = relaxed_cost(q, y)
    for sweep in range(max_sweeps):
        for i in range(n):
            g = [[0.0, 0.0] for _ in range(r)]
            for j in nb[i]:
                for k in range(r):
                    yk = y[k]
                    for b in range(2):
                        g[k][b] -= yk[2 * j] * q[2 * j][2 * i + b] + yk[2 * j + 1] * q[2 * j + 1][2 * i + b]
            set_block(y, i, polar_factor(g))
        cost = relaxed_cost(q, y)
        if last - cost <= tol * max(1.0, abs(cost)):
            return y, sweep + 1
        last = cost
    return y, max_sweeps


def certificate(q, y, n):
    """Return S = Q - Lambda with Lambda_i = Sym(sum_j Q_ij Y_j^T Y_i)."""
    yty = matmul(transpose(y), y)
    s = [list(row) for row in q]
    for i in range(n):
        lam = [[0.0, 0.0], [0.0, 0.0]]
        for a in range(2):
            for b in range(2):
                lam[a][b] = sum(q[2 * i + a][c] * yty[c][2 * i + b] for c in range(2 * n))
        for a in range(2):
            for b in range(2):
                s[2 * i + a][2 * i + b] -= 0.5 * (lam[a][b] + lam[b][a])
    return s


def riemannian_gradient_norm(q, y, n):
    """|| 2 Y S || in the Frobenius norm; zero exactly at a first order critical point."""
    ys = matmul(y, certificate(q, y, n))
    return 2.0 * math.sqrt(sum(x * x for row in ys for x in row))


def escape(q, y, n, v):
    """Lift Y to [Y; 0] and step along e_{r+1} v^T with a backtracking line search."""
    base = [list(row) for row in y] + [[0.0] * (2 * n)]
    f0 = relaxed_cost(q, base)
    norm = math.sqrt(sum(x * x for x in v))
    alpha = 1.0
    while alpha > 1e-12:
        trial = [list(row) for row in base]
        trial[-1] = [alpha * x / norm for x in v]
        for i in range(n):
            set_block(trial, i, polar_factor(block(trial, i)))
        if relaxed_cost(q, trial) < f0:
            return trial
        alpha *= 0.5
    raise ValueError("no descent along the eigenvector")


def round_solution(y, n):
    """Top 2 rows of U^T Y, sign fix, then the nearest rotation per block."""
    r = len(y)
    yyt = [[sum(a * b for a, b in zip(y[i], y[j])) for j in range(r)] for i in range(r)]
    _, vecs = symmetric_eigen(yyt)
    top = [[vecs[k][r - 1 - c] for k in range(r)] for c in range(2)]  # the two largest
    rr = [[sum(top[c][k] * y[k][col] for k in range(r)) for col in range(2 * n)] for c in range(2)]
    dets = [rr[0][2 * i] * rr[1][2 * i + 1] - rr[0][2 * i + 1] * rr[1][2 * i] for i in range(n)]
    if sum(1 for d in dets if d < 0) > n / 2:
        rr[1] = [-x for x in rr[1]]
    out = []
    for i in range(n):
        a, b = rr[0][2 * i], rr[0][2 * i + 1]
        c, d = rr[1][2 * i], rr[1][2 * i + 1]
        # the nearest rotation to [[a, b], [c, d]] has the angle atan2(c - b, a + d)
        out.append(rot(math.atan2(c - b, a + d)))
    g = transpose(out[0])
    return [matmul(g, x) for x in out]


def spanning_tree_start(n, edges):
    """Compose the measurements along a breadth-first spanning tree from rotation 0."""
    adj = {i: [] for i in range(n)}
    for i, j, rt, _ in edges:
        adj[i].append((j, rt))
        adj[j].append((i, transpose(rt)))
    rs = {0: rot(0.0)}
    queue = [0]
    while queue:
        i = queue.pop(0)
        for j, rt in adj[i]:
            if j not in rs:
                rs[j] = matmul(rs[i], rt)
                queue.append(j)
    if len(rs) != n:
        raise ValueError("the measurement graph is not connected")
    return [rs[i] for i in range(n)]


def se_sync(n, edges, start=None, eps=1e-6, max_rank=10):
    """Return a dict with the rotations, the bounds, the final rank and the history."""
    q = connection_laplacian(n, edges)
    scale = max(abs(x) for row in q for x in row)
    rs = start if start is not None else spanning_tree_start(n, edges)
    y = [[0.0] * (2 * n) for _ in range(2)]
    for i, r in enumerate(rs):
        set_block(y, i, r)  # @line L1
    history = []
    while True:  # @line L2
        y, sweeps = local_search(q, y, n)  # @line L3
        s = certificate(q, y, n)  # @line L4
        vals, vecs = symmetric_eigen(s)  # @line L5
        lam_min = vals[0]
        history.append((len(y), relaxed_cost(q, y), lam_min, sweeps))
        if lam_min >= -eps * scale:  # @line L6
            break
        if len(y) >= max_rank:
            raise ValueError("the staircase reached the largest rank without a certificate")
        v = [vecs[k][0] for k in range(2 * n)]
        y = escape(q, y, n, v)  # @line L7
    lower = relaxed_cost(q, y)
    rounded = round_solution(y, n)  # @line L8
    upper = objective(edges, rounded)  # @line L9
    return {
        "rotations": rounded,
        "lower": lower,
        "upper": upper,
        "rank": len(y),
        "lam_min": lam_min,
        "history": history,
    }
test_se_sync.py 155 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/se-sync/. The authors are listed in prov/ZTRAGF.jsonl.

import math
import random

from se_sync import (
    angle,
    certificate,
    connection_laplacian,
    local_search,
    matmul,
    objective,
    relaxed_cost,
    riemannian_gradient_norm,
    rot,
    se_sync,
    set_block,
    symmetric_eigen,
    transpose,
)


def wrap(a):
    return (a + math.pi) % (2.0 * math.pi) - math.pi


def random_problem(seed, n, extra, sigma):
    """Random rotations, a spanning path plus extra edges, angle noise sigma (rad)."""
    rng = random.Random(seed)
    truth = [0.0] + [rng.uniform(-math.pi, math.pi) for _ in range(n - 1)]
    pairs = [(i, i + 1) for i in range(n - 1)]
    while len(pairs) < n - 1 + extra:
        i, j = sorted(rng.sample(range(n), 2))
        if (i, j) not in pairs:
            pairs.append((i, j))
    edges = [(i, j, rot(truth[j] - truth[i] + rng.gauss(0.0, sigma)), 1.0) for i, j in pairs]
    return truth, edges


def angles(rs):
    return [angle(r) for r in rs]


def test_cost_is_the_trace_form():
    _, edges = random_problem(1, 6, 5, 0.3)
    rng = random.Random(2)
    rs = [rot(rng.uniform(-3, 3)) for _ in range(6)]
    y = [[0.0] * 12 for _ in range(2)]
    for i, r in enumerate(rs):
        set_block(y, i, r)
    q = connection_laplacian(6, edges)
    assert abs(objective(edges, rs) - relaxed_cost(q, y)) < 1e-9


def test_noise_free_problem_is_solved_exactly_and_certified():
    truth, edges = random_problem(3, 8, 8, 0.0)
    out = se_sync(8, edges)
    assert out["upper"] < 1e-10 and abs(out["lower"]) < 1e-10
    for a, b in zip(angles(out["rotations"]), truth):
        assert abs(wrap(a - b)) < 1e-6


def test_low_noise_certifies_a_global_optimum():
    truth, edges = random_problem(4, 10, 10, 0.1)
    out = se_sync(10, edges)
    assert out["lam_min"] >= -1e-6 * 4
    # tight relaxation: the rounded solution attains the lower bound
    assert out["upper"] - out["lower"] < 1e-6 * max(1.0, out["upper"])
    assert max(abs(wrap(a - b)) for a, b in zip(angles(out["rotations"]), truth)) < 0.3


def test_certificate_vanishes_on_the_solution():
    _, edges = random_problem(5, 7, 6, 0.2)
    q = connection_laplacian(7, edges)
    y = [[0.0] * 14 for _ in range(2)]
    for i in range(7):
        set_block(y, i, rot(0.0))
    y, _ = local_search(q, y, 7)
    s = certificate(q, y, 7)
    # first order condition: Y S = 0, so S has the rows of Y in its null space
    ys = matmul(y, s)
    assert max(abs(x) for row in ys for x in row) < 1e-5
    assert riemannian_gradient_norm(q, y, 7) < 1e-4


def test_brute_force_on_three_rotations():
    for seed in range(3):
        truth, edges = random_problem(10 + seed, 3, 1, 0.8)
        edges = [(i, j, r, w) for (i, j, r, _), w in zip(edges, (1.0, 2.0, 0.5))]
        out = se_sync(3, edges)
        # grid over the two free angles, then a local refinement
        best = (float("inf"), 0.0, 0.0)
        steps = 72
        for a in range(steps):
            for b in range(steps):
                t1, t2 = 2 * math.pi * a / steps, 2 * math.pi * b / steps
                f = objective(edges, [rot(0.0), rot(t1), rot(t2)])
                if f < best[0]:
                    best = (f, t1, t2)
        f, t1, t2 = best
        h = 2 * math.pi / steps
        while h > 1e-9:
            moved = False
            for d1, d2 in ((h, 0), (-h, 0), (0, h), (0, -h)):
                g = objective(edges, [rot(0.0), rot(t1 + d1), rot(t2 + d2)])
                if g < f:
                    f, t1, t2, moved = g, t1 + d1, t2 + d2, True
            if not moved:
                h /= 2
        assert out["lower"] <= f + 1e-9
        assert abs(out["upper"] - f) < 1e-7


def twisted_cycle(n, k):
    """A noise-free cycle of n identity measurements, started at the winding k state."""
    edges = [(i, (i + 1) % n, rot(0.0), 1.0) for i in range(n)]
    start = [rot(2.0 * math.pi * k * i / n) for i in range(n)]
    return edges, start


def test_twisted_cycle_is_a_critical_point_that_the_certificate_rejects():
    n = 9
    edges, start = twisted_cycle(n, 1)
    q = connection_laplacian(n, edges)
    y = [[0.0] * (2 * n) for _ in range(2)]
    for i, r in enumerate(start):
        set_block(y, i, r)
    # every rotation is balanced between its two neighbors
    assert riemannian_gradient_norm(q, y, n) < 1e-9
    # the local search cannot leave it in rank 2
    y2, _ = local_search(q, [list(row) for row in y], n)
    assert abs(relaxed_cost(q, y2) - relaxed_cost(q, y)) < 1e-9
    vals, _ = symmetric_eigen(certificate(q, y, n))
    assert vals[0] < -0.1
    # the staircase escapes and finds the global optimum, cost 0
    out = se_sync(n, edges, start=start)
    assert out["rank"] >= 3
    assert out["upper"] < 1e-8
    assert out["history"][0][2] < -0.1


def test_eigen_solver_matches_a_known_matrix():
    rng = random.Random(7)
    a = [[rng.uniform(-1, 1) for _ in range(6)] for _ in range(6)]
    s = [[a[i][j] + a[j][i] for j in range(6)] for i in range(6)]
    vals, vecs = symmetric_eigen(s)
    for k, lam in enumerate(vals):
        v = [vecs[i][k] for i in range(6)]
        sv = [sum(s[i][j] * v[j] for j in range(6)) for i in range(6)]
        assert max(abs(x - lam * y) for x, y in zip(sv, v)) < 1e-10
    assert vals == sorted(vals)
    vt = transpose(vecs)
    eye = matmul(vt, vecs)
    assert max(abs(eye[i][j] - (1.0 if i == j else 0.0)) for i in range(6) for j in range(6)) < 1e-10

History

Synchronization problems over rotations were studied in computer vision and in signal processing before SLAM. Carlone, Rosen, Calafiore, Leonard and Dellaert used Lagrangian duality in 2015 to verify the optimality of a pose graph solution from a local solver. Rosen, Carlone, Bandeira and Leonard presented SE-Sync in 2016 and published the journal version in 2019. It joins the semidefinite relaxation, the low rank method of Burer and Monteiro (2003), and the Riemannian staircase of Boumal. Later certifiable methods extend the idea to landmarks, to robust costs and to distributed solvers.

References

  1. David M. Rosen, Luca Carlone, Afonso S. Bandeira and John J. Leonard, SE-Sync: a certifiably correct algorithm for synchronization over the special Euclidean group, International Journal of Robotics Research 38(2-3), 2019, pages 95 to 125, the semidefinite relaxation of pose graph optimization, the closed form elimination of the translations, the exact recovery guarantee for small noise (Proposition 2), the Riemannian staircase, the optimality certificate and the rounding procedure
  2. Samuel Burer and Renato D. C. Monteiro, A nonlinear programming algorithm for solving semidefinite programs via low-rank factorization, Mathematical Programming 95(2), 2003, pages 329 to 357, the low rank factorization Z = Y^T Y of the semidefinite variable
  3. Cesar Cadena, Luca Carlone, Henry Carrillo, Yasir Latif, Davide Scaramuzza, Jose Neira, Ian Reid and John J. Leonard, Past, present, and future of simultaneous localization and mapping: toward the robust-perception age, IEEE Transactions on Robotics 32(6), 2016, pages 1309 to 1332, the discussion of global optimality and certifiable back ends

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.certificate
  • a full proof of time.jacobi_sweep_dense
  • a full proof of time.local_search_sweep
  • a full proof of time.rounding
  • a full proof of space.iterate
  • a full proof of space.sparse_q
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example