public void TestDefaultBehaviorIsNoDecay()
        {
            var mf = new SocialMF()
            {
                LearnRate = 1.1f, NumIter = 10, Ratings = TestUtils.CreateRatings(), UserRelation = new SparseBooleanMatrix()
            };

            mf.Train();
            Assert.AreEqual(1.1f, mf.current_learnrate);
        }
        public void TestCurrentLearnRate()
        {
            var mf = new SocialMF()
            {
                LearnRate = 1.1f, Ratings = TestUtils.CreateRatings(), UserRelation = new SparseBooleanMatrix()
            };

            mf.InitModel();
            Assert.AreEqual(1.1f, mf.LearnRate);
            Assert.AreEqual(1.1f, mf.current_learnrate);
        }
Esempio n. 3
0
        public void TestImplicitTrust()
        {
            var socialReguls = new float[] { 1F };
            var numFactors   = new uint[] { 5, 10 };
            var trustScores  = new string[] { "trust_values_LATHIA.dat", "trust_values_HWANGCHEN.dat",
                                              "trust_values_ODONOVAN.dat", "trust_values_PEARSON.dat", "trust_values_SHAMBOURLU.dat" };

            // step 1: dataset
            var config = new CsvConfiguration();

            config.Delimiter = " ";

            var trainReader = new CsvReader <ItemRating>(Paths.EpinionTrain80, config, new ItemRatingMap());
            var testReader  = new CsvReader <ItemRating>(Paths.EpinionTest20, config, new ItemRatingMap());
            var dataset     = new Dataset <ItemRating>(trainReader, testReader);

            foreach (string scoreFile in trustScores)
            {
                var relations = File.ReadAllLines(Paths.EpinionRelationsImplicit + scoreFile).ToCsvDictionary('\t')
                                .Select(i => new Relation()
                {
                    UserId             = i["UserId"],
                    ConnectedId        = i["ConnectionId"],
                    ConnectionStrength = float.Parse(i["Strength"])
                });
                //.Where(r => r.ConnectionStrength > 1F);

                string rmseValues = "", maeValues = "";

                foreach (uint num in numFactors)
                {
                    // step 2: recommender
                    var algorithm = new SocialMF();
                    algorithm.SocialRegularization = 1;
                    algorithm.NumFactors           = num;

                    var recommender = new MediaLiteRatingPredictor(algorithm, relations);

                    // step3: evaluation
                    var context = new EvalutationContext <ItemRating>(recommender, dataset);
                    var ep      = new EvaluationPipeline <ItemRating>(context);
                    ep.Evaluators.Add(new RMSE());
                    ep.Evaluators.Add(new MAE());

                    ep.Run();
                    rmseValues += context["RMSE"] + "\t";
                    maeValues  += context["MAE"] + "\t";
                }

                Console.WriteLine(scoreFile + "\t" + rmseValues + "\t" + maeValues);
            }
        }
        public void TestMatrixInit()
        {
            var mf = new SocialMF()
            {
                Ratings = TestUtils.CreateRatings(), UserRelation = new SparseBooleanMatrix()
            };

            mf.InitModel();
            Assert.IsNotNull(mf.user_factors);
            Assert.IsNotNull(mf.item_factors);
            Assert.IsNotNull(mf.user_bias);
            Assert.IsNotNull(mf.item_bias);
        }
Esempio n. 5
0
        public static void SocialMFTest()
        {
            List <Rating> baseRatings = Tools.GetRatings(BaseRatingFile, " ");
            List <Rating> testRatings = Tools.GetRatings(TestRatingFile, " ");
            List <Link>   links       = Tools.GetLinks(DefaultLinkFile, " ");

            Tools.UpdateIndexesToZeroBased(baseRatings);
            Tools.UpdateIndexesToZeroBased(testRatings);
            Tools.UpdateIndexesToZeroBased(links);

            SocialMF model = new SocialMF(MaxUserId, MaxItemId);

            model.TrySGD(baseRatings, testRatings, links, 200, 0.02, 0.9, 0.01, 0.01, 0.01);
        }
        public void TestDecay()
        {
            var mf = new SocialMF()
            {
                LearnRate    = 1.0f, Decay = 0.5f,
                NumIter      = 1, Ratings = TestUtils.CreateRatings(),
                UserRelation = new SparseBooleanMatrix()
            };

            mf.Train();
            Assert.AreEqual(0.5f, mf.current_learnrate);

            mf.Iterate();
            Assert.AreEqual(0.25f, mf.current_learnrate);
        }
        public void TestFoldIn()
        {
            var mf = new SocialMF()
            {
                Ratings = TestUtils.CreateRatings(), UserRelation = new SparseBooleanMatrix()
            };

            mf.Train();
            var user_ratings = new List <Tuple <int, float> >();

            user_ratings.Add(new Tuple <int, float>(0, 4.0f));
            var candidate_items = new List <int> {
                0, 1
            };                                                        // have a known and an unknown item
            var results = mf.ScoreItems(user_ratings, candidate_items);

            Assert.AreEqual(2, results.Count);
        }