Skip to content

Commit

Permalink
make calculate recall fn clear
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <kemingy94@gmail.com>
  • Loading branch information
kemingy committed Sep 25, 2024
1 parent 8f3cbec commit 8001d3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ where

/// Calculate the recall.
pub fn calculate_recall(truth: &[i32], res: &[i32], topk: usize) -> f32 {
assert_eq!(res.len(), topk);
let mut count = 0;
let length = topk.min(truth.len());
for t in truth.iter().take(length) {
for y in res.iter().take(length.min(res.len())) {
if *t == *y {
for id in res {
for t in truth.iter().take(topk) {
if *id == *t {
count += 1;
break;
}
}
}
(count as f32) / (length as f32)
(count as f32) / (topk as f32)
}

0 comments on commit 8001d3f

Please sign in to comment.