簡體   English   中英

Katz 中心性錯誤:PowerIterationFailedConvergence '冪迭代未能在 1000 次迭代內收斂')

[英]Katz Centrality Error: PowerIterationFailedConvergence 'power iteration failed to converge within 1000 iterations')

嘗試計算 NetworkX 中加權圖的 Katz 中心性時,我收到一個名為 PowerIterationFailedConvergence: (PowerIterationFailedConvergence(...), 'power iteration failed to convergence within 1000 iterations') 的錯誤。 我嘗試將 max_iter 屬性設置為最高 100000,但它仍然無法收斂。 高於此值會導致程序永遠運行。 與默認值 1e-06 相比,我還嘗試將 tol 屬性更改為 1e-03,但沒有運氣。 當我刪除 weight 屬性時,代碼運行沒有錯誤,但沒有給我想要的結果,因為這樣圖表不計為加權。

我在下面添加了導致錯誤的代碼,這很奇怪,因為我對包括特征向量在內的其他中心性的計算工作完美。

錯誤代碼(Katz 中心性):

#katz centrality
katz_centrality = nx.katz_centrality(G, weight = 'weight')

for x in range(5):
  print(katz_centrality[x])

無錯誤代碼(例如特征向量中心性):

#eigenvector centrality
eigenvector_centrality = nx.eigenvector_centrality(G, weight= 'weight')

for x in range(5):
  print(eigenvector_centrality[x])

這是G背后的代碼:

G = nx.from_numpy_matrix(network_matrix)

這是network_matrix

[[0. 5. 5. 5. 9. 3. 3. 3. 2. 3. 0. 0. 2. 0. 0. 0.]
 [5. 0. 7. 9. 4. 2. 2. 2. 1. 0. 1. 0. 0. 0. 0. 0.]
 [5. 7. 0. 7. 4. 1. 1. 1. 0. 0. 1. 0. 0. 0. 0. 0.]
 [5. 9. 7. 0. 4. 2. 2. 2. 1. 0. 1. 0. 0. 0. 0. 0.]
 [9. 4. 4. 4. 0. 2. 2. 2. 1. 4. 0. 0. 2. 0. 0. 0.]
 [3. 2. 1. 2. 2. 0. 5. 2. 3. 1. 0. 0. 0. 0. 0. 0.]
 [3. 2. 1. 2. 2. 5. 0. 2. 3. 1. 0. 0. 0. 0. 0. 0.]
 [3. 2. 1. 2. 2. 2. 2. 0. 2. 1. 0. 0. 0. 0. 0. 0.]
 [2. 1. 0. 1. 1. 3. 3. 2. 0. 1. 0. 0. 0. 0. 0. 0.]
 [3. 0. 0. 0. 4. 1. 1. 1. 1. 0. 1. 0. 3. 1. 1. 0.]
 [0. 1. 1. 1. 0. 0. 0. 0. 0. 1. 0. 0. 1. 3. 2. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
 [2. 0. 0. 0. 2. 0. 0. 0. 0. 3. 1. 0. 0. 1. 1. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 3. 0. 1. 0. 2. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 2. 0. 1. 2. 0. 0.]
 [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

使用 numpy 實現,它使用不同的求解器。

katz_centrality = nx.katz_centrality_numpy(G, weight= 'weight')

確保您已安裝 scipy >= 1.8。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM