graph_tool package¶
Reference page for the bluegraph.backends.graph_tool package. All the interfaces below are also available as bluegraph.backends.graph_tool.<interface> (for example, from bluegraph.backends.graph_tool import GTPathFinder
).
Graph metrics¶
- class bluegraph.backends.graph_tool.analyse.metrics.GTMetricProcessor(pgframe=None, directed=True)¶
- betweenness_centrality(distance=None, write=False, write_property=None)¶
Compute (weighted) betweenness centrality.
- closeness_centrality(distance=None, write=False, write_property=None)¶
Compute (weighted) closeness centrality.
- degree_centrality(weight=None, write=False, write_property=None)¶
Compute (weighted) degree centrality.
- pagerank_centrality(weight=None, write=False, write_property=None)¶
Compute (weighted) PageRank centrality.
Path search¶
- class bluegraph.backends.graph_tool.analyse.paths.GTPathFinder(pgframe=None, directed=True)¶
graph-tool-based shortest paths finder.
- get_distance(source, target, distance)¶
Get distance value between source and target.
- get_subgraph_from_paths(paths)¶
Get subgraph induced by a path.
- minimum_spanning_tree(distance, write=False, write_property=None)¶
Compute the minimum spanning tree.
- Parameters:
distance (str) – Distance to minimize when computing the minimum spanning tree (MST)
write (bool, optional) – Flag indicating whether the MST should be returned as a new graph object or saved within a Boolean edge property being True whenever a given edge belongs to the MST.
write_property (str, optional) – Edge property name for marking edges beloning to the MST.
- Returns:
tree – The minimum spanning tree graph object
- Return type:
nx.Graph
- n_shortest_paths(source, target, n, distance=None, strategy='naive', exclude_edge=False)¶
Compute n shortest paths from the source to the target.
Two search strategies are available: ‘naive’ and ‘yen’. The naive strategy first finds the set of all shortest paths from the source to the target node, it then ranks them by the cumulative distance score and returns n best paths. The second strategy uses Yen’s algorithm [1] for finding n shortest paths. The first naive strategy performs better for highly dense graphs (where every node is connected to almost every other node). Note that if there are less than n unweighted shortest paths in the graph, the naive strategy may return less than n paths.
1. Yen, Jin Y. “Finding the k shortest loopless paths in a network”. Management Science 17.11 (1971): 712-716.
- Parameters:
source (str) – Source node ID
target (str) – Target node ID
n (int) – Number of top paths to include in the result
distance (str, optional) – The name of the attribute to use as the edge distance
path_condition (func, optional) – Edge filtering function returning Boolean flag
strategy (str, optional) – Path finding strategy: naive or yen. By default, naive.
exclude_edge (bool, optional) – Flag indicating whether the direct edge from the source to the target should be excluded from the result (if exists).
- Returns:
paths – List containing top n best paths according to the distance score
- Return type:
list
- bluegraph.backends.graph_tool.analyse.paths.handle_exclude_gt_edge(method)¶
Method decorator that removes and restores the direct s/t edge.
Community Detection¶
- class bluegraph.backends.graph_tool.analyse.communities.GTCommunityDetector(pgframe=None, directed=True)¶
Graph-tool-based community detection interface.
This class provides a simple interface for detecting communities of densely connected nodes and evaluating community partitions.
Currently supported community detection strategies for ‘graph-tool’:
Statistical inference (strategy=”sbm”)
Hierarchical clustering (strategy=”hierarchical”)
References