networksns.centrality_measures.subgraph_centrality¶
- networksns.centrality_measures.subgraph_centrality(G, t=1, tol=1e-07, maxit=50)¶
Computes the subgraph centrality of all the nodes in graph \(G\).
The subgraph centrality of the \(i^{th}\) node is given by \([e^{tA}]_{ii}=e_i^T (e^{tA})e_i\), where \(e_i\) and \(A\) denote respectively the \(i^{th}\) vector of the canonical basis and the adjacency matrix of the graph [1].
- Parameters:
G (Graph or DiGraph object) – a graph.
t (scalar, optional) – when exponentiating multiply the adjacency matrix by t, default: 1.
tol (float,optional) – tolerance for convergence, relative accuracy, default: 1e-7.
maxit (integer, optional) – maximum number of Lanczos iterations, default: 50.
- Returns:
sc (dict) subgraph centrality of all nodes in \(G\).
Examples
>>> from networksns import centrality_measures as cm >>> import networkx as nx
Create graph \(G\).
>>> G = nx.Graph() >>> G.add_edge(1, 2) >>> G.add_edge(2, 3) EdgeView([(1, 2), (2, 3)])
Compute the subgraph centrality.
>>> sc = cm.subgraph_centrality(G)
References