示例#1
0
def wavelet_origin(dataset,
                   order,
                   threshold,
                   s,
                   mask,
                   data_normalize,
                   adj,
                   laplacian_normalize,
                   sparse_ness=False):
    from weighting_func import laplacian, fourier, weight_wavelet
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(dataset, L)

    Weight = weight_wavelet(s, lamb, U)
    del lamb, U, L

    if (sparse_ness):
        # for i in range(Weight.data.shape[0]):
        #     if(Weight.data[i] < threshold):
        #         Weight.data[i] = 0.0
        Weight[Weight < threshold] = 0

    Weight = sp.csr_matrix(Weight)
    Weight.setdiag([0.0] * Weight.shape[0])
    if (data_normalize == True):
        Weight = normalize(Weight, norm='l1', axis=1)

    t_k = [Weight]
    t_k.append(sp.eye(adj.shape[0]))
    return sparse_to_tuple(t_k)
示例#2
0
def wave_gcn(order,
             threshold,
             s,
             mask,
             data_normalize,
             weight_normalize,
             adj,
             laplacian_normalize,
             sparse_ness=False):
    from weighting_func import laplacian, fourier, weight_wavelet
    # wavelet community
    # adj = adj_matrix()
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(L)
    # print np.dot(np.dot(U,np.diag(lamb)),np.transpose(U))
    # U 列 eigen function
    Weight = weight_wavelet(s, lamb, U)
    t_k = to_gcn_weighting_function(order,
                                    threshold,
                                    mask,
                                    data_normalize,
                                    weight_normalize,
                                    adj,
                                    Weight,
                                    sparse_ness=sparse_ness)
    # return  U,Weight, t_k
    return sparse_to_tuple(t_k)
示例#3
0
def spectral_basis(dataset, adj, s, laplacian_normalize, sparse_ness,
                   threshold, weight_normalize):
    from weighting_func import laplacian, fourier, weight_wavelet, weight_wavelet_inverse
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(dataset, L)

    U = sp.csr_matrix(U)
    # U_transpose = sp.csr_matrix(np.transpose(U))
    t_k = [U]
    return sparse_to_tuple(t_k)
示例#4
0
def wavelet_basis_chebyshev(dataset, adj, s, laplacian_normalize, sparse_ness,
                            threshold, weight_normalize):
    from weighting_func import laplacian, fourier, weight_wavelet, weight_wavelet_inverse
    from pygsp import graphs, filters
    G = graphs.Graph(adj)
    taus = [s]
    g = filters.Heat(G, taus)
    signal_matrix = np.identity(G.N)
    Weight = g.filter(signal_matrix, method='chebyshev', order=50)

    # taus = [-s]
    # g = filters.Heat(G, taus)
    # signal_matrix = np.identity(G.N)
    # inverse_Weight = g.filter(signal_matrix, method='chebyshev', order=30)

    # 逆变换和正变换s不能共享,否则不可逆
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(dataset, L)
    # Weight = weight_wavelet(s, lamb, U)
    inverse_Weight = weight_wavelet_inverse(1.0, lamb, U)
    del U, lamb

    if (sparse_ness):
        Weight[Weight < threshold] = 0.0
        inverse_Weight[inverse_Weight < threshold] = 0.0
    print len(np.nonzero(Weight)[0])
    print len(np.nonzero(inverse_Weight)[0])

    if (weight_normalize == True):
        Weight = normalize(Weight, norm='l1', axis=1)
        inverse_Weight = normalize(inverse_Weight, norm='l1', axis=1)

    Weight = sp.csr_matrix(Weight)
    inverse_Weight = sp.csr_matrix(inverse_Weight)
    print Weight, inverse_Weight
    t_k = [inverse_Weight, Weight]
    # t_k = [Weight]
    return sparse_to_tuple(t_k)
示例#5
0
def wavelet_basis(dataset, adj, s, laplacian_normalize, sparse_ness, threshold,
                  weight_normalize):

    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(dataset, L)
    Weight = weight_wavelet(s, lamb, U)
    inverse_Weight = weight_wavelet_inverse(s, lamb, U)
    del U, lamb

    if (sparse_ness):
        Weight[Weight < threshold] = 0.0
        inverse_Weight[inverse_Weight < threshold] = 0.0
    # print len(np.nonzero(Weight)[0])

    if (weight_normalize == True):
        Weight = normalize(Weight, norm='l1', axis=1)
        inverse_Weight = normalize(inverse_Weight, norm='l1', axis=1)

    Weight = sp.csr_matrix(Weight)
    inverse_Weight = sp.csr_matrix(inverse_Weight)
    # print Weight
    t_k = [inverse_Weight, Weight]
    return sparse_to_tuple(t_k)
示例#6
0
def wave_basis(dataset, adj, s, laplacian_normalize, sparse_ness, threshold,
               weight_normalize):
    from weighting_func import laplacian, fourier, weight_wavelet, weight_wavelet_inverse
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(dataset, L)
    Weight = weight_wavelet(s, lamb, U)
    inverse_Weight = weight_wavelet_inverse(s, lamb, U)
    del U, lamb

    # positive_num = Weight[Weight > 0.0].shape[0]
    # nonzero_num = len(np.nonzero(Weight)[0])
    # print positive_num,nonzero_num
    # positive_num = inverse_Weight[inverse_Weight > 0.0].shape[0]
    # nonzero_num = len(np.nonzero(inverse_Weight)[0])
    # print positive_num, nonzero_num
    # inverse_Weight[inverse_Weight > -threshold] = 0.0
    # print len(np.nonzero(inverse_Weight)[0])
    # Weight[Weight > -threshold] = 0.0
    # print len(np.nonzero(Weight)[0])

    if (sparse_ness):
        Weight[Weight < threshold] = 0.0
        inverse_Weight[inverse_Weight < threshold] = 0.0
    print len(np.nonzero(Weight)[0])
    print len(np.nonzero(inverse_Weight)[0])

    if (weight_normalize == True):
        Weight = normalize(Weight, norm='l1', axis=1)
        inverse_Weight = normalize(inverse_Weight, norm='l1', axis=1)

    Weight = sp.csr_matrix(Weight)
    inverse_Weight = sp.csr_matrix(inverse_Weight)
    print Weight
    t_k = [inverse_Weight, Weight]
    # t_k = [Weight,inverse_Weight]
    # t_k = [Weight]
    return sparse_to_tuple(t_k)
示例#7
0
def wavelet_gcn_origin(order,
                       threshold,
                       s,
                       mask,
                       data_normalize,
                       adj,
                       laplacian_normalize,
                       sparse_ness=False):
    from weighting_func import laplacian, fourier, weight_wavelet
    L = laplacian(adj, normalized=laplacian_normalize)
    lamb, U = fourier(L)

    print U.shape, lamb[0], lamb[1]
    # print np.dot(np.dot(U,np.diag(lamb)),np.transpose(U))
    # U 列 eigen function
    Weight = weight_wavelet(s, lamb, U)

    if (mask == True):
        # mask 需要保留自身,为了使得自身的影响和其他可比,对adj加单位阵
        if (order == 0):
            adj = sp.csr_matrix(np.eye(adj.shape[0]))
        elif (order == 1):
            adj = adj + sp.csr_matrix(np.eye(adj.shape[0]))
        elif (order == 2):
            second_order = adj.dot(adj)
            adj = adj + sp.csr_matrix(np.eye(adj.shape[0])) + second_order
            del second_order
        elif (order == 3):
            second_order = adj.dot(adj)
            third_order = adj.dot(second_order)
            adj = adj + sp.csr_matrix(np.eye(
                adj.shape[0])) + second_order + third_order
            del second_order, third_order
        elif (order == 4):
            second_order = adj.dot(adj)
            third_order = adj.dot(second_order)
            four_order = adj.dot(third_order)
            adj = adj + sp.csr_matrix(np.eye(
                adj.shape[0])) + second_order + third_order + four_order
            del second_order, third_order, four_order

        Weight = adj.multiply(Weight)

    if (sparse_ness):
        # for i in range(Weight.data.shape[0]):
        #     if(Weight.data[i] < threshold):
        #         Weight.data[i] = 0.0
        Weight[Weight < threshold] = 0

    # 一阶关系利用GCN拟合,其他关系利用wavelet
    print len(np.nonzero(Weight)[0])
    Weight = np.multiply(Weight, (np.ones(shape=adj.shape) - adj))
    # Weight = Weight * (np.ones(shape=adj.shape) - adj)
    print len(np.nonzero(Weight)[0])

    Weight = sp.csr_matrix(Weight)
    Weight.setdiag([0.0] * Weight.shape[0])
    print len(np.nonzero(Weight)[0])
    if (data_normalize == True):
        Weight = normalize(Weight, norm='l1', axis=1)

    print Weight.shape
    print len(np.nonzero(Weight)[0])
    print Weight

    # print Weight.todense()

    # Weight = normalize(Weight + sp.eye(adj.shape[0]),norm='l1',axis = 1)
    t_k = [Weight]
    # 一阶和自身关系利用GCN拟合
    t_k.append(preprocess_adj(adj))
    # t_k.append(sp.eye(adj.shape[0]))
    return sparse_to_tuple(t_k)