attribute_assortativity_coefficient#

attribute_assortativity_coefficient(G, attribute, nodes=None)[源代码]#

计算节点属性的分类。

分类性度量图中连接相对于给定属性的相似性。

参数
G网络X图表
attribute字符串

节点属性键

nodes: list or iterable (optional)

计算容器中节点的属性分类度。默认为所有节点。

返回
R:浮点

图对给定属性的关联性

笔记

这将计算等式。(2)参考文献2 [1] ,(TRACE(M)-SUM(M^2))/(1-SUM(M^2)),其中M是指定属性的联合概率分布(混合矩阵)。

工具书类

1

M.E.J.Newman,《网络中的混合模式》,物理评论E,67 026126,2003

实例

>>> G = nx.Graph()
>>> G.add_nodes_from([0, 1], color="red")
>>> G.add_nodes_from([2, 3], color="blue")
>>> G.add_edges_from([(0, 1), (2, 3)])
>>> print(nx.attribute_assortativity_coefficient(G, "color"))
1.0