def compute_distances(matrix1, matrix2): nmatrix1 = normalize(matrix1) nmatrix2 = normalize(matrix2) distances = np.arccos(np.maximum(-1, np.minimum(1, dot(nmatrix1, nmatrix2.T)))) assert isinstance(distances, DenseMatrix) assert distances.same_row_labels_as(nmatrix1) return multiply(distances, distances)
def compute_distances(matrix1, matrix2): nmatrix1 = normalize(matrix1) nmatrix2 = normalize(matrix2) distances = np.arccos( np.maximum(-1, np.minimum(1, dot(nmatrix1, nmatrix2.T)))) assert isinstance(distances, DenseMatrix) assert distances.same_row_labels_as(nmatrix1) return multiply(distances, distances)
def project(self, vector): # vector can in fact be a matrix of many vectors # Dimensions: # vector = (m x ndim) or possibly just (ndim), # with ndim = K from the SVD # dist = (m x N) # means = (N) # mdsarray_sharp = (N x k) dist = (compute_distances(vector, self.landmarks) - self.means) / 2 return dot(dist, -self.mdsarray_sharp)