API reference

FastLieAlign — Module
FastLieAlign

Julia implementation of the optimal-alignment method of

Congzhou M Sha, "Optimal alignment of Lorentz orientation and
generalization to matrix Lie groups" (arXiv:2506.14994), now
expanded to arbitrary matrix Lie groups ("Vector alignment in matrix
Lie groups").

Given corresponding vectors {v{A,i}} measured in frame A and {v{B,i}} measured in frame B, sharing a common origin, we seek the group element Λ ∈ G (a matrix Lie group) such that Λ v{A,i} ≈ v{B,i}.

The "Lie algebra method" (Method 2 in the paper) generalizes to any matrix Lie group:

  1. Λ₀ = Y X⁺ (unconstrained least-squares, Moore–Penrose)
  2. l₀ = log Λ₀ (matrix logarithm)
  3. l = proj_𝔤(l₀) (orthogonal Frobenius projection onto the algebra)
  4. Λ = exp l (matrix exponential)

X (resp. Y) stacks the v{A,i} (resp. v{B,i}) as columns.

The only group-specific ingredient is the linear projection proj_𝔤 onto the Lie algebra 𝔤 ⊂ gl(n). Each classical group below provides one.

source

Groups

FastLieAlign.Spin — Type

Spin(n) — the simply-connected double cover of SO(n), realized in its 2^⌊n/2⌋-dimensional spinor representation generated by Euclidean gamma matrices. Its Lie algebra is spanned by the bivectors ½γᵢγⱼ (i<j), a copy of 𝔰𝔬(n).

source
FastLieAlign.Pin — Type

Pin(n) — the double cover of O(n). It is realized in dimension 2^⌊(n+1)/2⌋ by the generators ε_a = i γ_a γ_{n+1}, a = 1, …, n, of a Clifford representation with n+1 generators, which are Hermitian, anticommute and square to I, together with the grading Γ = γ_{n+1}, which anticommutes with every ε_a: the even elements of Pin(n) (the subgroup Spin(n)) commute with Γ and the odd ones anticommute. The covering map Pin(n) → O(n) is the twisted adjoint representation α(g) ε_b g⁻¹ = Σ_a R_ab ε_a with α(g) = Γ g Γ, under which a unit vector ũ = Σ u^a ε_a covers the reflection I - 2uuᵀ. The Lie algebra is 𝔰𝔭𝔦𝔫(n), the span of ε_a ε_b.

source
FastLieAlign.SpecialEuclidean — Type

SE(p,q) — the special Euclidean / inhomogeneous orthogonal group SO(p,q) ⋉ ℝ^{p+q}, acting on homogeneous coordinates as the (p+q+1)-square matrices [Λ t; 0 1] with Λ ∈ SO(p,q) and t a translation.

source
FastLieAlign.Similarity — Type

Sim(n) — the similarity group ℝ⁺ × SO(n) ⋉ ℝⁿ of scalings, rotations and translations, acting on homogeneous coordinates as the (n+1)-square matrices [s R t; 0 1] with s > 0 and R ∈ SO(n). Its Lie algebra is the matrices [c I + a v; 0 0] with a ∈ 𝔰𝔬(n), c ∈ ℝ and v ∈ ℝⁿ.

source
FastLieAlign.algebra_projection — Function
algebra_projection(G, l₀) -> l

Orthogonal projection (w.r.t. the real Frobenius inner product ⟨A,B⟩ = Re tr(A'B)) of an arbitrary matrix l₀ onto the Lie algebra of G. This is the proj_𝔤 operator of the paper (Eq. 16/17 for the Lorentz case).

source
FastLieAlign.algebra_basis — Function
algebra_basis(G) -> Vector{Matrix}

Orthonormal (real Frobenius) basis of the Lie algebra 𝔤, obtained by projecting the standard matrix units onto 𝔤 and Gram–Schmidt orthonormalizing. For complex groups the algebra is treated as a real vector space (units Eᵢⱼ and i·Eᵢⱼ). The length of the basis is the real dimension of the group.

source
FastLieAlign.component_representatives — Function
component_representatives(G) -> Vector{Matrix}

One representative of each connected component of G, the identity first. Orthogonal(n; special=false) and real GeneralLinear(n) have two components (sign of the determinant); IndefiniteOrthogonal(p, q; special=false) has four (signs of det g and of the determinant of the upper left p×p block); the connected groups have one.

source

Alignment

FastLieAlign.naive_align — Function
naive_align(G, X, Y) -> Λ

Lie algebra alignment method. X and Y are n × m matrices whose columns are the corresponding vectors v{A,i} and v{B,i}. Returns the estimated group element Λ ∈ G minimizing ‖Λ X − Y‖ subject to Λ ∈ G (to leading order).

source
FastLieAlign.branch_cut_align — Function
branch_cut_align(G, X, Y) -> Λ

Algorithm 2 of the manuscript, the Lie algebra method extended to the whole group. With g0 = Y X⁺ it returns r exp(proj log(r⁻¹ g0)), where r is the involution of negative_involution for the real groups, the even reflection of even_reflection for SL(n, ℂ) and SU(n), which makes the logarithm traceless, and for Spin(n) it calls spin_align. On noiseless data it returns every element of the group exactly (Theorem 2.3 of the manuscript).

source
FastLieAlign.negative_involution — Function
negative_involution(G, g0) -> r

Algorithm 3 of the manuscript for the groups other than SL(n, ℂ) and SU(n). The involution r = I - 2P which negates the eigenvalues of g0 in the open left half plane, so that r is the matrix sign function of g0 and r⁻¹ g0 has no negative real eigenvalue. For the groups preserving a form, P is the projector onto the invariant subspace N of those eigenvalues which is orthogonal with respect to the form, P = Q (Q⋆ M Q)⁻¹ Q⋆ M with Q a basis of N from the ordered Schur form, so that r is the reflection across N for the form and lies in the group exactly, also under noise; it coincides with the spectral projector when g0 is in the group. For the groups preserving no form (GL(n, F), SL(n, ℝ)) the same formula is used with M = I, so r = I - 2 Q Q⋆ is a unitary (real orthogonal) reflection which, in the Schur basis, negates exactly the eigenvalues of N. For the Euclidean groups the construction is applied to the rotation block. Returns the identity when g0 has no eigenvalue in the left half plane.

source
FastLieAlign.even_reflection — Function
even_reflection(g0) -> r

Algorithm 3 of the manuscript for SL(n, ℂ) and SU(n), the involution of branch_cut_align for these groups. Every logarithm of an element of these groups has trace 2πik; the principal one has k = round(Σ arg λ_i / 2π), which need not vanish. Reflecting an eigenvalue λ_i through the origin, λ_i ↦ -λ_i, moves its principal argument by s_i π with s_i = +1 for arg λ_i < 0 and s_i = -1 for arg λ_i > 0. A set S of eigenvalues with Σ_{i∈S} s_i = -2k therefore makes the logarithm traceless; such a set always exists because every argument is smaller than π in size, and |S| is automatically even. S must contain every negative real eigenvalue (otherwise the principal logarithm is undefined) and no positive real one (the reflection would put it on the cut); both are enforced by the cost π(π - 2|arg λ_i|) of a flip, the change of Σ|log λ|², which the selection minimizes. The reflection r = I - 2 Q₁ Q₁ᴴ through the invariant subspace spanned by the Schur vectors of S is unitary with det r = (-1)^{|S|} = 1, so it lies in SU(n) ⊂ SL(n, ℂ), and r g0 has the eigenvalues of g0 with those in S negated. Repeated eigenvalues and Jordan blocks need no special treatment, since any leading set of Schur vectors spans an invariant subspace.

source
FastLieAlign.spin_align — Function
spin_align(G::Spin, X, Y) -> Λ

Algorithm 4 of the manuscript, the branch-cut aware method for Spin(n). The rotation R₀ = spin_covering(g0) covered by g0 = Y X⁺ is factored as r_R exp(A) by the SO(n) case of branch_cut_align; the lifts r̃ = spin_lift_involution(r_R) and B = spin_lift(A) give the two elements ±r̃ exp(B) of Spin(n) covering it, the data choose the sign ζ, and the output is ζ r̃ exp(B + proj log(exp(-B) r̃⁻¹ ζ g0)), the projected logarithm of g0 on the sheet of B.

source
FastLieAlign.spin_covering — Function
spin_covering(G::Spin, g) -> R

The covering map Spin(n) → SO(n): g γ_b g⁻¹ = Σ_a R_ab γ_a, so R_ab = tr(γ_a g γ_b g⁻¹)/d. For Pin(n) it is the twisted adjoint representation α(g) ε_b g⁻¹ = Σ_a R_ab ε_a onto O(n), with α(g) = Γ g Γ. For g outside the group it returns the matrix of these traces, which is close to an orthogonal matrix when g is close to the group.

source
FastLieAlign.spin_lift — Function
spin_lift(G::Spin, A) -> B

The lift of A ∈ 𝔰𝔬(n) to the bivector B = ¼ Σ_ab A_ab γ_a γ_b ∈ 𝔰𝔭𝔦𝔫(n), so that exp(B) covers exp(A).

source
FastLieAlign.spin_lift_involution — Function
spin_lift_involution(G::Spin, rR) -> r̃

A lift of the involution rR = I - 2P ∈ O(n), the reflection of the k-dimensional subspace N = range(P): with u_1, …, u_k an orthonormal basis of N and ũ = Σ_a u^a γ_a, the lift is ũ_1 ũ_2 ⋯ ũ_k, which lies in Spin(n) for even k (where it is Π_j exp(π ũ_{2j-1} ũ_{2j} / 2)) and in the odd component of Pin(n) for odd k. The other lift is its negative.

source
FastLieAlign.align_components — Function
align_components(G, X, Y; all = false) -> Λ

The Lie algebra method on a group with several connected components. Each component is a coset h G⁰, so the method is applied to (X, h⁻¹Y) for a representative h of the component and the result is h Λ'. By default the component is read off the signs of det g₀ and, for O(p,q), of the upper left block of g₀ = Y X⁺, which is reliable when the noise is small; with all = true every representative is tried and the candidate with the smallest residual ‖ΛX − Y‖ is returned.

source
FastLieAlign.gauss_newton_refine — Function
gauss_newton_refine(G, X, Y; iters=12, tol=1e-13) -> Λ

Data-covariance correction of naive_align. The closed-form estimate minimizes the alignment objective only to leading order, because step 3 of naive_align projects in the algebra under the flat Frobenius metric whereas ‖gX − Y‖² weights directions by the data covariance S = XX† (see the error analysis in the paper). The constrained optimum solves the data-weighted normal equations G c = b with G_kj = ⟨Bₖ ΛX, Bⱼ ΛX⟩ and b_k = ⟨Bₖ ΛX, R⟩, R = Y − ΛX; i.e. the correction δl = Σ cₖ Bₖ ∈ 𝔤 is the pseudoinverse solution c = D⁺ vec(R) of the design D = [vec(B₁ ΛX) … vec(B_d ΛX)] (real and imaginary parts stacked for complex groups). Applying Λ ← exp(δl) Λ ∈ G and repeating once or twice to absorb the nonlinearity of exp reaches the constrained least-squares optimum of align_direct/align_newton at the cost of one extra pseudoinverse, with no nonlinear optimizer. On noiseless data R = 0, so c = 0 and the correction is inactive.

source
FastLieAlign.align_newton — Function
align_newton(G, X, Y; maxiter=100) -> Λ

Direct nonlinear optimization by Newton's method in optimization, started from the identity (θ = 0). Like align_direct it minimizes ‖Λ(θ)X − Y‖² over Lie-algebra coordinates θ, but updates θ with damped Newton steps (Hessian from central-differenced ReverseDiff gradients) rather than BFGS. Returns Λ = exp(Σ θₖ Bₖ) ∈ G.

source
FastLieAlign.align_newton_full — Function
align_newton_full(G, X, Y; maxiter=100, init=nothing) -> Λ

Like align_newton, but forms the exact Hessian by forward-over-reverse automatic differentiation (the ForwardDiff Jacobian of the ReverseDiff gradient) rather than central-differencing the gradient. With init it warm-starts at the Lie-algebra coordinates of that group element.

source
FastLieAlign.align_direct — Function
align_direct(G, X, Y; maxiter=500, init=nothing) -> Λ

Direct nonlinear optimization (Method 1 of the paper), generalized to any classical group. Minimizes ‖Λ(θ)X − Y‖² over Lie-algebra coordinates θ via BFGS with reverse-mode AD gradients (ReverseDiff.jl), returning Λ = exp(Σ θₖ Bₖ) ∈ G. Slower than naive_align but serves as an independent baseline; with exact gradients the two methods agree (cf. paper Figs. 1–2). Pass init = naive_align(G, X, Y) to warm-start the BFGS at the closed-form solution.

source
FastLieAlign.align_se — Function
align_se(G, PA, PB) -> M

Special Euclidean alignment via the Lie algebra method. PA, PB are (p+q)×m matrices of corresponding points related by p_{B,i} = Λ p_{A,i} + t. Lifts the points to homogeneous coordinates and applies naive_align on the full group G = SpecialEuclidean(p,q), jointly recovering rotation/boost and translation as a single (p+q+1)-square element [Λ t; 0 1].

source
FastLieAlign.align_se_centroid — Function
align_se_centroid(G, PA, PB) -> M

Traditional decoupled alignment (the classical Kabsch/Procrustes recipe for rigid motions): center each point set on its centroid, solve for the optimal linear part Λ ∈ SO(p,q) on the centered vectors, then recover the translation t = c_B − Λ c_A from the centroids. Returned as [Λ t; 0 1].

Centering is exact: if p_{B,i} = Λ p_{A,i} + t then the centered vectors satisfy q_{B,i} = Λ q_{A,i} (the translation cancels), so this agrees with align_se in the noiseless case.

source
FastLieAlign.align_error — Function
align_error(Λ_est, Λ_true) -> (l2, linf)

Frobenius (L²) and max (L∞) element-wise errors between the estimated and true transformation matrices, as reported in Figs. 1–2 of the paper.

source