spamosaic.MNN.mnn

spamosaic.MNN.mnn(ds1, ds2, names1, names2, knn1=20, knn2=20, approx=True, metric='euclidean', way='hnsw', norm=False)[source]

Compute mutual nearest neighbors (MNN) between two datasets.

Parameters:
  • ds1 (np.ndarray) – First dataset (queries), shape (N1, D).

  • ds2 (np.ndarray) – Second dataset (references), shape (N2, D).

  • names1 (list of str) – Identifiers for rows in ds1.

  • names2 (list of str) – Identifiers for rows in ds2.

  • knn1 (int) – Number of neighbors for ds1 ds2.

  • knn2 (int) – Number of neighbors for ds2 ds1.

  • approx (bool, default=True) – If True, use approximate search (HNSW/Annoy); otherwise exact kNN.

  • metric (str, default='euclidean') – Distance metric used when way='annoy'.

  • way (str, default='hnsw') – Approximation backend: 'hnsw' or 'annoy'.

  • norm (bool, default=False) – Whether to normalize inputs before Annoy search (ignored for HNSW/exact).

Returns:

Set of mutual nearest-neighbor pairs.

Return type:

set[tuple[str, str]]