mowgli.score

mowgli.score.embedding_leiden_across_resolutions(embedding: ndarray, labels: ndarray, n_neighbors: int, resolutions: Iterable[float] = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.]))

Compute the ARI and NMI for Leiden clustering on an embedding, for various resolutions.

Parameters:
  • embedding (np.ndarray) – The embedding, shape (n_obs, n_latent)

  • labels (np.ndarray) – The labels, shape (n_obs,)

  • n_neighbors (int) – The number of neighbors to use for the kNN graph.

  • resolutions (Iterable[float], optional) – The resolutions to use for Leiden clustering. Defaults to np.arange(0.1, 2.1, 0.1).

Returns:

The resolutions, ARIs and NMIs.

Return type:

Tuple[Iterable[float], Iterable[float], Iterable[float]]

mowgli.score.embedding_silhouette_score(embedding: ndarray, labels: ndarray, metric: str = 'euclidean') float

Compute the silhouette score for an embedding.

Parameters:
  • embedding (np.ndarray) – The embedding, shape (n_obs, n_latent)

  • labels (np.ndarray) – The labels, shape (n_obs,)

  • metric (str, optional) – The metric on the embedding space. Defaults to “euclidean”.

Returns:

The silhouette score.

Return type:

float

mowgli.score.embedding_to_knn(embedding: ndarray, k: int = 15, metric: str = 'euclidean') ndarray

Convert embedding to knn

Parameters:
  • embedding (np.ndarray) – The embedding (n_obs, n_latent)

  • k (int, optional) – The number of nearest neighbors. Defaults to 15.

  • metric (str, optional) – The metric to compute neighbors with. Defaults to “euclidean”.

Returns:

The knn (n_obs, k)

Return type:

np.ndarray

mowgli.score.knn_purity_score(knn: ndarray, labels: ndarray) float

Compute the kNN purity score, averaged over all observations. For one observation, the purity score is the percentage of nearest neighbors that share its label.

Parameters:
  • knn (np.ndarray) – The knn, shaped (n_obs, k). The i-th row should contain integers representing the indices of the k nearest neighbors.

  • labels (np.ndarray) – The labels, shaped (n_obs)

Returns:

The purity score.

Return type:

float