Distances Between Subspaces

I’m working with some multi-dimensional float-valued data – I’ll call a single instance of this data XRn×k. I have multiple samples X1,X2Xt, and want to compare these subspaces – namely, I want to compute the distance between pairs of subspaces.

Let’s assume that our subspaces are not rank-deficient – i.e. for a given subspace sample, all of our dimensions are linearly independent. Thus, the k vectors form a basis set that spans some k-d subspace in Rn. We can think of each k-d subspace as a hyperplane in (k+1)-d space, just as we can think of a 2-d plane in 3-d space. One way to compare these subspaces is by using the “principle angles between subspaces” (or angles between flats). We can compare the “angles” between these hyperplanes, which will tell us how “far apart” the two subspaces are.

Intersecting 2D linear subspaces.

This comparison is effectively based on the QR decomposition and the Singular Value Decomposition. For two subspaces [U,W], we compute the QR decomposition of both:

U=QuRuW=QwRw

where Qu and QwRn×k are orthonormal bases such that QuTQu=QwTQw=Ik that span the same subspace as the original columns of U and W, and Ru and RwRk×k are lower triangular matrices. Next, we compute the matrix D=Qu,Qw=QuTQwRk×k, and then apply the singular value decomposition:

D=USVT

We can sort of think of D as the cross-covariance matrix. As such, the singular vectors represent the main orthogonal axes of cross-covariation between our two subspaces, while the singular values represent angles. In order to compute the principle angles of our subspaces, we simply take

θ=cos1(S)=cos1[σ1,σ2σk]

which gives us the principle angles (in radians). Because the SVD is invariant to sign (+/-), the principle angles range between [0,π2]. This means that subspaces that span the same space have a principle angle of 0, and subspaces that are orthogonal (maximally far apart) to one another have a principle angle of π2.

In order to compute the “distance” between our subspaces, we can apply various metrics to our vector of principle angles. The simplest approach is to apply the L2 norm to our vector of principle angles, θ, as

d(Xi,Xj)=n=1kcos1(σn)2

This metric is called the Grassmann Distance and is formally related to the geodesic distance between subspaces distributed on the Grassmannian manifold.

Grassmann manifold and its tangent space.

This, however, is a topic for another future blog post. There are a variety of metrics we can use to compute the pairwise distance between subspaces, some of which are

  • Asimov: max(θ)
  • Fubini-Study: cos1(sin(θ))
  • Spectral: 2sin(max(θ)2)

but all are fundamentally based on some function of our vector of principle angles, θ.

Data Scientist + Engineer