pyFM.spectral.nearest_neighbor.tree_query

pyFM.spectral.nearest_neighbor.tree_query(X, Y, k=1, return_distance=False, n_jobs=None, leaf_size=None, **_)

Nearest neighbours via a kd-tree. Best in low dimension.

Trailing **_ is to ignore any extra arguments passed by the dispatcher.

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 distances.

  • n_jobs (int or None) – -1 uses all cores, 1 forces serial. None (default) uses all cores when n1 * n2 >= parallel_min_work, serial below it.

  • leaf_size (int, optional) – cKDTree leafsize. Defaults to the configured value.

Returns:

  • dists (np.ndarray, optional) – (n2,) if k = 1 else (n2, k). Distance to each neighbour. Only if return_distance.

  • matches (np.ndarray) – (n2,) if k = 1 else (n2, k). Index in X of each neighbour.