def gower_matrix(X):
"""
Gower, J.C. (1966). Some distance properties of latent root
and vector methods used in multivariate analysis.
Biometrika 53: 325-338
@param X: ensemble coordinates
@type X: (m,n,k) numpy.array
@return: symmetric dissimilarity matrix
@rtype: (n,n) numpy.array
"""
X = numpy.asarray(X)
B = sum(numpy.dot(x, x.T) for x in X) / float(len(X))
b = B.mean(1)
bb = b.mean()
return (B - numpy.add.outer(b, b)) + bb
评论列表
文章目录