diff options
Diffstat (limited to 'worldalign/anchor_bound.py')
| -rw-r--r-- | worldalign/anchor_bound.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/worldalign/anchor_bound.py b/worldalign/anchor_bound.py index 49f4ed3..2920934 100644 --- a/worldalign/anchor_bound.py +++ b/worldalign/anchor_bound.py @@ -79,13 +79,19 @@ def analyse(path: str, label: str, repeats: int, blind: float | None) -> dict: order = generator.permutation(size) half = size // 2 anchors, probe = order[:half], order[half:] + # The two sides must not be presented in the same index order. Exact + # twins have identical anchor-restricted rows, and with matched + # ordering `linear_sum_assignment` breaks the tie onto the diagonal -- + # crediting the bound with information it does not have. On the + # caption-omitted field that inflated it from 0.920 to 0.997. + order = generator.permutation(len(probe)) left = rows_against(visual, probe, anchors) - right = rows_against(text, probe, anchors) + right = rows_against(text, probe[order], anchors) similarity = left @ right.T / left.shape[1] - truth = np.arange(len(probe)) - nearest.append(float((similarity.argmax(1) == truth).mean())) + truth = order + nearest.append(float((order[similarity.argmax(1)] == np.arange(len(probe))).mean())) _, columns = linear_sum_assignment(-similarity) - assigned.append(float((columns == truth).mean())) + assigned.append(float((order[columns] == np.arange(len(probe))).mean())) row = { "label": label, |
