public override void Recommend() { SignedBeliefPropagation BP = new SignedBeliefPropagation(edge_list, node_potential_like, node_potential_dislike, propagation_matrix_like, propagation_matrix_dislike, max_user_id, max_item_id); recommend_user_item = new Dictionary <int, List <Score> >(); int num = 0; foreach (int target_user in correct_user_item.Keys) { if (!node_potential_like.ContainsKey(target_user)) { continue; } if (num != 0) { edge_list.Clear(); } List <Score> recommend_items = new List <Score>(); recommend_items = PerformBP(BP, target_user, num); recommend_user_item.Add(target_user, recommend_items); num++; if (num % 50 == 0) { Console.WriteLine("Compute BP score for {0} user / {1} users (fold{2}): Complete", num, correct_user_item.Count(), fold); } } Console.WriteLine("Compute BP scores: Complete"); }
public List <Score> PerformBP(SignedBeliefPropagation BP, int target_user, int num) { List <Score> belief_score_list = new List <Score>(); BP.AssignNodePotential(target_user); for (int iter = 0; iter < num_iter; iter++) { // message passing BP.PassMessage(target_user, iter); belief_score_list = BP.ComputeBeliefScore(target_user, test_items, num_recommend, correct_user_item); } List <Score> recommend_items = new List <Score>(); foreach (Score items in belief_score_list) { if (candidate_item == "Longtail_items") { if (Program.tophead_items.Contains(items.item_id)) { continue; } } if (node_potential_like[target_user].linkednode_list.Contains(items.item_id)) { continue; } //if (node_potential_dislike.ContainsKey(target_user)) // if (node_potential_dislike[target_user].linkednode_list.Contains(items.item_id)) continue; if (recommend_items.Count < num_recommend) { Score user_score = new Score(items.item_id, items.score); recommend_items.Add(user_score); } else { break; } } // 메모리 부족으로 이미 BP 수행한 target user 관련 데이터 지움 node_potential_like.Remove(target_user); BP.Clean(target_user); return(recommend_items); }