Title: | Diffusion Distance for Complex Networks |
---|---|
Description: | Enables the evaluation of diffusion distances for complex single-layer networks. Given a network one can define different types of Laplacian (or transition) matrices corresponding to different continuous-time random walks dynamics on the network. This package enables the evaluation of Laplacians, stochastic matrices, and the corresponding diffusion distance matrices. The metric structure induced by the network-driven process is richer and more robust than the one given by shortest-paths and allows to study the geometry induced by different types of diffusion-like communication mechanisms taking place on complex networks. For more details see: De Domenico, M. (2017) <doi:10.1103/physrevlett.118.168301> and Bertagnolli, G. and De Domenico, M. (2021) <doi:10.1103/PhysRevE.103.042301>. |
Authors: | Giulia Bertagnolli [aut, cre] , Manlio De Domenico [aut] |
Maintainer: | Giulia Bertagnolli <[email protected]> |
License: | GPL (>=2) |
Version: | 1.1 |
Built: | 2024-11-09 04:38:44 UTC |
Source: | https://github.com/gbertagnolli/diffudist |
Matrix multiplication of the two matrices in input, without copy.
eigenMapMatMult(A, B)
eigenMapMatMult(A, B)
A |
numeric matrix of dimension |
B |
numeric matrix of dimension |
C matrix of dimension of the row-column product of A and B and C
Matrix multiplication of the two matrices in input.
eigenMatMult(A, B)
eigenMatMult(A, B)
A |
numeric matrix of dimension |
B |
numeric matrix of dimension |
C matrix of dimension of the row-column product of A and B and C
Returns the diffusion distance matrix when the spectrum (more precisely, the eigendecomposition) of the Laplacian is provided as input (useful to speed up batch calculations).
For instance, the random walk normalised Laplacian ,
which generates the classical continuous-time random walk over a network,
can be easily and obtained from the spectral decomposition of the symmetric
normalised Laplacian
.
More specifically,
and, since
is symmetric it can be decomposed into
, hence
where
and
.
get_ddm_from_eigendec(tau, Q, Q_inv, lambdas, as_dist = FALSE, verbose = FALSE)
get_ddm_from_eigendec(tau, Q, Q_inv, lambdas, as_dist = FALSE, verbose = FALSE)
tau |
diffusion time (scalar) |
Q |
eigenvector matrix |
Q_inv |
inverse of the eigenvector matrix |
lambdas |
eigenvalues (vector) |
verbose |
whether warnings have to be printed or not |
The diffusion distance matrix , a square numeric matrix
of the Euclidean distances between the rows of the stochastic matrix
, where
is the Laplacian generating a
continuous-time random walk (Markov chain) over the network.
The matrix exponential is here computed using the given eigendecomposition
of the Laplacian matrix
.
Bertagnolli, G., & De Domenico, M. (2021). Diffusion geometry of multiplex and interdependent systems. Physical Review E, 103(4), 042301. doi:10.1103/PhysRevE.103.042301 arXiv: 2006.13032
Returns a matrix where each entry encodes the diffusion probability between two nodes
get_diffusion_probability_matrix( g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE ) getDiffusionProbabilityMatrix(g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE) get_diffu_Pt( g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE )
get_diffusion_probability_matrix( g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE ) getDiffusionProbabilityMatrix(g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE) get_diffu_Pt( g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE )
g |
a single-layer network |
tau |
diffusion time |
type |
default "Normalized Laplacian". The type of Laplacian (i.e. of dynamics) to consider. Other types available are:
Note that you can type abbreviations, e.g. "L", "N", "Q", "M" for the
respective types (case is ignored). The argument match is done through
|
weights |
edge weights, representing the strength/intensity (not the cost!) of each link. if weights is NULL (the default) and g has an edge attribute called weight, then it will be used automatically. If this is NA then no weights are used (even if the graph has a weight attribute). |
verbose |
default |
The matrix , exponential of a Laplacian matrix.
getDiffusionProbabilityMatrix()
: Old deprecated function
De Domenico, M. (2017). Diffusion Geometry Unravels the Emergence of Functional Clusters in Collective Phenomena. Physical Review Letters. doi:10.1103/PhysRevLett.118.168301
Bertagnolli, G., & De Domenico, M. (2021). Diffusion geometry of multiplex and interdependent systems. Physical Review E, 103(4), 042301. doi:10.1103/PhysRevE.103.042301 arXiv: 2006.13032
get_laplacian, get_distance_matrix
Description here
get_diffusion_probability_matrix_from_T(Pi, tau) get_diffu_Pt_from_T(Pi, tau) get_diffu_Pt_from_Pi(Pi, tau) get_diffusion_probability_matrix_from_Pi(Pi, tau)
get_diffusion_probability_matrix_from_T(Pi, tau) get_diffu_Pt_from_T(Pi, tau) get_diffu_Pt_from_Pi(Pi, tau) get_diffusion_probability_matrix_from_Pi(Pi, tau)
Pi |
Transition matrix. We do not use |
tau |
diffusion time |
, exponential of the normalized Laplacian
matrix corresponding to the given transition rate matrix (or transition
probability matrix of a discrete-time Markov chain).
De Domenico, M. (2017). Diffusion Geometry Unravels the Emergence of Functional Clusters in Collective Phenomena. Physical Review Letters. doi:10.1103/PhysRevLett.118.168301
Bertagnolli, G., & De Domenico, M. (2020). Diffusion Geometry of Multiplex and Interdependent Systems. arxiv preprint arxiv:2006.13032
get_diffusion_probability_matrix
Returns a matrix where each entry encodes the diffusion distance between two nodes of a network.
The diffusion distance at time between nodes
is defined as
with
indicating the i-th row of the stochastic matrix
and
representing the probability (row) vector of a random walk dynamics
corresponding to the initial condition
, i.e. the random
walker is in node
at time
with probability 1.
get_distance_matrix( g, tau, type = "Normalized Laplacian", weights = NULL, as_dist = FALSE, verbose = TRUE ) getDistanceMatrix(g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE) get_DDM( g, tau, type = "Normalized Laplacian", weights = NULL, as_dist = FALSE, verbose = TRUE )
get_distance_matrix( g, tau, type = "Normalized Laplacian", weights = NULL, as_dist = FALSE, verbose = TRUE ) getDistanceMatrix(g, tau, type = "Normalized Laplacian", weights = NULL, verbose = TRUE) get_DDM( g, tau, type = "Normalized Laplacian", weights = NULL, as_dist = FALSE, verbose = TRUE )
g |
a (single-layer) network |
tau |
diffusion time |
type |
default "Normalized Laplacian". The type of Laplacian (i.e. of dynamics) to consider. Other types available are:
Note that you can type abbreviations, e.g. "L", "N", "Q", "M" for the
respective types (case is ignored). The argument match is done through
|
weights |
edge weights, representing the strength/intensity (not the cost!) of each link. If weights is NULL (the default) and g has an edge attribute called weight, then it will be used automatically. If this is NA then no weights are used (even if the graph has a weight attribute). |
as_dist |
If the function should return a matrix or an object of class "dist" as returned from [stats::as.dist]. Default is FALSE if the number of nodes is smaller than 1000. |
verbose |
default TRUE |
The diffusion distance matrix , a square numeric matrix
of the
-norm distances between posterior probability vectors, i.e.
Euclidean distances between the rows of the stochastic matrix
, where
is the generator of the
continuous-time random walk (Markov chain) of given
type
over
network g
.
getDistanceMatrix()
: Old deprecated function
De Domenico, M. (2017). Diffusion Geometry Unravels the Emergence of Functional Clusters in Collective Phenomena. Physical Review Letters. doi:10.1103/PhysRevLett.118.168301
Bertagnolli, G., & De Domenico, M. (2021). Diffusion geometry of multiplex and interdependent systems. Physical Review E, 103(4), 042301. doi:10.1103/PhysRevE.103.042301 arXiv: 2006.13032
get_diffusion_probability_matrix
g <- igraph::sample_pa(10, directed = FALSE) dm_crw <- get_distance_matrix(g, tau = 1) dm_merw <- get_distance_matrix(g, tau = 1, type = "MERW")
g <- igraph::sample_pa(10, directed = FALSE) dm_crw <- get_distance_matrix(g, tau = 1) dm_merw <- get_distance_matrix(g, tau = 1, type = "MERW")
Returns a matrix where each entry encodes the diffusion distance between two nodes of a network, given a transition matrix on the network and a diffusion time.
The diffusion distance at time between nodes
is defined as
with
indicating the i-th row of the stochastic matrix
and
representing the probability (row) vector of a random walk dynamics
corresponding to the initial condition
, i.e. the random
walker is in node
at time
with probability 1.
The Laplacian is the normalised laplacian corresponding to the
given transition matrix, i.e.
.
get_distance_matrix_from_T(Pi, tau, as_dist = FALSE, verbose = TRUE) get_DDM_from_T(Pi, tau, as_dist = FALSE, verbose = TRUE) get_distance_matrix_from_Pi(Pi, tau, as_dist = FALSE, verbose = TRUE) get_DDM_from_Pi(Pi, tau, as_dist = FALSE, verbose = TRUE)
get_distance_matrix_from_T(Pi, tau, as_dist = FALSE, verbose = TRUE) get_DDM_from_T(Pi, tau, as_dist = FALSE, verbose = TRUE) get_distance_matrix_from_Pi(Pi, tau, as_dist = FALSE, verbose = TRUE) get_DDM_from_Pi(Pi, tau, as_dist = FALSE, verbose = TRUE)
Pi |
a transition matrix (it should be a stochastic matrix) |
tau |
diffusion time |
verbose |
default TRUE |
The diffusion distance matrix , a square numeric matrix
of the
-norm distances between posterior probability vectors, i.e.
Euclidean distances between the rows of the stochastic matrix
, where
is the generator of the
continuous-time random walk (Markov chain) corresponding to the
discrete-time transition matrix
Pi
.
De Domenico, M. (2017). Diffusion Geometry Unravels the Emergence of Functional Clusters in Collective Phenomena. Physical Review Letters. doi:10.1103/PhysRevLett.118.168301
Bertagnolli, G., & De Domenico, M. (2021). Diffusion geometry of multiplex and interdependent systems. Physical Review E, 103(4), 042301. doi:10.1103/PhysRevE.103.042301 arXiv: 2006.13032
get_distance_matrix get_diffusion_probability_matrix,
get_diffusion_probability_matrix_from_T
Returns a specific Laplacian matrix corresponding to the chosen dynamics type and network. The available types are:
for the classical combinatorial Laplacian matrix; it governs the diffusion dynamics on the network
for the Laplacian matrix normalized by degree matrix, the so-called classical random walk normalized Laplacian; it governs stochastic walks on the network
for the Laplacian matrix normalized to be symmetric; it governs quantum walks on the network
the maximal-entropy random walk (RW) normalized Laplacian; it governs stochastic walks on the network, in which the random walker moves according to a maximal-entropy RW [1].
The maximum entropy random walk (MERW) chooses the stochastic matrix which
maximizes , so that the walker can explore every walk of the
same length with equal probability.
Let
be the leading eigenvalue and
corresponding right eigenvector of the adjacency matrix
. Then the
transition matrix corresponding to the discrete-time random walk is
The MERW (normalized) Laplacian is then given by
.
Note that we use the notation
and
Pi
to avoid confusion
with the abbreviation T
for the logical TRUE
.
get_laplacian(g, type = "Laplacian", weights = NULL, verbose = TRUE) getLaplacianMatrix(g, type = "Laplacian", weights = NULL, verbose = TRUE)
get_laplacian(g, type = "Laplacian", weights = NULL, verbose = TRUE) getLaplacianMatrix(g, type = "Laplacian", weights = NULL, verbose = TRUE)
g |
a network |
type |
the type of Laplacian matrix. default |
weights |
edge weights, representing the strength/intensity (not the cost!) of each link. if weights is NULL (the default) and g has an edge attribute called weight, then it will be used automatically. If this is NA then no weights are used (even if the graph has a weight attribute). |
verbose |
default |
the ('type') Laplacian matrix of network 'g'
[1] Burda, Z., et al. (2009). Phys Rev. Lett. 102 160602(April), 1–4. doi:10.1103/PhysRevLett.102.160602
Given a sequence of distance matrices, expected to correspond to sequential increasing values of time, calculate the average distance between any pairs of nodes shortest-path (or geodesic) distance
get_mean_distance_matrix(DM_list) getMeanDistanceMatrix(DM_list)
get_mean_distance_matrix(DM_list) getMeanDistanceMatrix(DM_list)
DM_list |
list of distance matrices |
mean-distance matrix
getMeanDistanceMatrix()
: Old deprecated function
De Domenico, M. (2017). Diffusion Geometry Unravels the Emergence of Functional Clusters in Collective Phenomena. Physical Review Letters. doi:10.1103/PhysRevLett.118.168301
Bertagnolli, G., & De Domenico, M. (2020). Diffusion Geometry of Multiplex and Interdependent Systems. arxiv preprint arxiv:2006.13032
get_diffusion_probability_matrix
, get_distance_matrix
Returns the eigenvalue spectrum together with eigenvectors of a Laplacian
corresponding to a network. This involves computing the eigendecomposition of
a (symmetric) matrix, so it is computationally intense and may take some time.
The decomposition of the normalized Laplacian takes
is computed through the decomposition of its symmetric version
. See the package vignette for details.
get_spectral_decomp(g, type = "Normalized Laplacian", verbose = FALSE)
get_spectral_decomp(g, type = "Normalized Laplacian", verbose = FALSE)
g |
the network in the [igraph] format |
type |
the Laplacian type, default "Normalized Laplacian". At the moment this is the only available option. For other types of Laplacians one should get autonomously the eigendecomposition, e.g. using eigen. See the package vignette for an example. |
verbose |
whether warnings have to be printed or not |
lambdas the eigenvalues of the Laplacian
'u_L' the matrix of left eigenvectors (rows)
'u_R' the matrix of right eigenvectors (columns)
Bertagnolli, G., & De Domenico, M. (2021). Diffusion geometry of multiplex and interdependent systems. Physical Review E, 103(4), 042301. doi:10.1103/PhysRevE.103.042301 arXiv: 2006.13032
get_laplacian
get_ddm_from_eigendec
Plot a heatmap of the distance matrix using geom_tile.
## S3 method for class 'diffudist' plot( DM, col_palette = viridis(n = 11), log_scale = FALSE, cex = 1, show_dendro = TRUE, title = "" )
## S3 method for class 'diffudist' plot( DM, col_palette = viridis(n = 11), log_scale = FALSE, cex = 1, show_dendro = TRUE, title = "" )
DM |
a distance matrix |
col_palette |
a colour palette, previously it was set to the 'spectral' palette of brewer.pal but now it is, by default, to the color-blind firendly viridis. |
log_scale |
logical. Default FALSE |
cex |
numerical value by which text should be magnified (default font size in theme is 11) |
show_dendro |
If the dendrogram resulting from hclust should be shown. Default TRUE |
title |
Title of the plot passed to labs. No title by default. |
plot ggplot
'r lifecycle::badge("deprecated")'
plotHeatmap( DM, colPalette = NULL, log.scale = FALSE, cex = 1, showDendrogram = TRUE, title = "" )
plotHeatmap( DM, colPalette = NULL, log.scale = FALSE, cex = 1, showDendrogram = TRUE, title = "" )
DM |
a distance matrix |
colPalette |
'r lifecycle::badge("deprecated")' in the new function
plot_distance_matrix
it is called |
log.scale |
'r lifecycle::badge("deprecated")' in the new function
plot_distance_matrix
it is called |
cex |
numerical value by which text should be magnified (default font size in [ggplot2:theme] is 11) |
showDendrogram |
'r lifecycle::badge("deprecated")' in the new function plot_distance_matrix
it is called |
title |
Title of the plot passed to labs. No title by default |
a ggplot