Utility functions¶
Assorted utility functions for the motifcluster module are in motifcluster.utils.
-
_a_b_one
(a_mat, b_mat)¶ Compute a right-multiplication with the ones matrix.
Compute a * (b @ one_mat) where a, b, ones_mat are square matrices of the same size, and ones_mat contains all entries equal to one. The product * is an entry-wise (Hadamard) product, while @ represents matrix multiplication. This method is more efficient than the naive approach when a or b are sparse.
Parameters: a, b (matrix) – Square matrices of the same size. Returns: The sparse square matrix a * (b @ one_mat). Return type: sparse matrix
-
_a_one_b
(a_mat, b_mat)¶ Compute a left-multiplication with the ones matrix.
Compute a * (one_mat @ b) where a, b, ones_mat are square matrices of the same size, and ones_mat contains all entries equal to one. The product * is an entry-wise (Hadamard) product, while @ represents matrix multiplication. This method is more efficient than the naive approach when a or b are sparse.
Parameters: a, b (matrix) – Square matrices of the same size. Returns: The sparse square matrix a * (one_mat @ b). Return type: sparse matrix
-
_drop0_killdiag
(some_mat)¶ Set diagonal entries to zero and sparsify.
Set the diagonal entries of a matrix to zero and convert it to sparse form.
Parameters: some_mat (matrix) – A square matrix. Returns: sparse_mat – A sparse-form copy of some_mat with its diagonal entries set to zero. Return type: sparse matrix
-
_random_sparse_matrix
(m, n, p, sample_weight_type='constant', w=1)¶ Build a random sparse matrix.
Build a sparse matrix of size m * n with non-zero probability p. Edge weights can be unweighted, constant-weighted or Poisson-weighted.
Parameters: - m (int) – Size of first dimension of matrix.
- n (int) – Size of second dimension of matrix.
- p (float) – Probability that each entry is non-zero (before weighting).
- sample_weight_type (str) – Type of weighting scheme.
- w (float) – Weight parameter.
Returns: A random sparse matrix.
Return type: sparse matrix
-
get_largest_component
(adj_mat, gr_method)¶ Get largest connected component.
Get the indices of the vertices in the largest connected component of a graph from its adjacency matrix.
Parameters: - adj_mat (matrix) – An adjacency matrix of a graph.
- gr_method (str) – Format to use before building the graph. One of “sparse” or “dense”.
Returns: verts_to_keep – A list of indices corresponding to the vertices in the largest connected component.
Return type: list
Examples
>>> adj_mat = np.array([0, 1, 0, 0, 0, 0, 0, 0, 0]).reshape((3, 3)) >>> get_largest_component(adj_mat)
-
get_motif_names
()¶ Get common motif names.
Get the names of some common motifs as strings.
Returns: motif_names – A list of names (strings) of common motifs. Return type: list