Centrality#
- raphtory.algorithms.degree_centrality(g, threads=None)#
Computes the degree centrality of all nodes in the graph. The values are normalized by dividing each result with the maximum possible degree. Graphs with self-loops can have values of centrality greater than 1.
- Parameters:
g (Raphtory Graph) – The graph view on which the operation is to be performed.
threads (Option<usize>, default = None) – The number of threads to be used for parallel execution. Defaults to single-threaded operation if not provided.
- Returns:
A result containing a mapping of node names to the computed sum of their associated degree centrality.
- Return type:
AlgorithmResult<String, OrderedFloat<f64>>
- raphtory.algorithms.pagerank(g, iter_count=20, max_diff=None, use_l2_norm=True, damping_factor=0.85)#
Pagerank – pagerank centrality value of the nodes in a graph
This function calculates the Pagerank value of each node in a graph. See https://en.wikipedia.org/wiki/PageRank for more information on PageRank centrality. A default damping factor of 0.85 is used. This is an iterative algorithm which terminates if the sum of the absolute difference in pagerank values between iterations is less than the max diff value given.
- Parameters:
g (Raphtory graph) – Raphtory graph
iter_count (int) – Maximum number of iterations to run. Note that this will terminate early if convergence is reached.
max_diff (float) – Optional parameter providing an alternative stopping condition. The algorithm will terminate if the sum of the absolute difference in pagerank values between iterations
is less than the max diff value given.
- Returns:
AlgorithmResult with string keys and float values mapping node names to their pagerank value.
- Return type:
- raphtory.algorithms.hits(g, iter_count=20, threads=None)#
HITS (Hubs and Authority) Algorithm: AuthScore of a node (A) = Sum of HubScore of all nodes pointing at node (A) from previous iteration /
Sum of HubScore of all nodes in the current iteration
- HubScore of a node (A) = Sum of AuthScore of all nodes pointing away from node (A) from previous iteration /
Sum of AuthScore of all nodes in the current iteration
- Parameters:
g (Raphtory Graph) – Graph to run the algorithm on
iter_count (int) – How many iterations to run the algorithm
threads (int) – Number of threads to use (optional)
- Returns
An AlgorithmResult object containing the mapping from node ID to the hub and authority score of the node
- raphtory.algorithms.betweenness_centrality(g, k=None, normalized=True)#
Computes the betweenness centrality for nodes in a given graph.
- Parameters:
g (Raphtory Graph) – A reference to the graph.
k (int, optional) – Specifies the number of nodes to consider for the centrality computation. Defaults to all nodes if None.
normalized (boolean, optional) – Indicates whether to normalize the centrality values.
- Returns:
Returns an AlgorithmResult containing the betweenness centrality of each node.
- Return type:
AlgorithmResult[float]