magnetic_laplacian

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:
gGraph

Graph to be used.

qfloat (optional, default: 0.25)

Charge parameter, with \(0\le q\le 1/2\).

normbool (optional, default: False)

Whether to compute the normalized magnetic Laplacian.

weightEdgePropertyMap (optional, default: None)

Edge property map with the edge weights.

vindexVertexPropertyMap (optional, default: None)

Vertex property map specifying the row/column indices. If not provided, the internal vertex index is used.

operatorbool (optional, default: False)

If True, a scipy.sparse.linalg.LinearOperator subclass is returned, instead of a sparse matrix.

csrbool (optional, default: True)

If True, and operator is False, a scipy.sparse.csr_matrix sparse matrix is returned, otherwise a scipy.sparse.coo_matrix.

Returns:
Lcsr_matrix, coo_matrix, or MagneticLaplacianOperator

The (sparse, complex Hermitian) magnetic Laplacian matrix.

See also

laplacian

Laplacian matrix

directed_laplacian

Laplacian 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 weight is 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)\).

LinearOperator vs. sparse matrices

For many linear algebra computations it is more efficient to pass operator=True to this function. In this case, it will return a scipy.sparse.linalg.LinearOperator subclass, which implements matrix-vector and matrix-matrix multiplication, and is sufficient for the sparse linear algebra operations available in the scipy module scipy.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...]