Skip to content

Commit 7c8f576

Browse files
johnarevaloJohn Arevalo
authored andcommitted
Add support in multilabel
1 parent 8bd40e6 commit 7c8f576

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/copairs/map/average_precision.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def build_rank_lists(
8484

8585
def average_precision(
8686
meta: pd.DataFrame,
87-
feats: pd.DataFrame,
87+
feats: np.ndarray,
8888
pos_sameby: List[str],
8989
pos_diffby: List[str],
9090
neg_sameby: List[str],

‎src/copairs/map/multilabel.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def negs_for(query: np.ndarray):
3939

4040

4141
def _build_rank_lists_multi(pos_pairs, pos_sims, pos_counts, negs_for):
42-
ap_scores_list, null_confs_list, ix_list = [], [], []
42+
ap_scores_list, auc_scores_list, null_confs_list, ix_list = [], [], [], []
4343

4444
start = 0
4545
for end in pos_counts.cumsum():
@@ -63,14 +63,16 @@ def _build_rank_lists_multi(pos_pairs, pos_sims, pos_counts, negs_for):
6363
_, counts = np.unique(ix, return_counts=True)
6464
ap_scores, null_confs = compute.ap_contiguous(rel_k_list, counts)
6565
ap_scores_list.append(ap_scores)
66+
auc_scores, _ = compute.auc_contiguous(rel_k_list, counts)
67+
auc_scores_list.append(auc_scores)
6668
null_confs_list.append(null_confs)
6769
ix_list.append(query)
68-
return ap_scores_list, null_confs_list, ix_list
70+
return ap_scores_list, auc_scores_list, null_confs_list, ix_list
6971

7072

7173
def average_precision(
7274
meta: pd.DataFrame,
73-
feats: pd.DataFrame,
75+
feats: np.ndarray,
7476
pos_sameby: List[str],
7577
pos_diffby: List[str],
7678
neg_sameby: List[str],
@@ -123,7 +125,7 @@ def average_precision(
123125

124126
logger.info("Computing AP per label...")
125127
negs_for = _create_neg_query_solver(neg_pairs, neg_sims)
126-
ap_scores_list, null_confs_list, ix_list = _build_rank_lists_multi(
128+
ap_scores_list, auc_scores_list, null_confs_list, ix_list = _build_rank_lists_multi(
127129
pos_pairs, pos_sims, pos_counts, negs_for
128130
)
129131

@@ -142,6 +144,7 @@ def average_precision(
142144
{
143145
"average_precision": ap_scores_list[i],
144146
"normalized_average_precision": normalized_scores,
147+
"roc_auc": auc_scores_list[i],
145148
"n_pos_pairs": null_confs_list[i][:, 0],
146149
"n_total_pairs": null_confs_list[i][:, 1],
147150
"ix": ix_list[i],

0 commit comments

Comments
 (0)