如何使用networkX获得定向加权网络的拉普拉斯矩阵?

时间:2017-07-25 10:53:04

标签: python-3.x matrix networkx

我面临的问题是,当我改变权重时,它不会反映在拉普拉斯矩阵中

compile 'com.android.support:appcompat-v7:' + ANDROID_SUPPORT_LIBRARY_VERSION
compile 'com.android.support:design:' + ANDROID_SUPPORT_LIBRARY_VERSION
compile 'com.android.support:recyclerview-v7:' + ANDROID_SUPPORT_LIBRARY_VERSION

1 个答案:

答案 0 :(得分:1)

出现这种情况是因为DiGraph是一个三角形:

enter image description here

如果添加了额外的边缘:

enter image description here

拉普拉斯算子反映了权重:

import networkx as nx
G = nx.DiGraph()
G.add_weighted_edges_from([(1,2,0.65), (3,1,0.35), (2,3,0.85), (3,4,0.2)])
nx.directed_laplacian_matrix(G)
Out[1]:
matrix([[ 0.9875    , -0.45383656, -0.35847072, -0.10930101],
        [-0.45383656,  0.9875    , -0.45936416, -0.10267954],
        [-0.35847072, -0.45936416,  0.9875    , -0.34072508],
        [-0.10930101, -0.10267954, -0.34072508,  0.75      ]])

如果边缘权重更新,拉普拉斯算子反映了这一点:

G[3][1]['weight'] = 0.8
nx.directed_laplacian_matrix(G)
Out[2]:
matrix([[ 0.9875    , -0.47030901, -0.41990635, -0.0840537 ],
        [-0.47030901,  0.9875    , -0.47223262, -0.08179532],
        [-0.41990635, -0.47223262,  0.9875    , -0.25329959],
        [-0.0840537 , -0.08179532, -0.25329959,  0.75      ]])