Skip to contents

Computes the similarity between two subspaces spanned by basis matrices using QR decomposition and SVD. This metric measures how well the estimated subspace recovers the true subspace, independent of rotation and scaling.

Usage

compute_subspace_similarity(L_true, L_hat)

Arguments

L_true

A (M x r_true) matrix representing the true basis.

L_hat

A (M x r_hat) matrix representing the estimated basis.

Value

Numeric scalar in [0, 1], where 1 indicates identical subspaces. Returns NA if inputs are invalid (NULL, empty, or contain NA/NaN/Inf).

Details

The subspace similarity is computed as follows:

  1. Orthonormalize both bases using QR decomposition

  2. Compute the SVD of Q_true' * Q_hat

  3. Return the mean of squared singular values (up to min_dim)

This metric is invariant to rotation and scaling of the basis vectors, making it suitable for comparing factor analysis solutions where rotation indeterminacy exists.

When r_true != r_hat, the metric uses min(r_true, r_hat) dimensions, which allows comparison even when the estimated rank differs from truth.

Examples

if (FALSE) { # \dontrun{
# Same subspace (rotated)
L_true <- matrix(c(1, 0, 0, 1), 2, 2)
R <- matrix(c(cos(pi/4), -sin(pi/4), sin(pi/4), cos(pi/4)), 2, 2)
L_hat <- L_true %*% R
compute_subspace_similarity(L_true, L_hat)  # Should be ~1

# Orthogonal subspaces
L_true <- matrix(c(1, 0, 0, 0), 2, 2)
L_hat <- matrix(c(0, 0, 0, 1), 2, 2)
compute_subspace_similarity(L_true, L_hat)  # Should be ~0
} # }