def rotation_measure(A, B):
'''
function rotationMeasure measures how close a matrix can be to another matrix by rotation
@param1: Matrix A
@param2: Matrix B
find the orthogonal matrix Q that minimizes ||A - BQ||_2
'''
# ask if the two matrics have the same shape
if A.shape != B.shape:
raise Exception('Two matrics do not have the same shape')
# C=B^T * A
C = B.conjugate().T.dot(A)
U = la.svd(C)[0]
Vh = la.svd(C)[2]
# Q = UVh
return U.dot(Vh)
# compute the minimal angle between subspaces
评论列表
文章目录