我有两个部分的问题,与波音的OSMnx教程8街网络中心性分析。首先,我有一个关于边缘封闭中心性的知识问题,然后是一个关于边缘间中心性的基于代码的问题。我的目的是计算边缘贴近度和中间中心在不同的地点站周围。
1.边缘封闭中心性
下面的代码对我很有用:
# edge closeness centrality: convert graph to a line graph so edges become nodes and vice versa
edge_centrality = nx.closeness_centrality(nx.line_graph(G))
# list of edge values for the original graph
ev = [edge_centrality[edge + (0,)] for edge in G.edges()]
# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev]
问:有人能解释为什么在标准化代码中,最小边缘值乘以0.8,最大值设置为最大边缘值吗?我对文献不太熟悉,所以如果有任何建议,我将不胜感激。
2.边缘之间的中心性
我试图用类似于上面代码的方法计算边之间的中心性,以表示在示例中同一图上的边贴近中心性。我尝试过这样做,得到了以下信息:
# edge betweenness centrality
edge_bcentrality = nx.edge_betweenness_centrality(G)
# list of edge values for the orginal graph
ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]
# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(ev1)*0.8, vmax=max(ev1))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.inferno)
ec = [cmap.to_rgba(cl) for cl in ev1]
# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='k', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
edge_color=ec, edge_linewidth=1.5, edge_alpha=1)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-14-6ee1d322067c> in <module>()
1 # list of edge values for the orginal graph
----> 2 ev1 = [edge_bcentrality[edge + (0,)] for edge in G.edges()]
3
4 # color scale converted to list of colors for graph edges
5 norm = colors.Normalize(vmin=min(ev)*0.8, vmax=max(ev))
KeyError: (53090322, 53082634, 0)
如果有人建议最好的方法来计算边缘之间的中心性,我会非常感激,因为我仍然是一个新手。此外,如果有人能分享进行正常化的最佳方式,我们将不胜感激。
谢谢您抽时间见我,
BC
发布于 2019-11-16 21:40:54
我应用了这段代码,它适用于我。希望能帮上忙。
#calculate betweenness
betweenness = nx.edge_betweenness(G=G, normalized=False)
# iterate over edges
edges = []
for i in betweenness.items():
i = i[0] + (0,)
edges.append(i)
for i,j in zip(edges,betweenness.keys()):
betweenness[i] = betweenness[j]
del betweenness[j]
# color scale converted to list of colors for graph edges
norm = colors.Normalize(vmin=min(betweenness.values())*0.8, vmax=max(betweenness.values()))
cmap = cm.ScalarMappable(norm=norm, cmap=cm.viridis)
ec = [cmap.to_rgba(cl) for cl in betweenness.values()]
# color the edges in the original graph with betweeness centralities in the line graph
fig, ax = ox.plot_graph(G, bgcolor='w', axis_off=True, node_size=0, node_color='w', node_edgecolor='gray', node_zorder=2,
edge_color=ec, edge_linewidth=1.5, edge_alpha=1)
fig.show()
https://stackoverflow.com/questions/55330838
复制相似问题