def cluster(S, k, ndim):
 if (sum(abs((S - S.T))) > 1e-10):
  print 'not symmetric'
 rowsum = sum(abs(S), axis=0)
 D = diag((1 / sqrt((rowsum + 1e-06))))
 L = dot(D, dot(S, D))
 (U, sigma, V) = linalg.svd(L, full_matrices=False)
 features = array(V[:ndim]).T
 features = whiten(features)
 (centroids, distortion) = kmeans(features, k)
 (code, distance) = vq(features, centroids)
 return (code, V)

def cluster ( S , k , ndim ) : if ( sum ( abs ( ( S - S . T ) ) ) > 1e-10 ) : print 'not symmetric' rowsum = sum ( abs ( S ) , axis = 0 ) D = diag ( ( 1 / sqrt ( ( rowsum + 1e-06 ) ) ) ) L = dot ( D , dot ( S , D ) ) ( U , sigma , V ) = linalg . svd ( L , full_matrices = False ) features = array ( V [ : ndim ] ) . T features = whiten ( features ) ( centroids , distortion ) = kmeans ( features , k ) ( code , distance ) = vq ( features , centroids ) return ( code , V )
spectral clustering from a similarity matrix .