protected void Run(string[] args) { Console.WriteLine("WISER-RecSys começou"); options = new OptionSet() { // string-valued options { "arquivo=", v => arquivo = v }, { "measures=", v => measures = v }, { "recommender-options=", v => recommender_options += " " + v }, { "help", v => show_help = v != null }, }; eval_measures = ItemRecommendationEvaluationResults.DefaultMeasuresToShow; IList<string> extra_args = options.Parse(args); if (show_help) Usage(0); //eval if (measures != null) eval_measures = measures.Split(' ', ','); //Rodar o de vocs // training_file = "training.data"; test_file = "test.data"; training_partial_file = "training.partial.data"; test_partial_file = "test.partial.data"; for (int i = 0; i < arquivos.Length; i++) { MyMediaLite.Random.Seed = 1; item_attributes_file = "movie_" + arquivos[i] + ".dat_saida"; user_mapping.Add(new Mapping()); item_mapping.Add(new Mapping()); //Setup recommender recommenders.Add("BPRMFAttr".CreateItemRecommender()); recommenders[i].Configure(recommender_options, (string msg) => { Console.Error.WriteLine(msg); Environment.Exit(-1); }); // item attributes if (recommenders[i] is IItemAttributeAwareRecommender && item_attributes_file == null) Abort("Recommender expects --item-attributes=FILE."); if (item_attributes_file != null) item_attributes.Add(AttributeData.Read(item_attributes_file, item_mapping[i])); if (recommenders[i] is IItemAttributeAwareRecommender) ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes = item_attributes[i]; IBooleanMatrix lista_vazia = new SparseBooleanMatrix(); if (recommenders[i] is IUserAttributeAwareRecommender) ((IUserAttributeAwareRecommender)recommenders[i]).UserAttributes = lista_vazia; // training data training_data.Add(ItemData.Read(training_file, user_mapping[i], item_mapping[i], false)); test_data.Add(ItemData.Read(test_file, user_mapping[i], item_mapping[i], false)); test_users.Add(test_data[i].AllUsers); //Probe training_probe_data.Add(ItemData.Read(training_partial_file, user_mapping[i], item_mapping[i], false)); test_probe_data.Add(ItemData.Read(test_partial_file, user_mapping[i], item_mapping[i], false)); if (recommenders[i] is MyMediaLite.ItemRecommendation.ItemRecommender) ((ItemRecommender)recommenders[i]).Feedback = training_probe_data[i]; //Trainar Console.WriteLine("Vamos ao probe training"); var train_time_span = Wrap.MeasureTime(delegate () { recommenders[i].Train(); }); Console.WriteLine("training_time " + train_time_span + " "); } Evaluation evaluation = new Evaluation(recommenders, test_probe_data, training_probe_data); //Probe learn Console.WriteLine("Probe learn started"); TimeSpan time_span = Wrap.MeasureTime(delegate () { evaluation.EvaluateProbe(test_users, user_mapping, item_mapping); }); Console.WriteLine(" Probe learn time: " + time_span); for (int i = 0; i < arquivos.Length; i++) { MyMediaLite.Random.Seed = 1; item_attributes_file = "movie_" + arquivos[i] + ".dat_saida"; //Setup recommender recommenders[i] = "BPRMFAttr".CreateItemRecommender(); recommenders[i].Configure(recommender_options, (string msg) => { Console.Error.WriteLine(msg); Environment.Exit(-1); }); // item attributes if (recommenders[i] is IItemAttributeAwareRecommender && item_attributes_file == null) Abort("Recommender expects --item-attributes=FILE."); if (recommenders[i] is IItemAttributeAwareRecommender) ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes = item_attributes[i]; IBooleanMatrix lista_vazia = new SparseBooleanMatrix(); if (recommenders[i] is IUserAttributeAwareRecommender) ((IUserAttributeAwareRecommender)recommenders[i]).UserAttributes = lista_vazia; if (recommenders[i] is MyMediaLite.ItemRecommendation.ItemRecommender) ((ItemRecommender)recommenders[i]).Feedback = training_data[i]; //Trainar Console.WriteLine("Agora ao treino normal"); var train_time_span = Wrap.MeasureTime(delegate () { recommenders[i].Train(); }); Console.WriteLine("training_time " + train_time_span + " "); } var results = evaluation.Evaluate(test_data, training_data, test_users, user_mapping, item_mapping); foreach (EvaluationResults result in results) { Console.WriteLine(result.ToString()); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
protected void Run(string[] args) { Console.WriteLine("WISER-RecSys começou"); options = new OptionSet() { // string-valued options { "arquivo=", v => arquivo = v }, { "measures=", v => measures = v }, { "recommender-options=", v => recommender_options += " " + v }, { "help", v => show_help = v != null }, }; eval_measures = ItemRecommendationEvaluationResults.DefaultMeasuresToShow; IList <string> extra_args = options.Parse(args); if (show_help) { Usage(0); } //eval if (measures != null) { eval_measures = measures.Split(' ', ','); } //Rodar o de vocs // training_file = "training.data"; test_file = "test.data"; training_partial_file = "training.partial.data"; test_partial_file = "test.partial.data"; for (int i = 0; i < arquivos.Length; i++) { MyMediaLite.Random.Seed = 1; item_attributes_file = "movie_" + arquivos[i] + ".dat_saida"; user_mapping.Add(new Mapping()); item_mapping.Add(new Mapping()); //Setup recommender recommenders.Add("BPRMFAttr".CreateItemRecommender()); recommenders[i].Configure(recommender_options, (string msg) => { Console.Error.WriteLine(msg); Environment.Exit(-1); }); // item attributes if (recommenders[i] is IItemAttributeAwareRecommender && item_attributes_file == null) { Abort("Recommender expects --item-attributes=FILE."); } if (item_attributes_file != null) { item_attributes.Add(AttributeData.Read(item_attributes_file, item_mapping[i])); } if (recommenders[i] is IItemAttributeAwareRecommender) { ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes = item_attributes[i]; } IBooleanMatrix lista_vazia = new SparseBooleanMatrix(); if (recommenders[i] is IUserAttributeAwareRecommender) { ((IUserAttributeAwareRecommender)recommenders[i]).UserAttributes = lista_vazia; } // training data training_data.Add(ItemData.Read(training_file, user_mapping[i], item_mapping[i], false)); test_data.Add(ItemData.Read(test_file, user_mapping[i], item_mapping[i], false)); test_users.Add(test_data[i].AllUsers); //Probe training_probe_data.Add(ItemData.Read(training_partial_file, user_mapping[i], item_mapping[i], false)); test_probe_data.Add(ItemData.Read(test_partial_file, user_mapping[i], item_mapping[i], false)); if (recommenders[i] is MyMediaLite.ItemRecommendation.ItemRecommender) { ((ItemRecommender)recommenders[i]).Feedback = training_probe_data[i]; } //Trainar Console.WriteLine("Vamos ao probe training"); var train_time_span = Wrap.MeasureTime(delegate() { recommenders[i].Train(); }); Console.WriteLine("training_time " + train_time_span + " "); } Evaluation evaluation = new Evaluation(recommenders, test_probe_data, training_probe_data); //Probe learn Console.WriteLine("Probe learn started"); TimeSpan time_span = Wrap.MeasureTime(delegate() { evaluation.EvaluateProbe(test_users, user_mapping, item_mapping); }); Console.WriteLine(" Probe learn time: " + time_span); for (int i = 0; i < arquivos.Length; i++) { MyMediaLite.Random.Seed = 1; item_attributes_file = "movie_" + arquivos[i] + ".dat_saida"; //Setup recommender recommenders[i] = "BPRMFAttr".CreateItemRecommender(); recommenders[i].Configure(recommender_options, (string msg) => { Console.Error.WriteLine(msg); Environment.Exit(-1); }); // item attributes if (recommenders[i] is IItemAttributeAwareRecommender && item_attributes_file == null) { Abort("Recommender expects --item-attributes=FILE."); } if (recommenders[i] is IItemAttributeAwareRecommender) { ((IItemAttributeAwareRecommender)recommenders[i]).ItemAttributes = item_attributes[i]; } IBooleanMatrix lista_vazia = new SparseBooleanMatrix(); if (recommenders[i] is IUserAttributeAwareRecommender) { ((IUserAttributeAwareRecommender)recommenders[i]).UserAttributes = lista_vazia; } if (recommenders[i] is MyMediaLite.ItemRecommendation.ItemRecommender) { ((ItemRecommender)recommenders[i]).Feedback = training_data[i]; } //Trainar Console.WriteLine("Agora ao treino normal"); var train_time_span = Wrap.MeasureTime(delegate() { recommenders[i].Train(); }); Console.WriteLine("training_time " + train_time_span + " "); } var results = evaluation.Evaluate(test_data, training_data, test_users, user_mapping, item_mapping); foreach (EvaluationResults result in results) { Console.WriteLine(result.ToString()); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }