transition#
- graph_tool.spectral.transition(g, weight=None, vindex=None, operator=False, csr=True)[source]#
Return the transition matrix of the graph.
- Parameters:
- g
Graph
Graph to be used.
- 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.LinearOperator
subclass is returned, instead of a sparse matrix.- csr
bool
(optional, default:True
) If
True
, andoperator
isFalse
, ascipy.sparse.csr_matrix
sparse matrix is returned, otherwise ascipy.sparse.coo_matrix
is returned instead.
- g
- Returns:
- T
csr_matrix
orTransitionOperator
The (sparse) transition matrix.
- T
Notes
The transition matrix is defined as
\[T_{ij} = \frac{A_{ij}}{k_j}\]where \(k_i = \sum_j A_{ji}\), and \(A_{ij}\) is the adjacency matrix.
In the case of weighted edges, the values of the adjacency matrix are multiplied by the edge weights.
Note
For directed graphs the definition above means that the entry \(T_{ij}\) corresponds to the directed edge \(j\to i\). Although this is a typical definition in network and graph theory literature, many also use the transpose of this matrix.
LinearOperator
vs. sparse matricesFor many linear algebra computations it is more efficient to pass
operator=True
to this function. In this case, it will return ascipy.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 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
[wikipedia-transition]Examples
>>> g = gt.collection.data["polblogs"] >>> T = gt.transition(g, operator=True) >>> N = g.num_vertices() >>> ew1 = scipy.sparse.linalg.eigs(T, k=N//2, which="LR", return_eigenvectors=False) >>> ew2 = scipy.sparse.linalg.eigs(T, k=N-N//2, which="SR", return_eigenvectors=False) >>> ew = np.concatenate((ew1, ew2))
>>> figure(figsize=(8, 2)) <...> >>> scatter(real(ew), imag(ew), c=sqrt(abs(ew)), linewidths=0, alpha=0.6) <...> >>> xlabel(r"$\operatorname{Re}(\lambda)$") Text(...) >>> ylabel(r"$\operatorname{Im}(\lambda)$") Text(...) >>> tight_layout() >>> savefig("transition-spectrum.svg")