centrality
Algorithms to calculate centralities in (temporal) graphs.
The functions and submodules in this module allow to compute time-respecting or causal paths in temporal graphs and to calculate (temporal) and higher-order graph metrics like centralities.
Example
# Import pathpyG and configure your torch device if you want to use GPU acceleration.
import pathpyG as pp
pp.config['torch']['device'] = 'cuda'
# Generate toy example for temporal graph
g = pp.TemporalGraph.from_edge_list([
('b', 'c', 2),
('a', 'b', 1),
('c', 'd', 3),
('d', 'a', 4),
('b', 'd', 2),
('d', 'a', 6),
('a', 'b', 7)
])
bw_t = pp.algorithms.temporal_betweenness_centrality(g, delta=1)
cl_t = pp.algorithms.temporal_closeness_centrality(g, delta=1)
static_graph = g.to_static_graph()
bw_s = pp.algorithms.betweenness_centrality(static_graph)
bw_s = pp.algorithms.closeness_centrality(static_graph)
__getattr__
¶
Map to corresponding functions in centrality module of networkx.
Any call to a function that is not implemented in the module centrality
and whose first argument is of type Graph will be delegated to the
corresponding function in the networkx module centrality
. Please
refer to the networkx documentation
for a reference of available functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
the name of the function that shall be called |
required |
Source code in src/pathpyG/algorithms/centrality.py
betweenness_centrality
¶
Calculate the betweenness centrality of nodes based on the fast algorithm proposed by Brandes:
U. Brandes: A faster algorithm for betweenness centrality, The Journal of Mathematical Sociology, 2001
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
pathpyG.core.graph.Graph
|
|
required |
sources
|
optional list of source nodes for BFS-based shortest path calculation |
None
|
Example
Source code in src/pathpyG/algorithms/centrality.py
map_to_nodes
¶
Map node-level centralities in dictionary to node IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
pathpyG.core.graph.Graph
|
Graph object |
required |
c
|
typing.Dict
|
dictionary mapping node indices to metrics |
required |
Example
Source code in src/pathpyG/algorithms/centrality.py
path_node_traversals
¶
Calculate the number of times any path traverses each of the nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
pathpyG.core.path_data.PathData
|
|
required |
Source code in src/pathpyG/algorithms/centrality.py
path_visitation_probabilities
¶
Calculate the probabilities that a randomly chosen path passes through each of the nodes. If 5 out of 100 paths (of any length) traverse node v, node v will be assigned a visitation probability of 0.05. This measure can be interpreted as ground truth for the notion of importance captured by PageRank applied to a graphical abstraction of the paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
pathpyG.core.path_data.PathData
|
PathData object that contains path data |
required |
Source code in src/pathpyG/algorithms/centrality.py
temporal_betweenness_centrality
¶
Calculate the temporal betweenness of nodes in a temporal graph.
The temporal betweenness centrality definition is based on shortest time-respecting paths with a given maximum time difference delta, where the length of a path is given as the number of traversed edges (i.e. not the temporal duration of a path or the earliest arrival at a node).
The algorithm is an adaptation of Brandes' fast algorithm for betweenness centrality based on the following work:
S. Buss, H. Molter, R. Niedermeier, M. Rymar: Algorithmic Aspects of Temporal Betweenness, arXiv:2006.08668v2
Different from the algorithm proposed above, the temporal betweenness centrality implemented in pathpyG is based on a directed acyclic event graph representation of a temporal graph and it considers a maximum waiting time of delta. The complexity is in O(nm) where n is the number of nodes in the temporal graph and m is the number of time-stamped edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
pathpyG.core.temporal_graph.TemporalGraph
|
|
required |
delta
|
int
|
maximum waiting time for time-respecting paths |
1
|
Example
Source code in src/pathpyG/algorithms/centrality.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
temporal_closeness_centrality
¶
Calculates the temporal closeness centrality of nodes based on observed shortest time-respecting paths between all nodes.
Following the definition by M. A. Beauchamp 1965 (https://doi.org/10.1002/bs.3830100205).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
g
|
pathpyG.core.temporal_graph.TemporalGraph
|
|
required |
delta
|
int
|
maximum waiting time for time-respecting paths |
required |