magnetic_laplacian#
- graph_tool.spectral.magnetic_laplacian(g, q=0.25, norm=False, weight=None, vindex=None, operator=False, csr=True)[git][source]#
Return the magnetic Laplacian matrix of the graph.
- Parameters:
- g
Graph Graph to be used.
- q
float(optional, default:0.25) Charge parameter, with \(0\le q\le 1/2\).
- norm
bool(optional, default:False) Whether to compute the normalized magnetic Laplacian.
- weight
EdgePropertyMap(optional, default:None) Edge property map with the edge weights.
- vindex
VertexPropertyMap(optional, default:None) Vertex property map specifying the row/column indices. If not provided, the internal vertex index is used.
- operator
bool(optional, default:False) If
True, ascipy.sparse.linalg.LinearOperatorsubclass is returned, instead of a sparse matrix.- csr
bool(optional, default:True) If
True, andoperatorisFalse, ascipy.sparse.csr_matrixsparse matrix is returned, otherwise ascipy.sparse.coo_matrix.
- g
- Returns:
- L
csr_matrix,coo_matrix, orMagneticLaplacianOperator The (sparse, complex Hermitian) magnetic Laplacian matrix.
- L
See also
laplacianLaplacian matrix
directed_laplacianLaplacian of a directed graph
Notes
The magnetic Laplacian [fanuel-magnetic-2018] encodes the directions of the edges in complex phases. With the symmetrized weights \(w'_{ij} = (w_{ij} + w_{ji})/2\) (where \(w_{ij}\) is the sum of the weights of the edges \(j\to i\), with unit weights if
weightis not given; for undirected graphs, \(w'_{ij}\) is the sum of the weights of the edges between \(i\) and \(j\)), it is\[\begin{split}\ell_{ij} = \begin{cases} \sum_{k\ne i} w'_{ik} & \text{if } i = j, \\ -w'_{ij}\,e^{\mathrm{i}2\pi q\delta_{ij}} & \text{otherwise}, \end{cases}\end{split}\]where \(\mathrm{i}\) is the imaginary unit, \(\delta_{ij} = 1\) if there are edges \(j\to i\) but not \(i\to j\), \(\delta_{ij}=-1\) in the opposite case, and \(\delta_{ij}=0\) otherwise (self-loops are ignored). For \(q=0\), or for undirected graphs, it reduces to the Laplacian of the symmetrized graph. The normalized version is \(D^{-1/2}LD^{-1/2}\), where \(D\) is the diagonal of \(L\), and has unit diagonal entries for the vertices with nonzero degree. The matrix is Hermitian and positive semidefinite, so its eigenvalues are real and nonnegative.
As in
laplacian(), the entry \(\ell_{ij}\) corresponds to the edge \(j\to i\); the matrix with the opposite convention is the complex conjugate. The matrix is built in time \(O(V + E)\).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
[fanuel-magnetic-2018]Michaël Fanuel, Carlos M. Alaíz, Ángela Fernández and Johan A. K. Suykens, “Magnetic eigenmaps for the visualization of directed networks”, Applied and Computational Harmonic Analysis 44, 189-199 (2018), DOI: 10.1016/j.acha.2017.01.004 [sci-hub, @tor]
Examples
>>> g = gt.collection.data["celegansneural"] >>> L = gt.magnetic_laplacian(g, norm=True) >>> ew = scipy.sparse.linalg.eigsh(L, k=1, which="SA", ... return_eigenvectors=False) >>> print(ew) [0.28338...]