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); }
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); }
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); }
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()); }
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()); }