Title: | Temporal Network Centrality (TNC) Measures |
---|---|
Description: | Node centrality measures for temporal networks. Available measures are temporal degree centrality, temporal closeness centrality and temporal betweenness centrality defined by Kim and Anderson (2012) <doi:10.1103/PhysRevE.85.026107>. Applying the REN algorithm by Hanke and Foraita (2017) <doi:10.1186/s12859-017-1677-x> when calculating the centrality measures keeps the computational running time linear in the number of graph snapshots. Further, all methods can run in parallel up to the number of nodes in the network. |
Authors: | Moritz Hanke [aut, cre] |
Maintainer: | Moritz Hanke <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-01 06:51:39 UTC |
Source: | CRAN |
tbc
returns the temporal betweenness centrality for each node in a
dynamic network (sequence of graph snapshots).
tbc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), vertexindices = NULL, directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
tbc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), vertexindices = NULL, directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
x |
A list of adjacency matrices or a list of adjacency lists. |
type |
Data format of |
startsnapshot |
Numeric. Entry of |
endsnapshot |
Numeric. Entry of |
vertexindices |
Numeric. A vector of nodes. Only shortest temporal paths
ending at nodes in |
directed |
Logical. Set |
normalize |
Logical. Set |
centrality_evolution |
Logical. Set |
tbc
calculates the temporal betweenness centrality (Kim and
Anderson, 2012). To keep the computational effort linear in the number of
snapshots the Reversed Evolution Network algorithm (REN; Hanke and Foraita,
2017) is used to find all shortest temporal paths.
The (normalized) temporal betweenness centrality (TBC
) values
of all nodes. If centrality_evolution
is TRUE
, an additional
matrix will be returned (CentEvo
), containing the temporal matrix is returned (
CentEvo
), containing the temporal
centrality value at each snapshot between startsnapshot
and
endsnapshot
.
Using adjacency matrices as input exponentially increases the required memory. Use adjacency lists to save memory.
Kim, Hyoungshick and Anderson, Ross (2012). Temporal node centrality in complex networks. Physical Review E, 85 (2).
Hanke, Moritz and Foraita, Ronja (2017). Clone temporal centrality measures for incomplete sequences of graph snapshots. BMC Bioinformatics, 18 (1).
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculate tbc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tbc(As, "M", centrality_evolution=TRUE) ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tbc(Ls, "L", centrality_evolution=TRUE) ### Run tbc in parallel ### library(parallel) # Calculate the number of cores cores_avail <- detectCores()-1 # Initiate cluster cl <- makeCluster(2) clusterExport(cl, c("As", "tbc")) TBC <- parLapply(cl, 1:6, function(x){ tbc(As, "M", vertexindices = x) } ) stopCluster(cl) Reduce("+", TBC)
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculate tbc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tbc(As, "M", centrality_evolution=TRUE) ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tbc(Ls, "L", centrality_evolution=TRUE) ### Run tbc in parallel ### library(parallel) # Calculate the number of cores cores_avail <- detectCores()-1 # Initiate cluster cl <- makeCluster(2) clusterExport(cl, c("As", "tbc")) TBC <- parLapply(cl, 1:6, function(x){ tbc(As, "M", vertexindices = x) } ) stopCluster(cl) Reduce("+", TBC)
tcc
returns the temporal closeness centrality for each node in a
dynamic network (sequence of graph snapshots).
tcc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), vertexindices = NULL, directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
tcc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), vertexindices = NULL, directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
x |
A list of adjacency matrices or a list of adjacency lists. |
type |
Data format of |
startsnapshot |
Numeric. Entry of |
endsnapshot |
Numeric. Entry of |
vertexindices |
Numeric. A vector of nodes. Only shortest temporal paths
ending at nodes in |
directed |
Logical. Set |
normalize |
Logical. Set |
centrality_evolution |
Logical. Set |
tcc
calculates the temporal closeness centrality (Kim and
Anderson, 2012). To keep the computational effort linear in the number of
snapshots the Reversed Evolution Network algorithm (REN; Hanke and Foraita,
2017) is used to find all shortest temporal paths.
The (normalized) temporal betweenness centrality values of all nodes
(TCC
). If centrality_evolution
is TRUE
, an additional
matrix is returned (
CentEvo
), containing the
temporal centrality value at each snapshot between startsnapshot
and
endsnapshot
.
Using adjacency matrices as input exponentially increases the required memory. Use adjacency lists to save memory.
Kim, Hyoungshick and Anderson, Ross (2012). Temporal node centrality in complex networks. Physical Review E, 85 (2).
Hanke, Moritz and Foraita, Ronja (2017). Clone temporal centrality measures for incomplete sequences of graph snapshots. BMC Bioinformatics, 18 (1).
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculate tcc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tcc(As, "M", centrality_evolution=TRUE) ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tcc(Ls, "L", centrality_evolution=TRUE) ### Run tbc in parallel ### library(parallel) # Calculate the number of cores cores_avail <- detectCores()-1 # Initiate cluster cl <- makeCluster(2) clusterExport(cl, c("As", "tcc")) TCC <- parLapply(cl, 1:6, function(x){ tcc(As, "M", vertexindices = x) } ) stopCluster(cl) Reduce("+", TCC)
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculate tcc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tcc(As, "M", centrality_evolution=TRUE) ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tcc(Ls, "L", centrality_evolution=TRUE) ### Run tbc in parallel ### library(parallel) # Calculate the number of cores cores_avail <- detectCores()-1 # Initiate cluster cl <- makeCluster(2) clusterExport(cl, c("As", "tcc")) TCC <- parLapply(cl, 1:6, function(x){ tcc(As, "M", vertexindices = x) } ) stopCluster(cl) Reduce("+", TCC)
tdc
returns the temporal degree centrality for each node in a dynamic
network (sequence of graph snapshots).
tdc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
tdc(x, type = NULL, startsnapshot = 1, endsnapshot = length(x), directed = FALSE, normalize = TRUE, centrality_evolution = FALSE)
x |
A list of adjacency matrices or a list of adjacency lists. |
type |
Data format of |
startsnapshot |
Numeric. Entry of |
endsnapshot |
Numeric. Entry of |
directed |
Logical. Set |
normalize |
Logical. Set |
centrality_evolution |
Logical. Set |
tdc
calculates the temporal degree centrality (see Kim and
Anderson, 2012), which is defined as the average degree centrality over all
snapshots.
The (normalized) temporal degree centrality values of all nodes
(TDC
). If centrality_evolution
is TRUE
an additional
matrix is returned (CentEvo
), containing the temporal centrality
value at each snapshot between startsnapshot
and endsnapshot
.
Using adjacency matrices as input exponentially increases the required memory. Use adjacency lists to save memory.
Kim, Hyoungshick and Anderson, Ross, 2012. Temporal node centrality in complex networks. Physical Review E, 85 (2).
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculating tdc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tdc(As, "M", centrality_evolution=TRUE) #' ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tdc(Ls, "L", centrality_evolution=TRUE)
# Create a list of adjacency matrices, plot the corresponding graphs # (using the igraph package) and calculating tdc A1 <- matrix(c(0,1,0,0,0,0, 1,0,1,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A2 <- matrix(c(0,0,0,0,0,0, 0,0,1,0,0,0, 0,1,0,1,1,0, 0,0,1,0,0,0, 0,0,1,0,0,0, 0,0,0,0,0,0), ncol=6) A3 <- matrix(c(0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) A4 <- matrix(c(0,1,0,0,0,0, 1,0,0,1,0,0, 0,0,0,0,0,0, 0,1,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0), ncol=6) library(igraph) par(mfrow=c(2,2)) Layout <- layout_in_circle(graph_from_adjacency_matrix(A1, mode = "undirected")) plot(graph_from_adjacency_matrix(A1, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A2, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A3, "undirected"), layout=Layout) plot(graph_from_adjacency_matrix(A4, "undirected"), layout=Layout) As <- list(A1,A2,A3,A4) tdc(As, "M", centrality_evolution=TRUE) #' ### Create list of adjacency lists Ls <- lapply(seq_along(As), function(i){ sapply(1:6, function(j){which(As[[i]][j,]==1)}) }) tdc(Ls, "L", centrality_evolution=TRUE)
The TNC package provides three functions: tbc, tcc and tdc for calculating temporal betweenness, temporal closeness and temporal degree centrality.