spateo.tools.cluster.leiden =========================== .. py:module:: spateo.tools.cluster.leiden Functions --------- .. autoapisummary:: spateo.tools.cluster.leiden.distance_knn_graph spateo.tools.cluster.leiden.embedding_knn_graph spateo.tools.cluster.leiden.adj_to_igraph spateo.tools.cluster.leiden.calculate_leiden_partition spateo.tools.cluster.leiden.calculate_louvain_partition Module Contents --------------- .. py:function:: distance_knn_graph(dist: numpy.ndarray, num_neighbors: int) Construct a k-nearest neighbor graph from a distance matrix. :param dist: Pairwise distance matrix :param num_neighbors: Number of nearest neighbors :returns: K-nearest neighbor graph :rtype: G .. py:function:: embedding_knn_graph(X: numpy.ndarray, num_neighbors: int) Construct a k-nearest neighbor graph from an arbitrary array, of shape [n_samples, n_features] :param X: Embedding matrix :param num_neighbors: Number of nearest neighbors :returns: K-nearest neighbor graph :rtype: G .. py:function:: adj_to_igraph(adj: numpy.ndarray) Convert an adjacency matrix to an igraph graph. .. py:function:: calculate_leiden_partition(adj: Optional[Union[scipy.sparse.spmatrix, numpy.ndarray]] = None, input_mat: Optional[numpy.ndarray] = None, num_neighbors: int = 10, graph_type: Literal['distance', 'embedding'] = 'distance', resolution: float = 1.0, n_iterations: int = -1) -> numpy.ndarray Performs Leiden clustering on a given dataset. :param adj: Optional precomputed adjacency matrix :param input_mat: Optional, will be used only if 'adj' is not given. The input data, will be interepreted as either a distance matrix (if :param `graph_type` is "distance" or an embedding matrix (if :param `graph_type` is "embedding") :param num_neighbors: Only used if 'adj' is not given- the number of nearest neighbors for constructing the graph :param graph_type: Only used if 'adj' is not given- specifies the input type, either 'distance' or 'embedding' :param resolution: The resolution parameter for the Leiden algorithm :param n_iterations: The number of iterations for the Leiden algorithm (-1 for unlimited iterations) :returns: Array containing cluster assignments :rtype: clusters .. py:function:: calculate_louvain_partition(adj: Optional[Union[scipy.sparse.spmatrix, numpy.ndarray]] = None, input_mat: Optional[numpy.ndarray] = None, num_neighbors: int = 10, graph_type: Literal['distance', 'embedding'] = 'distance', resolution: float = 1.0, n_iterations: int = -1) -> numpy.ndarray Performs Louvain clustering on a given dataset. :param adj: Optional precomputed adjacency matrix :param input_mat: Optional, will be used only if 'adj' is not given. The input data, will be interepreted as either a distance matrix (if :param `graph_type` is "distance" or an embedding matrix (if :param `graph_type` is "embedding") :param num_neighbors: Only used if 'adj' is not given- the number of nearest neighbors for constructing the graph :param graph_type: Only used if 'adj' is not given- specifies the input type, either 'distance' or 'embedding' :param resolution: The resolution parameter for the Louvain algorithm :param n_iterations: The number of iterations for the Louvain algorithm (-1 for unlimited iterations) :returns: Array containing cluster assignments :rtype: clusters