Network Metrics: Centrality, PageRank, Clustering, and Communities
Complex Systems · 5/8 · Series index · Notation
Graph representations and connectivity are developed in Network fundamentals.
Network Metrics and Algorithms
Unless stated otherwise, formulas refer to simple, undirected, unweighted graphs without self-loops. There are nodes and edges.
Distance, Eccentricity, Diameter, and Radius
The shortest-path distance is the length of the shortest feasible path from to . In an unweighted graph, length counts edges. If weights represent distances or costs, length is the sum of the weights along the path. A stronger connection need not represent a greater distance: interpret the weights before choosing an algorithm.
is the mean shortest-path length, also called the characteristic path length. The eccentricity measures the greatest distance from ; is the diameter and the radius. The center consists of nodes with , and the periphery of nodes with . A connected undirected graph satisfies : any two nodes can be connected via a center node by a walk of length at most .
Conditions: finite whole-graph distance formulas require all relevant pairs to be reachable. Disconnected graphs contain pairs with . One can instead analyse the largest connected component or average over reachable pairs, but must state the convention. In directed graphs, retain edge directions; reachability for every ordered pair requires strong connectivity.
Degree, Closeness, and Betweenness: Different Meanings of Importance
Degree centrality is
It measures the number of direct neighbours. Directed versions use or . If means “ follows ,” having many followers means high in-degree, while following many accounts means high out-degree. An interpretation such as “influence equals out-degree” cannot be separated from the meaning of an edge.
Closeness centrality is
It is the reciprocal of mean distance: a larger value means a node is closer, on average, to the others. In a directed graph distinguish outward distances, from the node to others, from inward distances, from others to the node. NetworkX uses inward distances by default; call the function on the reversed graph for outward closeness. Its default correction for disconnected graphs is, with other nodes able to reach ,
The value is zero when no other node can reach .
For betweenness centrality, let be the number of shortest paths from to , and the number passing through as an internal node. For , normalized undirected betweenness is
If the sum instead includes ordered pairs , use the prefactor . Unreachable pairs contribute zero, and endpoints are excluded from internal passage. Betweenness measures a node's role as a bridge between regions. When several shortest paths exist, divide the contribution among them instead of selecting just one.
Choosing a metric: use degree for direct connection count, closeness for average reachability distance, and betweenness for shortest-path bottlenecks between communities. These measures can produce different rankings; no single centrality is best for every task.
Eigenvector Centrality and Katz Centrality
Eigenvector centrality gives more credit for connections to important neighbours. For an undirected graph,
Choose a nonnegative eigenvector corresponding to the spectral radius and specify its normalization. For a connected graph, the Perron–Frobenius properties of its nonnegative adjacency matrix give a unique positive direction. Disconnected graphs can introduce nonuniqueness or zero components.
Our convention is for , so importance received through incoming edges satisfies
This is a left eigenvector of , or a right eigenvector of when written as a column. NetworkX uses this incoming-edge definition. To receive scores from outgoing neighbours instead, use .
Left/right eigenvectors and in/out-degree must be interpreted using a consistent adjacency convention. A directed acyclic graph (DAG) has only zero adjacency eigenvalues, making ordinary eigenvector centrality degenerate. This does not mean every mathematical eigenvector must be the zero vector. The issue is that the usual propagation rule with a positive eigenvalue does not provide an appropriate unique positive ranking.
Katz centrality adds a baseline score to every node. Set for an undirected graph and for incoming-edge centrality in a directed graph:
Expanding the inverse as a geometric series gives
Thus walks of length receive weight . The parameter controls the influence of distant walks. A uniform , often set to one, changes only the overall scale. Changing can alter relative scores and potentially the ranking; knowing only is insufficient. The inverse gives an unnormalized solution; nx.katz_centrality normalizes its Euclidean norm to one by default. If , as for a DAG, the series terminates after finitely many terms, so there is no finite upper bound.
PageRank: Probability Flow with Random Teleportation
Katz transfers importance without dividing each node's contribution by its out-degree. PageRank instead describes a random walk: node divides its score equally among the nodes it points to, while teleportation occurs with probability . The damping factor satisfies , commonly ; this differs from Katz's spectral-radius condition.
Let be a row-stochastic matrix. For an unweighted graph without dangling nodes, . When , replace that row with the teleportation distribution ; uniform teleportation has . In column-vector notation,
With uniform teleportation, every node receives baseline probability . For normalized PageRank with uniform teleportation, the baseline vector is . Equivalently, the Google matrix is
A quick check is to sum the components: both sides must sum to one. Replacing dangling rows by the teleportation distribution keeps the transition matrix row-stochastic.
Worked example: suppose the only edge is , with uniform teleportation. Replace the second transition row by . Then
At , the scores are approximately . Node 2 does not absorb and destroy the total probability merely because it has no outgoing edges.
Cores, Local Clustering, and Global Transitivity
A -core is the maximal induced subgraph obtained by repeatedly removing nodes whose current degree is below . Every remaining node has degree at least within the subgraph. A node's core number is the largest for which it belongs to a -core. Degrees must be updated within the remaining subgraph after each removal. A node with a large original degree can still have core number one if it is connected only to leaves, as in a star.
A node in a -core needs at least neighbours within that core; those neighbours may have higher core numbers. They need not all have exactly the same coreness. A -core also need not be the innermost core.
For the local clustering coefficient, let count triangles containing , equivalently edges between its neighbours. Then
The mean local clustering weights nodes equally. In a simple undirected graph, useful checks are and the total triangle count .
Global transitivity is
NetworkX defines transitivity as zero when there are no connected triples. The denominator counts pairs of neighbours centred on a node; each triangle contributes three closed triples. Transitivity weights local coefficients by neighbour-pair counts, so it generally differs from . Neither is universally larger. Transitivity can be smaller when high-degree nodes have low local clustering.
Assortativity, Communities, and Modularity
Assortativity measures the correlation of attributes at the two ends of an edge. For each directed edge , write and . Count both orientations of undirected edges to avoid arbitrary endpoint asymmetry. With endpoint means ,
This is Pearson correlation. Positive indicates assortative mixing, negative disassortative mixing, and zero no linear correlation of these attributes. It is undefined when an endpoint attribute has zero variance. Undirected degree assortativity uses . For directed graphs, specify the degree type at each endpoint; NetworkX defaults to source out-degree and target in-degree (x="out", y="in"). Sampling is by edge endpoints, not uniformly over nodes.
In BA growth, new nodes start with low degree and preferentially connect to high-degree nodes; finite samples may exhibit weak negative degree correlations. The sign in one simulation is not a theorem for every BA parameter choice and size. Political networks can exhibit different connection patterns within and between groups.
A community usually means a set of nodes with denser internal than external connections. A partition may be supplied by domain labels or inferred algorithmically. Louvain is an unsupervised community-detection method and does not require pre-existing correct labels.
Modularity compares observed within-community edges with a random baseline that incorporates node degrees. For an unweighted undirected graph with , a non-overlapping partition , and resolution parameter one,
Here counts internal edges of community , while sums its nodes' degrees in the original graph. The baseline is not an unspecified “purely random graph”: its expected edge counts depend on degree. A larger indicates more internal edges than this baseline predicts, but does not guarantee a unique true community structure. Putting every node in one group gives .
Giant Components, Small Worlds, and Reading Empirical Network Tables
The fraction of nodes in the largest connected component is . Strictly, a giant component occupies a nonzero fraction as the network grows, with size of order . Being the largest component of a finite graph does not by itself establish this asymptotic property.
Increasing the edge probability in can merge many small components into a large one.
The small-world property means typical shortest paths are short, often growing slowly with network size. A power-law degree distribution, short paths, and high clustering are three distinct properties. “Six degrees of separation” is an empirical description of social networks, not a theorem that every pair of people is exactly six steps apart.
Empirical networks can be compared using , the degree-tail exponent, transitivity, mean local clustering, and . Social networks often have short distances, high clustering, and positive assortativity; information and biological networks may have heavy-tailed degrees and negative assortativity. These tendencies have exceptions and must not be treated as universal laws.
A power law does not necessarily have infinite variance. An ideal unbounded power-law tail with has no finite second moment, while can have finite variance. A finite observed sample of finite values still has a computable sample variance.
BFS and Computational Complexity: State the Representation
An adjacency list uses space; an adjacency matrix uses . If the graph is sparse, , adjacency-list storage is approximately linear. A hub can nevertheless have a large degree, so enumerating every individual node's neighbours cannot always be treated as constant-time work.
Breadth-first search (BFS) finds shortest paths in an unweighted graph. Set the source distance to zero and enqueue it. Remove the next node from the front of the queue; for each unvisited neighbour , set and enqueue . Because the search visits distance layer before layer , first discovery gives the shortest distance.
| Task | Typical adjacency-list complexity | Reason and conditions |
|---|---|---|
| Enumerate neighbours of node | Each neighbour must be visited | |
| Retrieve an unweighted degree | Can be | If the container or a cache stores the neighbour count; scanning costs |
| Compute mean degree | or | Constant time if are known; summing retrieved node degrees costs ; scanning edges costs |
| Single-source BFS or a two-node shortest path | worst case | Nodes and edges are visited a constant number of times; early stopping need not improve the worst-case order |
| One node's eccentricity | Run BFS, then take the largest distance | |
| All-pairs distances and exact whole-graph | Run BFS from every node |
The last row becomes for sparse graphs. With an adjacency matrix, a BFS typically costs because it scans whole rows. Weighted distances generally require another algorithm; Dijkstra is commonly used for nonnegative distance weights.
Worked Example: A Triangle with One Leaf
Consider and .
1 | 1 ----- 2 |
There are four edges, degrees , mean degree two, and density . The six unordered pair distances sum to eight, so . Also , , the center is , and the periphery is .
| Node | Core number | ||||
|---|---|---|---|---|---|
| 1 | 0 | 1 | 2 | ||
| 2 | 0 | 1 | 2 | ||
| 3 | 1 | 1 | 2 | ||
| 4 | 0 | 0 | 1 |
Node 3 lies on the shortest paths for and , giving normalized betweenness . There is one triangle and connected triples, hence and .
For the partition , we have , so
Degree assortativity is : the mean degree sampled at edge endpoints is , the covariance is , and each endpoint variance is . High-degree endpoints therefore tend to connect to lower-degree endpoints in this example.
The negative modularity means that separating the leaf into its own community does not improve on the degree-based random baseline. The code in the next section checks these results.
← Network fundamentals · Series index · Working with NetworkX →

