2017-07-25 389 views
0

我面臨的是,當我改變權重是不反映在拉普拉斯矩陣問題如何使用networkX獲得有向加權網絡的拉普拉斯矩陣?

import numpy as np 
import networkx as nx 
#construction of directed graph 
g=nx.DiGraph() 
#adding weights to the links 
g.add_weighted_edges_from([(1,2,0.65), (3,1,0.35),(2,3,0.85)]) 
#extracting the 
L = nx.directed_laplacian_matrix(g) 

L = nx.directed_laplacian_matrix(g) 
print(L) 

回答

0

這種現象的出現是因爲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  ]]) 
+0

是否有任何直接的方法來提取加權有向圖的拉普拉斯矩陣? – arjun