Created
February 10, 2021 16:13
-
-
Save sscdotopen/c6a83c2c20f0c7ac633dc478ef53ca7d to your computer and use it in GitHub Desktop.
Session similarity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 'most_recent_neighbors' is a set of ~500 similar sessions | |
for neighbor_session in most_recent_neighbors.into_iter() { | |
let mut similarity = 0_f64; | |
// This returns a HashSet of the items contained in the session | |
let other_session_items = index.items_for_session(&neighbor_session.id); | |
// The 'evolving_session' is an array of items of length 'num_items_in_evolving_session' | |
for (pos, item_id) in evolving_session.iter().enumerate() { | |
if other_session_items.contains(&item_id) { | |
let weight = (pos + 1) as f64 / num_items_in_evolving_session as f64; | |
similarity += decay_factor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment