gpt4 book ai didi

python - Networkx 统计推断

转载 作者:太空狗 更新时间:2023-10-29 22:18:49 32 4
gpt4 key购买 nike

我有一个使用 networkx 成功创建的有向加权图。

我正尝试在此网络上生成一些统计推断,但我遇到了麻烦。他们在这里:

(i) 网络的平均度。 (我唯一能找到的是 average_degree_connectivity,它返回一个字典,而不是一个带有整个网络平均度数的 float )

(ii) 网络的平均加权度。 (同上)

(iii) 网络的平均聚类系数。 (我知道我必须使用 nx.average_clustering(g),但是我如何考虑它是加权有向图这一事实?我不断收到错误消息:NetworkXError: ('未定义聚类算法', '用于有向图。') )

谢谢!

最佳答案

(i) The Average degree of the network. (The only one I could find was average_degree_connectivity, which returns a dictionary and not a single float with the average degree of the whole network)

假设您的 Graph 对象是 G

degrees = G.degree()
sum_of_edges = sum(degrees.values())

计算平均值只是除以节点数的问题。

(ii) The Average weighted degree of the network. (same as above)

获取所有节点的列表,为每个节点获取所有边的列表,为每个节点求和权重属性:

edgesdict = G.edge
total = 0
for node_adjacency_dict in edgesdict.valuess():
total += sum([adjacency.get("weight",0) for adjacency in node_adjacency_dict.values()])

(iii) The Average clustering coefficient of the network. (I know that I have to use nx.average_clustering(g), however how do I take the fact that it is weighted directed graph into consideration? I keep getting the error: NetworkXError: ('Clustering algorithms are not defined ', 'for directed graphs.') )

要点是,在您定义它之前,它的定义并不明确。我认为,对于 StackOverflow 的回答来说,这有点太多了,所以我留给你为你的特定问题定义算法的问题。

(iv) The maximum shortest path length in the giant component of the network. (i know you find the giant component as such: giant = max(nx.connected_component_subgraphs(G), key=len) but how do we get the max shortest path length in it?)

运行 ipython 或其他东西。输入giant.;你会得到一个 list ,上面列出了你可以用 giant 做的事情。

关于python - Networkx 统计推断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29064636/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com