0

我有一个与波音 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)

如果有人就计算边缘介数中心性的最佳方法提出建议,我将不胜感激,因为我仍然是新手。此外,如果有人可以分享进行标准化的最佳方法,我们将不胜感激。

感谢您的时间,

公元前

4

1 回答 1

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()
于 2019-11-16T21:40:54.370 回答