where \(i\) is a node,
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
and \(\mathbf{A}\) is the adjacency matrix, optionally weighted by an edge-level
weight attribute. For multigraphs, adjacencies are weighted by the number of
parallel edges, unless weight=False.
Parameters:
TG (object) – A TemporalGraph or static NetworkX graph
object.
nbunch (Any | None) – One or more nodes to return. Optional.
where \(i\) is a node,
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
and \(\mathbf{A}\) is the adjacency matrix, optionally weighted by an edge-level
weight attribute. For multigraphs, adjacencies are weighted by the number of
parallel edges, unless weight=False.
Parameters:
TG (object) – A TemporalGraph or static NetworkX graph
object.
nbunch (Any | None) – One or more nodes to return. Optional.
where \(i\) is a node,
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
and \(\mathbf{A}\) is the adjacency matrix, optionally weighted by an edge-level
weight attribute. For multigraphs, adjacencies are weighted by the number of
parallel edges, unless weight=False.
Parameters:
TG (object) – A TemporalGraph or static NetworkX graph
object.
nbunch (Any | None) – One or more nodes to return. Optional.
where
\(c_{\text{deg}}(i)\) is the degree centrality of node \(i\),,
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(\mathbf{A}\) is the adjacency matrix,
and \(|\mathcal{V}|\) is the order of the graph \(\mathcal{G}\).
Note that this function does not consider node copies or edge weights in the adjacency matrix.
Parameters:
nbunch (Any | None) – One or more nodes to return. Optional.
where
\(c_{\text{in}}(i)\) is the degree centrality of node \(i\),
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(\mathbf{A}\) is the adjacency matrix,
and \(|\mathcal{V}|\) is the order of the graph \(\mathcal{G}\).
Note that this function does not consider node copies or edge weights in the adjacency matrix.
Parameters:
nbunch (Any | None) – One or more nodes to return. Optional.
where
\(c_{\text{in}}(i)\) is the degree centrality of node \(i\),
\(G\) is a snapshot in the temporal graph \(\mathcal{G}\),
\(j\) is a node in the neighborhood \(\mathcal{N}(i)\),
\(\mathbf{A}\) is the adjacency matrix,
and \(|\mathcal{V}|\) is the order of the graph \(\mathcal{G}\).
Note that this function does not consider node copies or edge weights in the adjacency matrix.
Parameters:
nbunch (Any | None) – One or more nodes to return. Optional.
Bridging centrality measures the importance of a node in connecting different parts of a
network, and is defined [2] as the product of betweenness centrality and bridging coefficient:
being \(\text{deg}(i)^{-1}\) the inverse degree of node \(i\), and \(N(i)\) its
set of neighbors \(j \in N(i)\).
Returns zero for isolated nodes, i.e., with no neighbors.
If betweenness is not provided, the bridging coefficient of nodes is returned instead,
that is, consider \(c_{\text{bet}}(i) = 1\) for all nodes.
Parameters:
TG (object) – A TemporalGraph
or static NetworkX graph object.
betweenness (dict | List[dict] | None) – Dictionary of node betweenness centrality values. Returns
bridging coefficient if not provided. Optional.
Brokering centrality [3] is a measure of the node’s ability to connect different parts of the
network and is useful for identifying nodes that play a key role in the network’s structure.
It is defined as:
where
\(\text{deg}(i)\) is the degree centrality of node \(i\),
and \(\text{clu}(i)\) is its clustering coefficient.
Clustering coefficient works as a measure of interconnectivity in a node’s neighborhood and may
be defined [4] as the the number of edges between a node’s neighbors divided by the
number of possible edges between them. If clustering_coef is not provided, it is computed
as:
where
\(\text{clu}(i)\) is the clustering coefficient of node \(i\),
\(n\) is the number of edges between its neighbors,
and \(|N_i|\) is its number of neighbors.
Lower values indicate nodes part of a loosely connected groups, while higher values indicate
nodes at the center of fully connected clusters.
Attention
In directed graphs, connections are not necessarily reciprocal, affecting the coefficients.
Parameters:
TG (object) – A TemporalGraph
or static NetworkX graph object.
Centralization [5] is defined as the sum of differences between the most central node’s
centrality and each of the other nodes’ centralities, divided by the maximum theoretical sum of
values in a graph with the same properties, such as order, size, and edge directionality.
It is calculated as:
where
\(\text{centrality}_{\text{max}}\) is the maximum node centrality in \(G\),
\(\text{centrality}(i)\) is the centrality of node \(i \in V\),
and \({\text{theoretical}}_{\text{max}}\) and \({\text{theoretical}}(i)\)
refer to node centralities of a theoretical likewise graph for which the sum of differences
equals the highest possible scalar value.
Example
Calculating the degree centralization of a simple graph (no parallel edges, self-loops
or isolates):
>>> importnetworkxasnx>>> importnetworkx_temporalastx>>>>>> G=nx.Graph()>>>>>> G.add_edges_from([... (1,0),... (2,0),... (3,0),... ])>>>>>> centrality=G.degree()# Node degree values.>>> maximum=G.order()-1# Highest possible degree.>>> minimum=1# Minimum possible degree.>>>>>> # Highest theoretical sum of values in a simple star-like graph.>>> scalar=sum(maximum-minimumforninrange(G.order()-1))>>>>>> tx.centralization(centrality=centrality,scalar=scalar)1.0
Alternatively, passing a list of theoretical centrality values:
centrality (list | dict) – List or dictionary of node centralities.
scalar (int | float | list | dict) – Maximum theoretical sum of values. Accepts a value, list, or dictionary
with node centrality degrees values. Optional.
The degree centralization [1] of a graph is the sum of differences between the centrality of
the most central node and each of the other nodes’ centralities, divided by the maximum
theoretical sum of values in a graph with the same order, size, and edge directionality,
i.e., a star graph.
The degree centralization \(C_\text{deg}\) of a simple graph without self-loops
\(G\) corresponds to:
where \(|V|\) is the number of nodes,
\(\text{deg}_{\text{max}}\) is the highest node degree in \(G\),
\(\text{deg}(i)\) is the degree of node \(i \in V\),
and \(\text{deg}^\star_{\text{max}} = |V|-1\)
the maximum theoretical node degree.
where \(|V|\) is the number of nodes,
\(\text{in}_{\text{max}}\) is the highest node in-degree in \(G\),
\(\text{in}(i)\) is the in-degree of node \(i \in V\),
and \(\text{in}^\star_{\text{max}} = |V|-1\)
the maximum theoretical node in-degree.
Parameters:
TG (object) – A TemporalGraph or static NetworkX graph
object.
self_loops (bool) – If True, self-loops are considered in the calculation.
Defaults to False.
isolates (bool) – If True, node isolates are considered in the calculation.
Defaults to False.
where \(|V|\) is the number of nodes,
\(\text{out}_{\text{max}}\) is the highest node out-degree in \(G\),
\(\text{out}(i)\) is the out-degree of node \(i \in V\),
and \(\text{out}^\star_{\text{max}} = |V|-1\)
the maximum theoretical node out-degree.
Parameters:
TG (object) – A TemporalGraph or static NetworkX graph
object.
self_loops (bool) – If True, self-loops are considered in the calculation.
Defaults to False.
isolates (bool) – If True, node isolates are considered in the calculation.
Defaults to False.
Conductance [6] measures the fraction of edges that falls within a community compared to
those leaving it. Lower values indicate well-defined internal community structures,
weakly connected to the rest of the graph. For a set of communities, it is defined as their
average:
where \(G\) is a graph,
\(C\) is a set of disjoint node partitions,
\(V\) is the set of all nodes,
and \(\phi(S)\) is the conductance of each node subset \(S \in C\).
The latter is defined as:
where \(\text{cut}(S, \bar{S})\) is the total weight of edges connecting \(S\)
to its complement \(\bar{S}\),
and \(\text{vol}(S)\) is the volume of \(S\), i.e., the total weight of all edges
starting at the node subset.
Parameters:
G (object) – TemporalGraph
or static NetworkX graph object.
communities (str | list | dict) – List of community assignments for each node, or
a list of lists in case of temporal graphs, one per snapshot.
weight (str | None) – The edge attribute key used to compute edge weights. If None (default),
all edge weights are considered as 1.
Modularity [7] measures the fraction of edges in a graph that fall within communities,
compared to their expected number in a random graph with the same degree sequence.
Higher values may indicate more internal connections than expected by chance.
It is commonly defined as:
where
\(m\) is the number of edges in the graph,
\((i,j) \in V^2\) are node pairs,
\(\mathbf{A}\) is the adjacency matrix,
\(d\) are node in/out-degrees,
\(c\) are their communities,
and \(\gamma = 1\) (default) is the resolution parameter [4],
where smaller values favor larger communities, including negative values.
This can be reduced to a summation over communities, which is more efficient to compute:
where \(L_c\) is the number of within-community edges
and \(d_c\) is the sum of degrees of nodes in community \(c\).
If spectral=True, modularity is computed using
spectral_modularity() instead.
Multislice modularity [8] is a generalization of the metric for multiplex graphs, where each
layer corresponds to a temporal graph snapshot. Temporal node copies are connected across time
by interlayer edges (‘’couplings’’), as in an unrolled graph, so the expected fraction of intra-layer
edges is adjusted to account for these added connections. It may be defined as:
where
\(\mu\) is the total number of intra- and inter-layer edges in the temporal graph,
\(G_t \in \mathcal{G}\) are graph snapshots (slices/layers),
\((i,j) \in V^2\) are node pairs,
\(\mathbf{A}\) is the adjacency matrix,
\(d\) are node degrees,
\(c\) are their communities,
and \(t\) is the time or snapshot index.
Additional term \(\gamma = 1\) (default) is the community resolution
and \(\omega = 1\) (default) is the interlayer edge weight.
Note that if spectral=True, modularity is computed using
spectral_modularity() instead.
where
\(m\) is the total number of edges,
\(\mathbf{B}\) is the modularity matrix,
\(\mathbf{A}\) is the (optionally sparse) adjacency matrix,
\(\mathbf{C}\) is the \(n \times k\) community assignment matrix
with \(n\) as the number of nodes and \(k\) the number of communities,
\(\mathbf{d_{in}}\) and \(\mathbf{d_{out}}\) are the node in- and out-degree vectors,
and \(\gamma = 1\) (default) is the resolution parameter. Note that this formulation
naturally extends to mixed memberships, where nodes may belong to
different communities with different weights.
Parameters:
A (object) – Adjacency matrix (dense numpy array or sparse scipy matrix).
If A is a temporal or static graph, convert it automatically.
communities (array | csr_array) – Community assignment matrix with shape (n_nodes,k_communities),
a or vector of length n_nodes.
resolution (float | None) – The resolution parameter. Default is 1.
directed (bool | None) – Whether the graph is directed. Default is True.
weight (str | bool | None) – Whether to consider edge weights. If a string is provided,
it is used as the edge attribute key. Default is True.