Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def lle(k,data,style_data,src,outfile,dim):
    '''1. Start with knn
    '''
    n = data.shape[1]
    # k+1 because nearest neighbor includes self
    matrix = knn(data,k+1)

    print "--- Seeting Weights on Adjacency Matrix ---\n"
    # weighted is a 500x500 matrix
    weighted = set_weights(matrix,data,k,dim,src,n)

    print "--- Embedding Coordinates ---\n"
    # matrix is nxn
    matrix = embedd_y(weighted,n)

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

    # return a 500x2 points
    points = get_points(matrix,dim,src)

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

    plot_points(np.transpose(points),style_data,outfile)