def mds(matrix,n,outfile):
    '''Code for multi-dimensional scaling
       Take the eigendecomp of the gram matrix.
       Take the p largest eigenvectors where
       rank(G)< p, 
       ? p should be bounded by the number of attributes?
       ? so p < 3?
    '''
    print "--- Starting Multi-Dimensional Scaling ---\n"
    gram = gram_matrix(matrix,n)
    print "--- Starting Eigen Decomp --- \n"
    matrix_w = eigen_decomp(gram,dim= n)

    return matrix_w
示例#2
0
def lap(k,data,style_data,dim,outfile):
    ''' 1. Construct your k nearest neighbors adjacency matrix
        2. Use Heat Equation exp -{||x_i-x_j||^2/4t}
    '''    
    adjacency = knn(data,data.shape[1])
    heat = 1.0
    print "--- Seeting Weights on Adjacency Matrix ---\n"
    heat_matrix = set_weights(adjacency,k,heat)

    print "--- Creating Laplacian Matrix ---\n"

    laplacian, weight = get_laplacian(heat_matrix)

    print "--- Eigendecomp -> Points ---\n"

    points = eigen_decomp( laplacian,weight,dim)

    print "--- Plotting Points ---\n"

    plot_points(points,style_data, outfile)