pyFM.spectral.nn_utils.knn_query¶
- pyFM.spectral.nn_utils.knn_query(X, Y, k=1, return_distance=False, n_jobs=None, *, method='auto', leaf_size=None, working_memory=None)¶
Query the k nearest neighbours in X of each point of Y.
The backend is chosen according to
choose_backend().- Parameters:
X (np.ndarray) – (n1, p). Reference points, the set being searched.
Y (np.ndarray) – (n2, p). Query points.
k (int) – Number of neighbours
return_distance (bool) – Whether to also return the nearest neighbour distances.
n_jobs (int or None) – Number of parallel jobs. -1 uses all processes, 1 forces single thread. None (default) uses all cores when n1 * n2 >= parallel_min_work (see
config). Only affects the tree backend.method (str) – “auto” (default), or “tree” / “brute” to force a backend.
leaf_size (int, optional) – Override the configured cKDTree leafsize.
working_memory (int, optional) – Override the configured chunking budget in MB. Ignored by the tree backend.
- Returns:
dists (np.ndarray, optional) – (n2,) if k = 1 else (n2, k). Distance to each neighbour. Only if return_distance is True.
matches (np.ndarray) – (n2,) if k = 1 else (n2, k). Index in X of each neighbour.