def principal_angles(X, Y, n):
'''
compute the principal angles between two subspaces
return: np.array of principal angles, orthogonal matrics U and V
'''
QX, RX = la.qr(X)
QY, RY = la.qr(Y)
if X.shape[1] >= Y.shape[1]:
C = QX.conjugate().T.dot(QY)
M, cos, Nh = la.svd(C)
U = QX.dot(M)
V = QY.dot(Nh.conjugate().T)
angles = np.arccos(cos)
return angles, U, V
else:
C = QY.conjugate().T.dot(QX)
M, cos, Nh = la.svd(C)
U = QX.dot(M)
V = QY.dot(Nh.conjugate().T)
angles = np.arccos(cos)
return angles, U, V
# Similarity between subspaces by Yamaguchi's definition
评论列表
文章目录