Ejemplo n.º 1
0
        public double userSimilarity(long userID1, long userID2)
        {
            DataModel model = base.getDataModel();
            FastIDSet other = model.getItemIDsFromUser(userID1);
            FastIDSet set2  = model.getItemIDsFromUser(userID2);
            int       num   = other.size();
            int       num2  = set2.size();

            if ((num == 0) && (num2 == 0))
            {
                return(double.NaN);
            }
            if ((num == 0) || (num2 == 0))
            {
                return(0.0);
            }
            int num3 = (num < num2) ? set2.intersectionSize(other) : other.intersectionSize(set2);

            if (num3 == 0)
            {
                return(double.NaN);
            }
            int num4 = (num + num2) - num3;

            return(((double)num3) / ((double)num4));
        }
Ejemplo n.º 2
0
        public double userSimilarity(long userID1, long userID2)
        {
            DataModel model        = base.getDataModel();
            FastIDSet other        = model.getItemIDsFromUser(userID1);
            FastIDSet set2         = model.getItemIDsFromUser(userID2);
            int       num          = other.size();
            int       num2         = set2.size();
            int       intersection = (num < num2) ? set2.intersectionSize(other) : other.intersectionSize(set2);

            return(doSimilarity(num, num2, intersection));
        }
        public override int getNumUsersWithPreferenceFor(long itemID1, long itemID2)
        {
            FastIDSet other = this.preferenceForItems.get(itemID1);

            if (other == null)
            {
                return(0);
            }
            FastIDSet set2 = this.preferenceForItems.get(itemID2);

            if (set2 == null)
            {
                return(0);
            }
            return((other.size() < set2.size()) ? set2.intersectionSize(other) : other.intersectionSize(set2));
        }
Ejemplo n.º 4
0
        public double userSimilarity(long userID1, long userID2)
        {
            DataModel model = base.getDataModel();
            FastIDSet other = model.getItemIDsFromUser(userID1);
            FastIDSet set2  = model.getItemIDsFromUser(userID2);
            long      num   = other.size();
            long      num2  = set2.size();
            long      num3  = (num < num2) ? ((long)set2.intersectionSize(other)) : ((long)other.intersectionSize(set2));

            if (num3 == 0L)
            {
                return(double.NaN);
            }
            long   num4 = model.getNumItems();
            double num5 = LogLikelihood.logLikelihoodRatio(num3, num2 - num3, num - num3, ((num4 - num) - num2) + num3);

            return(1.0 - (1.0 / (1.0 + num5)));
        }