public string RunPrefMRF(double regularization, double learnRate, int maxEpoch, List <double> quantizer, int topN = 10) { // Load OMFDistribution from file Dictionary <Tuple <int, int>, List <double> > OMFDistributionByUserItem; if (File.Exists(GetDataFileName("PrefOMF_"))) { OMFDistributionByUserItem = Utils.IO <Dictionary <Tuple <int, int>, List <double> > > .LoadObject(GetDataFileName("PrefOMF_")); } else { return("Abort, Run OMF first."); } if (!ReadyForOrdinal) { GetReadyForOrdinal(); } StringBuilder log = new StringBuilder(); log.AppendLine(Utils.PrintHeading("PrefMRF: PrefNMF based ORF")); // Prediction Utils.StartTimer(); DataMatrix R_predicted_expectations; DataMatrix R_predicted_mostlikely; // Convert PR_train into user-wise preferences DataMatrix R_train_positions = new DataMatrix(PR_train.GetPositionMatrix()); R_train_positions.Quantization(quantizer[0], quantizer[quantizer.Count - 1] - quantizer[0], quantizer); ORF orf = new ORF(); orf.PredictRatings(R_train_positions, R_unknown, StrongSimilarityIndicatorsByItemPref, OMFDistributionByUserItem, regularization, learnRate, maxEpoch, quantizer.Count, out R_predicted_expectations, out R_predicted_mostlikely); log.AppendLine(Utils.StopTimer()); // Evaluation var topNItemsByUser_expectations = ItemRecommendationCore.GetTopNItemsByUser(R_predicted_expectations, topN); for (int n = 1; n <= topN; n++) { log.AppendLine(Utils.PrintValue("NCDG@" + n, NCDG.Evaluate(RelevantItemsByUser, topNItemsByUser_expectations, n).ToString("0.0000"))); } for (int n = 1; n <= topN; n++) { log.AppendLine(Utils.PrintValue("MAP@" + n, MAP.Evaluate(RelevantItemsByUser, topNItemsByUser_expectations, n).ToString("0.0000"))); } return(log.ToString()); }
public string RunNMFbasedORF(double regularization, double learnRate, int maxEpoch, List <double> quantizer, int topN = 0) { // Load OMFDistribution from file Dictionary <Tuple <int, int>, List <double> > OMFDistributionByUserItem; if (File.Exists(GetDataFileName("RatingOMF_"))) { OMFDistributionByUserItem = Utils.IO <Dictionary <Tuple <int, int>, List <double> > > .LoadObject(GetDataFileName("RatingOMF_")); } else { return("Abort, Run OMF first."); } if (!ReadyForNumerical) { GetReadyForNumerical(); } StringBuilder log = new StringBuilder(); log.AppendLine(Utils.PrintHeading("NMF based ORF")); // Prediction Utils.StartTimer(); DataMatrix R_predicted_expectations; DataMatrix R_predicted_mostlikely; ORF orf = new ORF(); orf.PredictRatings(R_train, R_unknown, StrongSimilarityIndicatorsByItemRating, OMFDistributionByUserItem, regularization, learnRate, maxEpoch, quantizer.Count, out R_predicted_expectations, out R_predicted_mostlikely); log.AppendLine(Utils.StopTimer()); // Numerical Evaluation log.AppendLine(Utils.PrintValue("RMSE", RMSE.Evaluate(R_test, R_predicted_expectations).ToString("0.0000"))); log.AppendLine(Utils.PrintValue("MAE", RMSE.Evaluate(R_test, R_predicted_mostlikely).ToString("0.0000"))); // Top-N Evaluation if (topN != 0) { var topNItemsByUser_expectations = ItemRecommendationCore.GetTopNItemsByUser(R_predicted_expectations, topN); for (int n = 1; n <= topN; n++) { log.AppendLine(Utils.PrintValue("NCDG@" + n, NCDG.Evaluate(RelevantItemsByUser, topNItemsByUser_expectations, n).ToString("0.0000"))); } for (int n = 1; n <= topN; n++) { log.AppendLine(Utils.PrintValue("MAP@" + n, MAP.Evaluate(RelevantItemsByUser, topNItemsByUser_expectations, n).ToString("0.0000"))); } } return(log.ToString()); }