Spectral methods¶
Functions relating to spectral methods are in motifcluster.spectral.
-
_get_first_eigs
(some_mat, num_eigs)¶ Compute first few eigenvalues and eigenvectors of a matrix.
Compute the first few eigenvalues (by magnitude) and associated eigenvectors of a matrix.
Parameters: - some_mat (matrix) – Matrix for which eigenvalues and eigenvectors are to be calculated.
- num_eigs (int) – Number of eigenvalues and eigenvectors to calculate.
Returns: - vals (list) – A length-num_eigs list of the first few eigenvalues.
- vects (matrix) – A some_mat.shape[0] by num_eigs matrix of the associated eigenvectors.
-
build_laplacian
(adj_mat, type_lap='rw')¶ Build a Laplacian matrix.
Build a Laplacian matrix (combinatorial Laplacian or random-walk Laplacian) from a symmetric (weighted) graph adjacency matrix.
Parameters: - adj_mat (matrix) – Symmetric adjacency matrix from which to build the Laplacian.
- type_lap (str) – Type of Laplacian to build. One of “comb” (combinatorial) or “rw” (random-walk).
Returns: The specified Laplacian matrix.
Return type: sparse matrix
Examples
>>> adj_mat = np.array(range(1, 10)).reshape((3, 3)) >>> build_laplacian(adj_mat, "rw")
-
run_laplace_embedding
(adj_mat, num_eigs, type_lap='rw')¶ Run Laplace embedding.
Run Laplace embedding on a symmetric (weighted) adjacency matrix with a specified number of eigenvalues and eigenvectors.
Parameters: - adj_mat (matrix) – Symmetric adjacency matrix to be embedded.
- num_eigs (int) – Number of eigenvalues and eigenvectors for the embedding.
- type_lap (str) – Type of Laplacian for the embedding. One of “comb” (combinatorial) or “rw” (random-walk).
Returns: - vals (list) – The length-num_eigs list of the first few eigenvalues of the Laplacian.
- vects (matrix) – An adj_mat.shape[0] by num_eigs matrix of the associated eigenvectors.
Examples
>>> adj_mat = np.array(range(1, 10)).reshape((3, 3)) >>> run_laplace_embedding(adj_mat, 2, "rw")
-
run_motif_embedding
(adj_mat, motif_name, motif_type='struc', mam_weight_type='unweighted', mam_method='sparse', num_eigs=2, type_lap='rw', restrict=True, gr_method='sparse')¶ Run motif embedding.
Calculate a motif adjacency matrix for a given motif and motif type, optionally restrict it to its largest connected component, and then run Laplace embedding with specified Laplacian type and number of eigenvalues and eigenvectors.
Parameters: - adj_mat (matrix) – Adjacency matrix to be embedded.
- motif_name (str) – Motif used for the motif adjacency matrix.
- motif_type (str) – Type of motif adjacency matrix to use. One of “func” or “struc”.
- mam_weight_type (str) – Weighting scheme for the motif adjacency matrix. One of “unweighted”, “mean” or “product”.
- mam_method (str) – The method to use for building the motif adjacency matrix. One of “sparse” or “dense”.
- num_eigs (int) – Number of eigenvalues and eigenvectors for the embedding.
- type_lap (str) – Type of Laplacian for the embedding. One of “comb” or “rw”.
- restrict (bool) – Whether or not to restrict the motif adjacency matrix to its largest connected component before embedding.
- gr_method (str) – Format to use for getting largest component. One of “sparse” or “dense”.
Returns: - adj_mat (sparse matrix) – The original adjacency matrix.
- motif_adj_mat (sparse matrix) – The motif adjacency matrix.
- comps (list) – The indices of the largest connected component of the motif adjacency matrix (if restrict=True).
- adj_mat_comps (matrix) – The original adjacency matrix restricted to the largest connected component of the motif adjacency matrix (if restrict=True).
- motif_adj_mat_comps (matrix) – The motif adjacency matrix restricted to its largest connected component (if restrict=True).
- vals (list) – A length-num_eigs list containing the eigenvalues associated with the Laplace embedding of the (restricted) motif adjacency matrix.
- vects – A matrix containing the eigenvectors associated with the Laplace embedding of the (restricted) motif adjacency matrix.
Examples
adj_mat = np.array(range(1, 10)),reshape((3, 3)) run_motif_embedding(adj_mat, “M1”)