public static void Experiments(string algo, string candidate_item, string dataset_name, bool b_social_int, bool b_social_unint, bool b_rating_int, bool b_rating_unint, int[] balance, string version) { int num_recommend = 50; for (int fold = 1; fold <= 1; fold++) { string data_name = "SRWR_" + dataset_name; string result_name = data_name + "_" + version; if (b_social_int == true) { if (b_social_unint == false) { result_name = result_name + "_social(int)"; } else { result_name = result_name + "_social(int,unint)"; } } else { if (b_social_unint == false) { } else { result_name = result_name + "_social(unint)"; } } if (b_rating_int == true) { if (b_rating_unint == false) { result_name = result_name + "_rating(int)"; } else { result_name = result_name + "_rating(int,unint)"; } } else { if (b_rating_unint == false) { } else { result_name = result_name + "_rating(unint)"; } } StreamReader social = new StreamReader(file_path + data_name + "_social_bi.txt"); StreamReader social_unint = new StreamReader(file_path + data_name + "_social_predict_500.txt"); StreamReader training = new StreamReader(file_path + data_name + "_rating_train_bi.txt"); StreamReader training_unint = new StreamReader(file_path + data_name + "_rating_train_predict_500.txt"); StreamWriter result = new StreamWriter(file_path + "Result\\" + result_name + ".results"); StreamReader test = new StreamReader(file_path + data_name + "_rating_test.txt"); StreamWriter time = new StreamWriter(file_path + "Result\\" + result_name + ".time"); if (b_social_int == false) { social = null; } if (b_social_unint == false) { social_unint = null; } if (b_rating_int == false) { training = null; } if (b_rating_unint == false) { training_unint = null; } Stopwatch sw = new Stopwatch(); sw.Start(); if (algo == "SignedRWR_SoRec") { double beta = 0.9d; double gamma = 0.9d; double delta = 0.5d; var recsys = new SignedRWR_Recommender(candidate_item, num_recommend, fold, test, beta, gamma, delta, num_user, balance, social, social_unint, training, training_unint); recsys.Recommend(); recsys.PrintResults(result); } else { break; } sw.Stop(); time.WriteLine(algo + "\t" + sw.ElapsedMilliseconds.ToString() + "ms"); Console.WriteLine(algo + "\t" + sw.ElapsedMilliseconds.ToString() + "ms"); time.Close(); result.Close(); } }
public static void Experiments(string algo, string candidate_item) { int num_recommend = 50; for (int fold = 1; fold <= 1; fold++) { if (candidate_item == "Longtail_items") { tophead_items = new HashSet <int>(); sr = new StreamReader(file_path + "raw\\longtail\\u" + fold + "_longtail_items.txt"); while (!sr.EndOfStream) { int item_id = int.Parse(sr.ReadLine().ToString()) + num_user; tophead_items.Add(item_id); } sr.Close(); } StreamReader training = new StreamReader(file_path + "unint\\basic\\u" + fold + "\\u" + fold + "_balance.base"); StreamReader test = new StreamReader(file_path + "raw\\basic\\u" + fold + "\\u" + fold + ".test"); StreamWriter result = new StreamWriter(file_path + "results\\" + algo + "\\unint\\origin\\u" + fold + "_" + algo + "_rankresult_balance(" + candidate_item + ").results"); StreamWriter time = new StreamWriter(file_path + "results\\" + algo + "\\unint\\origin\\u" + fold + "_" + algo + "_rankresult_balance(" + candidate_item + ").time"); Stopwatch sw = new Stopwatch(); sw.Start(); if (algo == "SeparateRWR") { var recsys = new SeparateRWR_Recommender(candidate_item, num_recommend, fold, training, test); recsys.Recommend(); recsys.PrintResults(result); } else if (algo == "SignedRWR") { double beta = 0.9d; double gamma = 0.9d; var recsys = new SignedRWR_Recommender(candidate_item, num_recommend, fold, training, test, beta, gamma); recsys.Recommend(); recsys.PrintResults(result); } else if (algo == "SeparateBP") { int num_iter = 5; double propagation_alpha = 0.0001d; var recsys = new SeparateBP_Recommender(candidate_item, num_iter, num_recommend, propagation_alpha, fold, training, test); recsys.Recommend(); recsys.PrintResults(result); } else if (algo == "SignedBP") { int num_iter = 5; double propagation_alpha = 0.0001d; var recsys = new SignedBP_Recommender(candidate_item, num_iter, num_recommend, propagation_alpha, fold, training, test); recsys.Recommend(); recsys.PrintResults(result); } else if (algo == "RWR") { var recsys = new RWR_Recommender(candidate_item, num_recommend, fold, training, test); recsys.Recommend(); recsys.PrintResults(result); } sw.Stop(); time.WriteLine(algo + "\t" + sw.ElapsedMilliseconds.ToString() + "ms"); Console.WriteLine(algo + "\t" + sw.ElapsedMilliseconds.ToString() + "ms"); time.Close(); result.Close(); } }