Compute recall@topk: fraction of gt top-k found in returned top-k.
(ids: np.ndarray, gt: np.ndarray, topk: int)
| 23 | # ────────────────────────────────────────────── |
| 24 | |
| 25 | def compute_recall(ids: np.ndarray, gt: np.ndarray, topk: int) -> float: |
| 26 | """Compute recall@topk: fraction of gt top-k found in returned top-k.""" |
| 27 | nq = ids.shape[0] |
| 28 | total_correct = 0 |
| 29 | for i in range(nq): |
| 30 | gt_set = set(gt[i, :topk].tolist()) |
| 31 | for j in range(topk): |
| 32 | if ids[i, j] in gt_set: |
| 33 | total_correct += 1 |
| 34 | return total_correct / (nq * topk) |
| 35 | |
| 36 | # ────────────────────────────────────────────── |
| 37 | # Clustering |