normalized_laplacian_matrix#
- normalized_laplacian_matrix(G, nodelist=None, weight='weight')[源代码]#
返回图 G 的归一化拉普拉斯矩阵。
归一化图拉普拉斯矩阵为
\[N = D^{-1/2} L D^{-1/2}\]其中
L
是图拉普拉斯矩阵,D
是节点度数的对角矩阵 [1]。- 参数:
- G图
一个 NetworkX 图
- nodelist列表,可选
行和列的顺序根据 nodelist 中的节点排列。如果 nodelist 为 None,则顺序由 G.nodes() 生成。
- weight字符串或 None,可选(默认值为 'weight')
用于计算矩阵中每个值的边数据键。如果为 None,则每条边权重为 1。
- 返回:
- NSciPy 稀疏数组
图 G 的归一化拉普拉斯矩阵。
另请参阅
laplacian_matrix
normalized_laplacian_spectrum
directed_laplacian_matrix
directed_combinatorial_laplacian_matrix
注意事项
对于 MultiGraph,边权重会被求和。有关其他选项,请参见
to_numpy_array()
。如果图包含自环,则 D 定义为
diag(sum(A, 1))
,其中 A 是邻接矩阵 [2]。此计算使用图
G
的出度。要改为使用入度进行计算,请使用G.reverse(copy=False)
并进行转置。要获得未归一化的输出,请使用
laplacian_matrix
。参考文献
[1]Fan Chung-Graham,《谱图理论》,CBMS 区域数学会议系列,第 92 期,1997年。
[2]Steve Butler,《使用归一化拉普拉斯矩阵的加权图交错》,电子线性代数杂志,第 16 卷,第 90-98 页,2007年3月。
[3]Langville, Amy N., 和 Carl D. Meyer。《Google 的 PageRank 及其他:搜索引擎排名的科学》。普林斯顿大学出版社,2006年。
示例
>>> import numpy as np >>> edges = [ ... (1, 2), ... (2, 1), ... (2, 4), ... (4, 3), ... (3, 4), ... ] >>> DiG = nx.DiGraph(edges) >>> print(nx.normalized_laplacian_matrix(DiG).toarray()) [[ 1. -0.70710678 0. 0. ] [-0.70710678 1. -0.70710678 0. ] [ 0. 0. 1. -1. ] [ 0. 0. -1. 1. ]]
请注意,节点 4 由第三列和第三行表示。这是因为默认情况下,行/列顺序是
G.nodes
的顺序(即节点添加顺序——在边列表中,节点 4 首先出现在 (2, 4) 中,然后才是边 (4, 3) 中的节点 3)。要控制矩阵的节点顺序,请使用nodelist
参数。>>> print(nx.normalized_laplacian_matrix(DiG, nodelist=[1, 2, 3, 4]).toarray()) [[ 1. -0.70710678 0. 0. ] [-0.70710678 1. 0. -0.70710678] [ 0. 0. 1. -1. ] [ 0. 0. -1. 1. ]] >>> G = nx.Graph(edges) >>> print(nx.normalized_laplacian_matrix(G).toarray()) [[ 1. -0.70710678 0. 0. ] [-0.70710678 1. -0.5 0. ] [ 0. -0.5 1. -0.70710678] [ 0. 0. -0.70710678 1. ]] ----
其他后端实现了此函数
graphblas:支持 OpenMP 的稀疏线性代数后端。