ak_lpe#

scio.scores.utils.ak_lpe(index, k, query, *, self_query=False)[source]#

Mean distance from \(\approx k\)-th nearest neighbors.

Parameters:
  • index (Index) – Search index.

  • k (int) – Number of neighbors to look up.

  • query (Tensor) – The query samples, not necessarily flattened. Shape (n_query, *sample_shape).

  • self_query (bool) – See Index.search(). Requires one additional reference sample in index. Defaults to False.

Returns:

out (Tensor) – Mean distance from m-th nearest neighbors, with k / 2 < m <= 3 * k // 2. Shape (n_query,). Full of nan if index.ntotal < 3 * k // 2 + self_query.

Attention

If index uses the \(L^2\) metric, the “mean distance” actually ressembles a variance, since Index.search() outputs the squared euclidian distance in that case.