pegasus.get_neighbors

pegasus.get_neighbors(data, K=100, rep='pca', n_jobs=- 1, random_state=0, full_speed=False, use_cache=True, dist='l2')[source]

Find K nearest neighbors for each data point and return the indices and distances arrays.

Parameters
  • data (pegasusio.MultimodalData) – An AnnData object.

  • K (int, optional (default: 100)) – Number of neighbors, including the data point itself.

  • rep (str, optional (default: ‘pca’)) – Representation used to calculate kNN. If None use data.X

  • n_jobs (int, optional (default: -1)) – Number of threads to use. -1 refers to using all physical CPU cores.

  • random_state (int, optional (default: 0)) – Random seed for random number generator.

  • full_speed (bool, optional (default: False)) – If full_speed, use multiple threads in constructing hnsw index. However, the kNN results are not reproducible. If not full_speed, use only one thread to make sure results are reproducible.

  • use_cache (bool, optional (default: True)) – If use_cache and found cached knn results, will not recompute.

  • dist (str, optional (default: ‘l2’)) – Distance metric to use. By default, use squared L2 distance. Available options, inner product ‘ip’ or cosine similarity ‘cosine’.

Return type

kNN indices and distances arrays.

Examples

>>> indices, distances = tools.get_neighbors(data)