directed_laplacian#
- graph_tool.spectral.directed_laplacian(g, weight=None, walk_type=None, alpha=0.95, combinatorial=False, operator=False)[git][source]#
Return the directed Laplacian matrix of Chung.
- Parameters:
- g
Graph Graph to be used (if it is undirected, every edge is traversed in both directions).
- weight
EdgePropertyMap(optional, default:None) Edge weights.
- walk_type
str(optional, default:None) Random walk:
"random","lazy", or"pagerank". If not given,"random"is used if the graph is strongly connected and aperiodic,"lazy"if it is strongly connected but periodic, and"pagerank"otherwise.- alpha
float(optional, default:0.95) Damping factor of the
"pagerank"walk, i.e. the probability of following an edge instead of teleporting.- combinatorial
bool(optional, default:False) If
True, the combinatorial version is returned.- operator
bool(optional, default:False) If
True, ascipy.sparse.linalg.LinearOperatorsubclass is returned, instead of a matrix.
- g
- Returns:
- L
csr_matrix,numpy.ndarray, orDirectedLaplacianOperator The symmetric directed Laplacian, which is a sparse matrix for the
"random"and"lazy"walks, and a dense array for"pagerank", unlessoperator == True. The rows and columns are in the order of the vertices.
- L
See also
laplacianLaplacian matrix
magnetic_laplacianMagnetic Laplacian matrix
transitionTransition matrix
Notes
The directed Laplacian of Chung [chung-laplacians-2005] of a random walk with transition matrix \(P\) (where \(P_{ij}\) is the probability of moving from \(i\) to \(j\)) is
\[L = I - \frac{\Phi^{1/2}P\Phi^{-1/2} + \Phi^{-1/2}P^T\Phi^{1/2}}{2},\]and the combinatorial directed Laplacian is
\[L = \Phi - \frac{\Phi P + P^T\Phi}{2},\]where \(\Phi\) is the diagonal matrix of the stationary distribution of the walk, i.e. \(\Phi_{ii} = \phi_i\) with \(\phi P = \phi\) and \(\sum_i\phi_i = 1\). The walks are the simple random walk, with \(P_{ij} = w_{ij}/\sum_k w_{ik}\) (which requires a strongly connected graph, and aperiodic for a unique limit), its lazy version \((I + P)/2\), and the walk with teleportation of PageRank, \(\alpha P' + (1-\alpha)/N\), where \(P'\) is \(P\) with the rows of the vertices without out-edges replaced by the uniform distribution, which defines a dense matrix, and whose stationary distribution is obtained with
pagerank(). Here \(w_{ij}\) is the sum of the weights of the edges \(i\to j\) (the edges between \(i\) and \(j\), for undirected graphs), with unit weights ifweightis not given. Both versions of \(L\) are symmetric, and their rows are indexed by the vertices in the order of their indices.The matrix is built in time \(O(V + E)\) (or \(O(V^2)\) if dense), after the stationary distribution is obtained. With
operator == True, the products with \(L\) are computed from the products with \(P\) and \(P^T\), in time \(O(V + E)\) per vector also for the walk with teleportation, whose matrix is then not built.LinearOperatorvs. sparse matricesFor many linear algebra computations it is more efficient to pass
operator=Trueto this function. In this case, it will return ascipy.sparse.linalg.LinearOperatorsubclass, which implements matrix-vector and matrix-matrix multiplication, and is sufficient for the sparse linear algebra operations available in the scipy modulescipy.sparse.linalg. This avoids copying the whole graph as a sparse matrix, and performs the multiplication operations in parallel (if enabled during compilation) — see note below.Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using OpenMP. See the parallel algorithms section for information about how to control several aspects of parallelization.
(The above is only applicable if
operator == True, and when the object returned is used to perform matrix-vector or matrix-matrix multiplications.)References
[chung-laplacians-2005]Fan Chung, “Laplacians and the Cheeger inequality for directed graphs”, Annals of Combinatorics 9, 1-19 (2005), DOI: 10.1007/s00026-005-0237-z [sci-hub, @tor]
Examples
The neural network of the C. elegans worm is not strongly connected, so that the walk with teleportation is used by default, and the matrix is dense:
>>> g = gt.collection.data["celegansneural"] >>> L = gt.directed_laplacian(g) >>> print(type(L).__name__, np.linalg.eigvalsh(L)[1]) ndarray 0.27306766...