示例#1
0
        public IReadOnlyList <WeightedMovie> GetRecoMovies(User u, UserRecoOptions options)
        {
            var users     = GetSimilarUsers(u, options.NbSimilarUser, options.OnlyPositiveUserSimilarity);
            var allMovies = new Dictionary <Movie, WeightedMovie>();

            foreach (var other in users)
            {
                foreach (var movieRated in other.User.Ratings)
                {
                    var m = movieRated.Key;
                    if (u.Ratings.ContainsKey(m))
                    {
                        continue;
                    }
                    allMovies.TryGetValue(m, out WeightedMovie already);
                    double deltaWeight = other.Similarity
                                         * (movieRated.Value - options.DeltaMovieRating);
                    allMovies[m] = new WeightedMovie(
                        m,
                        already.TotalWeight + deltaWeight,
                        already.Count + 1);
                }
            }
            var bestMovies = new BestKeeper <WeightedMovie>(
                options.MaxMovieCount,
                (m1, m2) => Math.Sign(m2.Weight - m1.Weight));

            foreach (var mW in allMovies.Values)
            {
                bestMovies.Add(mW);
            }
            return(bestMovies);
        }
示例#2
0
        public IReadOnlyCollection <SimilarMovies> GetSimilarMovies(Movie m, User[] users, int count = 100)
        {
            BestKeeper <SimilarMovies> best = new BestKeeper <SimilarMovies>(count,
                                                                             (m1, m2) => Math.Sign(m1.Similarity - m2.Similarity));

            foreach (var movie in Movies)
            {
                if (movie != m)
                {
                    best.AddCandidate(new SimilarMovies(movie, SimilarityPearson(m, movie, users)));
                }
            }
            return(best);
        }
示例#3
0
        public IReadOnlyCollection <SimilarUser> GetSimilarUsers(User u, int count = 100)
        {
            BestKeeper <SimilarUser> best = new BestKeeper <SimilarUser>(count,
                                                                         (u1, u2) => Math.Sign(u1.Similarity - u2.Similarity));

            foreach (var other in Users)
            {
                if (other != u)
                {
                    best.AddCandidate(new SimilarUser(other, SimilarityPearson(u, other)));
                }
            }
            return(best);
        }
示例#4
0
        public SimilarMovie[] GetSimilarMovies(Movie m, int count)
        {
            BestKeeper <SimilarMovie> best = new BestKeeper <SimilarMovie>(count,
                                                                           (s1, s2) => Math.Sign(s2.Similarity - s1.Similarity));

            foreach (var other in Movies)
            {
                if (other == m)
                {
                    continue;
                }
                SimilarMovie sM = new SimilarMovie(other, SimilarityPearson(m, other));
                best.Add(sM);
            }
            return(best.ToArray());
        }
示例#5
0
        public SimilarUser[] GetSimilarUsers(User u, int count)
        {
            BestKeeper <SimilarUser> best = new BestKeeper <SimilarUser>(count,
                                                                         (s1, s2) => Math.Sign(s2.Similarity - s1.Similarity));

            //BestKeeper<SimilarUser> worst = new BestKeeper<SimilarUser>( count,
            //                                        (s1,s2) => Math.Sign( s1.Similarity - s2.Similarity ) );
            foreach (var other in Users)
            {
                if (other == u)
                {
                    continue;
                }
                SimilarUser sU = new SimilarUser(other, SimilarityPearson(u, other));
                best.Add(sU);
            }
            return(best.ToArray());
        }