scimilarity.cell_search_knn#
- class scimilarity.cell_search_knn.CellSearchKNN(model_path, use_gpu=False)[source]#
Bases:
CellEmbedding
A class for searching similar cells using cell embeddings kNN.
- Parameters:
model_path (str) –
use_gpu (bool) –
- get_nearest_neighbors(embeddings, k=50, ef=100)[source]#
Get nearest neighbors. Used by classes that inherit from CellEmbedding and have an instantiated kNN.
- Parameters:
embeddings (numpy.ndarray) – Embeddings as a numpy array.
k (int, default: 50) – The number of nearest neighbors.
ef (int, default: 100) – The size of the dynamic list for the nearest neighbors. See https://github.com/nmslib/hnswlib/blob/master/ALGO_PARAMS.md
- Returns:
nn_idxs (numpy.ndarray) – A 2D numpy array of nearest neighbor indices [num_cells x k].
nn_dists (numpy.ndarray) – A 2D numpy array of nearest neighbor distances [num_cells x k].
- Return type:
Tuple[numpy.ndarray, numpy.ndarray]
Examples
>>> nn_idxs, nn_dists = get_nearest_neighbors(embeddings)