【问题标题】:Problem in calculating the symmetric normalised laplacian matrix计算对称归一化拉普拉斯矩阵的问题
【发布时间】:2020-05-25 16:50:55
【问题描述】:

我在python中计算对称归一化拉普拉斯矩阵时发现了一些问题。 假设有矩阵S及其对角度矩阵D:

    [ [ 1 , 0.5, 0.2]        [ [1.7, 0, 0 ]
S =   [0.5,  1 , 0.5]     D =  [ 0 , 2, 0 ] 
      [0.2, 0.5,  1 ] ]        [ 0 , 0,1.7] ]

当计算 L 时

我得到这个结果:

       [[ 0.41176471 -0.27116307 -0.11764706]
    L = [-0.27116307  0.5        -0.27116307]
        [-0.11764706 -0.27116307  0.41176471]]

使用此代码:

S = np.array([[1,0.5,0.2],[0.5,1,0.5],[0.2,0.5,1]])

print("Similiarity Matrix: \n",S)
print("\n\n")


D = np.zeros((len(S), len(S)))
#H = np.sum(G[0])
for id, x in enumerate(S):
    D[id][id] = np.sum(x)

I = np.identity(len(S))

L = I - ((sqrtm(inv(D))).dot(S)).dot(sqrtm(inv(D)))
print("\n\n")
print("Laplacian normalized: \n",L)

这与使用返回的函数csgraph.laplacian(S, normed=True) 不同:

       [[[ 1.        -0.5976143  -0.28571429]
    L = [-0.5976143   1.         -0.5976143 ]
        [-0.28571429 -0.5976143   1.        ]]

为什么会这样?我是不是做错了什么?

【问题讨论】:

    标签: python matrix linear-algebra matrix-multiplication algebra


    【解决方案1】:

    我注意到csgraph.laplacian 返回的未归一化矩阵和归一化矩阵之间的比率与未归一化矩阵和您的L 的比率密切相关:

    In [20]: csgraph.laplacian(S, normed=False) / L - 1
    Out[20]:
    array([[0.7       , 0.84390889, 0.7       ],
           [0.84390889, 1.        , 0.84390889],
           [0.7       , 0.84390889, 0.7       ]])
    
    In [21]: csgraph.laplacian(S, normed=False) / csgraph.laplacian(S, normed=True)
    Out[21]:
    array([[0.7       , 0.83666003, 0.7       ],
           [0.83666003, 1.        , 0.83666003],
           [0.7       , 0.83666003, 0.7       ]])
    

    0.84390889 ≠ 0.83666003 但其他数字匹配。差异可能仅仅是归一化造成的吗?

    【讨论】:

    • 不幸的是我不知道。我认为这种差异太小,无法在这两个矩阵中产生如此大的差异,但我完全不确定。
    【解决方案2】:

    那是因为你在 S 的对角线上有 1:

    # weighted adjacency
    S = np.array([[1,0.5,0.2],[0.5,1,0.5],[0.2,0.5,1]])
    
    np.fill_diagonal(S, 0.0)
    
    # strength diagonal matrix
    D = np.diag(np.sum(S,axis=1))
    
    # identity
    I = np.identity(S.shape[0])
    
    # D^{-1/2} matrix
    D_inv_sqrt = np.linalg.inv(np.sqrt(D))
    
    L = I - np.dot(D_inv_sqrt, S).dot(D_inv_sqrt)
    
    L
    
    array([[ 1.        , -0.5976143 , -0.28571429],
           [-0.5976143 ,  1.        , -0.5976143 ],
           [-0.28571429, -0.5976143 ,  1.        ]])
    

    【讨论】:

    • 您能否详细说明为什么此操作比对已经在邻接矩阵中的矩阵进行操作更好?很想知道!
    猜你喜欢
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多