rapids_singlecell.tl.louvain

Contents

rapids_singlecell.tl.louvain#

rapids_singlecell.tl.louvain(adata, resolution=1.0, *, restrict_to=None, key_added='louvain', adjacency=None, n_iterations=100, threshold=1e-07, use_weights=True, neighbors_key=None, obsp=None, copy=False)[source]#

Performs Louvain clustering using cuGraph, which implements the method described in:

Blondel, V.D., Guillaume, J.-L., Lambiotte, R., & Lefebvre, E. (2008). Fast unfolding of community hierarchies in large networks, J. Stat. Mech., P10008. DOI: 10.1088/1742-5468/2008/10/P10008

Parameters:
adata AnnData

annData object

resolution float (default: 1.0)

A parameter value controlling the coarseness of the clustering (called gamma in the modularity formula). Higher values lead to more clusters.

restrict_to tuple[str, Sequence[str]] | None (default: None)

Restrict the clustering to the categories within the key for sample annotation, tuple needs to contain (obs_key, list_of_categories).

key_added str (default: 'louvain')

adata.obs key under which to add the cluster labels.

adjacency spmatrix | None (default: None)

Sparse adjacency matrix of the graph, defaults to neighbors connectivities.

n_iterations int (default: 100)

This controls the maximum number of levels/iterations of the Louvain algorithm. When specified the algorithm will terminate after no more than the specified number of iterations. No error occurs when the algorithm terminates early in this manner. Capped at 500 to prevent excessive runtime.

threshold float (default: 1e-07)

Modularity gain threshold for each level/iteration. If the gain of modularity between two levels of the algorithm is less than the given threshold then the algorithm stops and returns the resulting communities. Defaults to 1e-7.

use_weights bool (default: True)

If True, edge weights from the graph are used in the computation (placing more emphasis on stronger edges).

neighbors_key int | None (default: None)

If not specified, louvain looks at .obsp['connectivities'] for neighbors connectivities. If specified, louvain looks at .obsp[.uns[neighbors_key]['connectivities_key']] for neighbors connectivities.

obsp str | None (default: None)

Use .obsp[obsp] as adjacency. You can’t specify both obsp and neighbors_key at the same time.

copy bool (default: False)

Whether to copy adata or modify it in place.

Return type:

AnnData | None