I want to calculate the average shortest path length and diameter of a graph's giant component. The files are represented in .mat format.Is there any built-in function to do so?
data = loadmat("filename.mat")
data=coo_matrix(data.get('A'))
graph= igraph.Graph(zip(data.row.tolist(), data.col.tolist()))
As per this answer , we can find the giant component with the following function as follows.
def giant_component(graph):
"""Compute giant component.
Returns:
The giant component of `graph` as an `igraph.Graph`.
"""
vc = graph.components()
vc_sizes = vc.sizes()
return vc.subgraph(vc_sizes.index(max(vc_sizes)))
Its diameter can be found as giant_component(graph).diameter()
.
The Graph.shortest_paths
function will return a matrix containing all shortest path lengths, of which you can then compute the average.
np.mean(graph.shortest_paths())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.