XtY = multiprod(multitransp(X), Y)
square_d = 0
for i in xrange(self._k):
s = np.linalg.svd(XtY[i], compute_uv=False)
// Ensure that -1 <= s <= 1
s = np.fmin(s, [1])
s = np.fmax(s, [-1])
square_d = square_d + np.linalg.norm(np.arccos(s))**2
After Change
// Geodesic distance for Grassmann
def dist(self, X, Y):
u, s, v = svd(multiprod(multitransp(X), Y))
s[s > 1] = 1
s = np.arccos(s)
return np.linalg.norm(s)