Skip to content

Commit

Permalink
add support for disabling idf using idf_weighting=0
Browse files Browse the repository at this point in the history
  • Loading branch information
bkersbergen committed Mar 15, 2022
1 parent 1357284 commit 6f3127d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/vmisknn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ pub fn predict<I: SimilarityComputationNew + Send + Sync>(

for item_id in training_item_ids.iter() {
let item_idf = index.idf(item_id);
*item_scores.entry(*item_id).or_insert(0.0) +=
session_weight * item_idf * scored_session.score;
if item_idf > 0.0 {
*item_scores.entry(*item_id).or_insert(0.0) +=
session_weight * item_idf * scored_session.score;
} else {
*item_scores.entry(*item_id).or_insert(0.0) +=
session_weight * scored_session.score;
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/vmisknn/vmis_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,10 @@ pub(crate) fn prepare_hashmap(
item_to_top_sessions_ordered.insert(*current_item, current_item_similar_sessions_id_sorted);
// Store (item, idf score) in second hashmap
// let idf_score = (current_item_timestamps.len() as f64 / historical_sessions_values_sorted.len() as f64).ln();
let idf_score = if idf_weighting > 0.0 {
let idf_score =
(historical_sessions_values_sorted.len() as f64
/ current_item_timestamps.len() as f64)
.ln() * idf_weighting
} else {
1.0
};
.ln() * idf_weighting;
item_to_idf_score.insert(*current_item, idf_score);
let attributes = ProductAttributes {
is_adult: false,
Expand Down

0 comments on commit 6f3127d

Please sign in to comment.