Пример #1
0
        public static void TestAllRecommenders()
        {
            UserBehaviorDatabaseParser dbp = new UserBehaviorDatabaseParser();
            UserBehaviorDatabase       db  = dbp.LoadUserBehaviorDatabase("UserBehaviour.txt");

            //var ubt = new UserBehaviorTransformer(db);
            //var uart = ubt.GetUserArticleRatingsTable();
            //uart.SaveSparcityVisual("sparcity.bmp");
            //uart.SaveUserRatingDistribution("distrib.csv");
            //uart.SaveArticleRatingDistribution("distriba.csv");

            var rate = new LinearRater();
            var sp   = new DaySplitter(db, 5);
            var uc   = new CorrelationUserComparer();

            //var rr = new RandomRecommender();
            //rr.Train(sp.TrainingDB);
            //ScoreResults scores5 = rr.Score(sp.TestingDB, rate);
            //TestResults results5 = rr.Test(sp.TestingDB, 30);

            var ubc = new UserCollaborativeFilterRecommender(uc, rate, 30);
            var mfr = new MatrixFactorizationRecommender(30, rate);
            var icf = new ItemCollaborativeFilterRecommender(uc, rate, 30);
            var hbr = new HybridRecommender(ubc, mfr, icf);

            hbr.Train(sp.TrainingDB);
            ScoreResults scores1  = hbr.Score(sp.TestingDB, rate);
            TestResults  results1 = hbr.Test(sp.TestingDB, 30);

            ubc = new UserCollaborativeFilterRecommender(uc, rate, 30);
            mfr = new MatrixFactorizationRecommender(30, rate);
            icf = new ItemCollaborativeFilterRecommender(uc, rate, 30);

            ubc.Train(sp.TrainingDB);
            ScoreResults scores2  = ubc.Score(sp.TestingDB, rate);
            TestResults  results2 = ubc.Test(sp.TestingDB, 30);

            mfr.Train(sp.TrainingDB);
            ScoreResults scores3  = mfr.Score(sp.TestingDB, rate);
            TestResults  results3 = mfr.Test(sp.TestingDB, 30);

            icf.Train(sp.TrainingDB);
            ScoreResults scores4  = icf.Score(sp.TestingDB, rate);
            TestResults  results4 = icf.Test(sp.TestingDB, 30);

            using (StreamWriter w = new StreamWriter("results.csv"))
            {
                w.WriteLine("model,rmse,users,user-solved,precision,recall");
                w.WriteLine("UCF," + scores2.RootMeanSquareDifference + "," + results2.TotalUsers + "," + results2.UsersSolved + "," + results2.AveragePrecision + "," + results2.AverageRecall);
                w.WriteLine("SVD," + scores3.RootMeanSquareDifference + "," + results3.TotalUsers + "," + results3.UsersSolved + "," + results3.AveragePrecision + "," + results3.AverageRecall);
                w.WriteLine("ICF," + scores4.RootMeanSquareDifference + "," + results4.TotalUsers + "," + results4.UsersSolved + "," + results4.AveragePrecision + "," + results4.AverageRecall);
                w.WriteLine("HR," + scores1.RootMeanSquareDifference + "," + results1.TotalUsers + "," + results1.UsersSolved + "," + results1.AveragePrecision + "," + results1.AverageRecall);
            }
        }
Пример #2
0
        public void RemoveGame(int index)
        {
            Game game        = Games[index];
            int  winnerScore = 0;

            for (int i = 0; i < Players.Count; ++i)
            {
                int score = ComputeScore(game.NumBomb, GetNumCard(game.NumCards, i));
                winnerScore      -= score;
                Players[i].Score -= score;
            }
            Players[game.Winner].Score -= winnerScore;

            Games.RemoveAt(index);
            ScoreResults.RemoveAt(index);
        }
        public IActionResult GetByUserId()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var id = User.Identity.GetUserIdentity();

            if (!_board.AllRecords().Any(x => x.UserId == id))
            {
                return(NotFound());
            }

            var query      = _db.Database.GetCollection <ScoreRecord>(ResourceType.ScoreRecord.Name).AsQueryable();
            var allRecords = new ScoreResults(query.Where(x => x.UserId == id)
                                              .OrderByDescending(x => x.Timestamp)
                                              .PaginateAndSelect(null, null, x => new ScoreResult(x)));

            allRecords.Rank = _board.AllRecords().ToList().FindIndex(x => x.UserId == id) + 1;

            return(Ok(allRecords));
        }
Пример #4
0
        private void AddGame(Game game)
        {
            ScoreResult scoreResult = new ScoreResult();

            scoreResult.Time    = game.Time;
            scoreResult.NumBomb = game.NumBomb;

            Object scoreResultBox = scoreResult;
            int    winnerScore    = 0;

            for (int i = 0; i < Players.Count; ++i)
            {
                int score = ComputeScore(game.NumBomb, GetNumCard(game.NumCards, i));
                winnerScore -= score;
                scoreResult.GetType().GetProperty(string.Format("Score{0}", i)).SetValue(scoreResultBox, score);
                Players[i].Score += score;
            }
            scoreResult.GetType().GetProperty(string.Format("Score{0}", game.Winner)).SetValue(scoreResultBox, winnerScore);
            Players[game.Winner].Score += winnerScore;

            Games.Add(game);
            ScoreResults.Add((ScoreResult)scoreResultBox);
        }