Example #1
0
        public double CalcPearson(UserP user, int minRatings = 0)
        {
            double sum1 = 0, sum2 = 0, sum1sq = 0, sum2sq = 0, psum = 0;
            int    n = 0;

            // Iterate over all rating combinations
            foreach (var rA in Ratings)
            {
                foreach (var rB in user.Ratings)
                {
                    if (rA.MovieId == rB.MovieId &&
                        (rA.Movie.NumberOfRatings > minRatings || rB.Movie.NumberOfRatings > minRatings))
                    {
                        sum1   += rA.Score;
                        sum2   += rB.Score;
                        sum1sq += rA.Score * rA.Score;
                        sum2sq += rB.Score * rB.Score;
                        psum   += rA.Score * rB.Score;
                        n++;
                    }
                }
            }
            if (n == 0)
            {
                return(0);
            }
            double num = psum - ((sum1 * sum2) / n);
            double den = Math.Sqrt((sum1sq - Math.Pow(sum1, 2.0) / n) * (sum2sq - Math.Pow(sum2, 2.0) / n));

            return(num / den);
        }
Example #2
0
 public UserViewModel(UserP u)
 {
     Id       = u.Id;
     Name     = u.Name;
     Distance = new DistanceMetric();
     // RatingsP = u.Ratings;
 }
Example #3
0
        public double CalcEuclidean(UserP user, int minRatings = 0)
        {
            double sim = 0;
            int    n   = 0;

            // Iterate over all rating combinations
            foreach (var rA in Ratings)
            {
                foreach (var rB in user.Ratings)
                {
                    if (rA.MovieId == rB.MovieId &&
                        (rA.Movie.NumberOfRatings > minRatings || rB.Movie.NumberOfRatings > minRatings))
                    {
                        sim += Math.Pow(rA.Score - rB.Score, 2.0);
                        n++;
                    }
                }
            }
            // No ratings in common, return 0 else calculate inverted score
            return(n == 0 ? 0 : 1 / (1 + sim));
        }
Example #4
0
        public override bool Equals(Object obj)
        {
            UserP g = obj as UserP;

            return(g != null && g.Id == this.Id);
        }