我有一个与波音公司的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
答案 0 :(得分:0)
我应用了此代码,它对我有用。希望对您有所帮助。
#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()