2017-07-25 17 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

関連する問題