public BeliefPropagation(BPMatrix edge_list, Dictionary <int, NodePotential> node_potential, double[,] propagation_matrix, int max_user_id, int max_item_id) { this.edge_list = edge_list; this.node_potential = node_potential; this.propagation_matrix = propagation_matrix; this.max_user_id = max_user_id; this.max_item_id = max_item_id; }
public SignedBeliefPropagation (BPMatrix edge_list, Dictionary <int, NodePotential> node_potential_like, Dictionary <int, NodePotential> node_potential_dislike, double[,] propagation_matrix_like, double[,] propagation_matrix_dislike, int max_user_id, int max_item_id) { this.edge_list = edge_list; this.node_potential_like = node_potential_like; this.node_potential_dislike = node_potential_dislike; this.propagation_matrix_like = propagation_matrix_like; this.propagation_matrix_dislike = propagation_matrix_dislike; this.max_user_id = max_user_id; this.max_item_id = max_item_id; }
public override void ReadTrainingSet(StreamReader sr) { max_user_id = int.MinValue; max_item_id = int.MinValue; like_edges = new BPMatrix(); dislike_edges = new BPMatrix(); node_potential_like = new Dictionary <int, NodePotential>(); node_potential_dislike = new Dictionary <int, NodePotential>(); while (sr.EndOfStream == false) { line = sr.ReadLine().Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries); int user_id = int.Parse(line[0].ToString()); int item_id = int.Parse(line[1].ToString()) + Program.num_user; int rating = int.Parse(line[2].ToString()); if (max_user_id < user_id) { max_user_id = user_id; } if (max_item_id < item_id) { max_item_id = item_id; } if (rating == 1) { Edge forward_edge = new Edge(); like_edges.SetAt(user_id, item_id, forward_edge); Edge backward_edge = new Edge(); like_edges.SetAt(item_id, user_id, backward_edge); if (node_potential_like.ContainsKey(user_id)) { node_potential_like[user_id].AddNode(item_id); } else { NodePotential temp_node = new NodePotential(); temp_node.AddNode(item_id); node_potential_like.Add(user_id, temp_node); } } else { Edge forward_edge = new Edge(); dislike_edges.SetAt(user_id, item_id, forward_edge); Edge backward_edge = new Edge(); dislike_edges.SetAt(item_id, user_id, backward_edge); if (node_potential_dislike.ContainsKey(user_id)) { node_potential_dislike[user_id].AddNode(item_id); } else { NodePotential temp_node = new NodePotential(); temp_node.AddNode(item_id); node_potential_dislike.Add(user_id, temp_node); } } } }