Math - Frobenius Norm

Frobenius Norm as a Trace, Von-Neumann's Trace Inequality, Closest Rotation Matrix

Posted by Rico's Nerd Cluster on March 1, 2017

This post uses the trace properties from Math - Trace.

Preliminaries

Frobenius Norm as a Trace

\[\|A\|_F^2 = \operatorname{tr}(A^\top A)\]

The \(i\)-th diagonal entry of \(A^\top A\) is the squared length of the \(i\)-th column of \(A\). Summing over all columns adds up every squared entry of \(A\):

\[\begin{aligned} [A^\top A]_{ii} &= \sum_j A_{ji} A_{ji}, \\ \operatorname{tr}(A^\top A) &= \sum_i \sum_j A_{ji} A_{ji} = \|A\|_F^2 \end{aligned}\]

Von-Neumann’s Trace Inequality

In 1937, Von-Neumann proved that if \(A, B\) are complex \(n \times n\) matrices with singular values

\[a_1 \ge a_2 \ge \cdots \ge a_n,\quad b_1 \ge b_2 \ge \cdots \ge b_n\]

then

\[\lvert \operatorname{tr}(AB) \rvert \le \sum_i a_i b_i\]

The bound is reached, for example, when \(A\) and \(B\) are both diagonal with their singular values sorted the same way:

\[A = \operatorname{diag}(a_1, a_2, \dots, a_n),\quad B = \operatorname{diag}(b_1, b_2, \dots, b_n),\quad \operatorname{tr}(AB) = \sum_{i=1}^n a_i b_i.\]

Singular Values of a Rotation Matrix Are All 1

Let \(R \in SO(3)\), i.e., \(R^\top R = I\) and \(\det R = 1\). The singular values \(\{\sigma_i\}_{i=1}^3\) of \(R\) are the square roots of the eigenvalues of \(R^\top R\):

\[\sigma_i = \sqrt{\lambda_i(R^\top R)}.\]

Since \(R^\top R = I\), all eigenvalues of \(R^\top R\) are \(1\). Therefore,

\[\sigma_1 = \sigma_2 = \sigma_3 = 1.\]

Equivalently, in the SVD \(R = U\Sigma V^\top\) with orthogonal \(U\) and \(V\), we must have \(\Sigma = I\), so all singular values are \(1\).

Frobenius Norm

The Frobenius norm is the square root of the sum of all squared entries: \(\|A\|_F = \sqrt{\sum_i \sum_j a_{ij}^2}\).

E.g., a common task in lidar is: we have an estimate \(R\) of a rotation matrix that has drifted away from \(SO(3)\), and we want the closest true rotation \(X \in SO(3)\), i.e. the one with the lowest \(\|X - R\|_F\). Here’s how to find it.

Step 1: turn the norm into a trace. Using \(\|A\|_F^2 = \operatorname{tr}(A^\top A)\) and linearity,

\[\begin{aligned} \|X-R\|_F^2 &= \operatorname{tr}((X-R)^\top(X-R)) \\ &= \operatorname{tr}(X^\top X - X^\top R - R^\top X + R^\top R) \\ &= \operatorname{tr}(X^\top X) - \operatorname{tr}(X^\top R) - \operatorname{tr}(R^\top X) + \operatorname{tr}(R^\top R) \\ &= \|X\|_F^2 - \operatorname{tr}(X^\top R) - \operatorname{tr}(X^\top R) + \|R\|_F^2 \\ &= \|X\|_F^2 + \|R\|_F^2 - 2\operatorname{tr}(X^\top R) \end{aligned}\]

where the fourth line uses \(\operatorname{tr}(R^\top X) = \operatorname{tr}((X^\top R)^\top) = \operatorname{tr}(X^\top R)\).

Step 2: minimizing the norm means maximizing the trace. \(\|R\|_F^2\) is fixed, and \(\|X\|_F^2 = \operatorname{tr}(X^\top X) = \operatorname{tr}(I) = 3\) for any rotation \(X\). So both are constants, and

\[\arg\min_X \|X-R\|_F^2 = \arg\max_X \operatorname{tr}(X^\top R)\]

Step 3: simplify with the SVD. Take the SVD \(R = U\,\Sigma\,V^\top\), with \(U, V \in \mathrm{O}(3)\) and \(\Sigma = \operatorname{diag}(\sigma_1,\sigma_2,\sigma_3)\), \(\sigma_1 \ge \sigma_2 \ge \sigma_3 \ge 0\). Then define an intermediate variable

\[Y = U^\top X V \quad\Leftrightarrow\quad X = U Y V^\top\]

\(Y\) is a product of orthogonal matrices, so it is orthogonal too (\(Y \in \mathrm{O}(3)\)). Substituting, and then using cyclic shifting to move \(V^\top\) to the front:

\[\begin{aligned} \operatorname{tr}(X^\top R) &= \operatorname{tr}((UYV^\top)^\top (U \Sigma V^\top)) \\ &= \operatorname{tr}(VY^\top U^\top U \Sigma V^\top) \\ &= \operatorname{tr}(VY^\top \Sigma V^\top) \\ &= \operatorname{tr}(Y^\top \Sigma V^\top V) \\ &= \operatorname{tr}(Y^\top \Sigma) \end{aligned}\]

Step 4: watch the determinant. \(X\) must be a proper rotation, \(\det(X) = 1\), which pins down the determinant of \(Y\) (using \(\det(AB) = \det(A)\det(B)\)):

\[\det(Y) = \det(U^\top)\,\det(X)\,\det(V) = \det(U)\,\det(V)\cdot 1 = \det(UV^\top) \in \{\pm 1\}.\]

Step 5: pick the best \(Y\). By Von-Neumann’s trace inequality, \(\operatorname{tr}(Y^\top \Sigma)\) is largest when \(Y\) is diagonal, since \(\Sigma\) already is. A diagonal orthogonal matrix has \(\pm 1\) on its diagonal, so we maximize over those, subject to \(\det(Y) = \det(UV^\top)\):

  • If \(\det(UV^\top) = 1\), the maximizer is \(Y = I\), giving \(\operatorname{tr}(Y^\top \Sigma) = \sigma_1 + \sigma_2 + \sigma_3\).
  • If \(\det(UV^\top) = -1\), we need an odd number of \(-1\)’s, and the cheapest place to put one is on the smallest singular value: \(Y = \operatorname{diag}(1,1,-1)\), giving \(\operatorname{tr}(Y^\top \Sigma) = \sigma_1 + \sigma_2 - \sigma_3\).

Step 6: map back. Since \(X = U Y V^\top\), the closest rotation is

\[X^* = U\,\operatorname{diag}\big(1,\,1,\,\det(UV^\top)\big)\,V^\top.\]

In code:

1
2
3
4
5
6
7
8
9
10
11
12
Eigen::Matrix3d nearestRotation(const Eigen::Matrix3d& R) {
    Eigen::JacobiSVD<Eigen::Matrix3d> svd(R, Eigen::ComputeFullU | Eigen::ComputeFullV);
    Eigen::Matrix3d U = svd.matrixU();
    Eigen::Matrix3d Vt = svd.matrixV().transpose();
    Eigen::Matrix3d R_ortho = U * Vt;
    if (R_ortho.determinant() < 0.0) {
        Eigen::Matrix3d S = Eigen::Matrix3d::Identity();
        S(2,2) = -1.0;
        R_ortho = U * S * Vt;
    }
    return R_ortho;
}