Hi - I am trying to find a way to speed up a calculation of straightness centrality, defined here: Centrality Analysis. Betweenness, Closeness, Straightness… | by AxU Platform | Medium
It’s effectively the euclidean_distance (stored as node attributes) / network_dist
I tried using Dask to speed it up but it is still slow; would anyone have any reccomendations to use graph-tools to speed it up?
# def euclidean_dist(x1, y1, x2, y2):
# return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
# def bravo(target, k, vertID_dict, network_dist):
# euclidean_distance = euclidean_dist(vertID_dict[k][0], vertID_dict[k][1], vertID_dict[target][0], vertID_dict[target][1])
# return euclidean_distance / network_dist
# for k in tqdm(ego_graphs_2000):
# ego_graph = ego_graphs_2000[k]["graph"]
# straightness = 0
# sp = gt.shortest_distance(ego_graph, k, target=gt.shortest_distance weights=ego_graph.edge_properties["mm_len"])
# if len(sp.get_array()) > 0 and len(G) > 1:
# for target, value in enumerate(sp):
# if k != target:
# network_dist = sp_scattered[target]
# straightness += bravo(target, k, vertID_dict, network_dist)
# straightness_df[k] = straightness * (1.0 / (len(vertID_dict.keys()) - 1.0))
# else:
# straightness_df[k] = 0