Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. def mds(d, dimensions=3, method='cpu'):
  2.     (n, n) = d.shape
  3.     E = (-0.5 * d ** 2)
  4.  
  5.     Er = np.mat(np.mean(E, 1))
  6.     Es = np.mat(np.mean(E, 0))
  7.  
  8.     # From Principles of Multivariate Analysis: A User's Perspective (page 107).
  9.     F = np.array(E - np.transpose(Er) - Es + np.mean(E))
  10.  
  11.     [U, S, V] = svd_cpu(F)
  12.  
  13.     Y = U * np.sqrt(S)
  14.  
  15.     return (Y[:, 0:dimensions], S)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement