public void testNumUsersPreferring()
 {
     Assert.AreEqual(2, model.GetNumUsersWithPreferenceFor(456));
     Assert.AreEqual(0, model.GetNumUsersWithPreferenceFor(111));
     Assert.AreEqual(0, model.GetNumUsersWithPreferenceFor(111, 456));
     Assert.AreEqual(2, model.GetNumUsersWithPreferenceFor(123, 234));
 }
        public override double ItemSimilarity(long itemID1, long itemID2)
        {
            IDataModel dataModel    = getDataModel();
            int        preferring1  = dataModel.GetNumUsersWithPreferenceFor(itemID1);
            int        preferring2  = dataModel.GetNumUsersWithPreferenceFor(itemID2);
            int        intersection = dataModel.GetNumUsersWithPreferenceFor(itemID1, itemID2);

            return(doSimilarity(preferring1, preferring2, intersection));
        }
        private double doItemSimilarity(long itemID1, long itemID2, int preferring1)
        {
            IDataModel dataModel       = getDataModel();
            int        preferring1and2 = dataModel.GetNumUsersWithPreferenceFor(itemID1, itemID2);

            if (preferring1and2 == 0)
            {
                return(Double.NaN);
            }
            int preferring2 = dataModel.GetNumUsersWithPreferenceFor(itemID2);

            return((double)preferring1and2 / (double)(preferring1 + preferring2 - preferring1and2));
        }
        public override double[] ItemSimilarities(long itemID1, long[] itemID2s)
        {
            IDataModel dataModel   = getDataModel();
            int        preferring1 = dataModel.GetNumUsersWithPreferenceFor(itemID1);

            double[] distance = new double[itemID2s.Length];
            for (int i = 0; i < itemID2s.Length; ++i)
            {
                int preferring2  = dataModel.GetNumUsersWithPreferenceFor(itemID2s[i]);
                int intersection = dataModel.GetNumUsersWithPreferenceFor(itemID1, itemID2s[i]);
                distance[i] = doSimilarity(preferring1, preferring2, intersection);
            }
            return(distance);
        }
Exemple #5
0
        public override double ItemSimilarity(long itemID1, long itemID2)
        {
            IDataModel dataModel   = getDataModel();
            long       preferring1 = dataModel.GetNumUsersWithPreferenceFor(itemID1);
            long       numUsers    = dataModel.GetNumUsers();

            return(doItemSimilarity(itemID1, itemID2, preferring1, numUsers));
        }
Exemple #6
0
        private double doItemSimilarity(long itemID1, long itemID2, long preferring1, long numUsers)
        {
            IDataModel dataModel       = getDataModel();
            long       preferring1and2 = dataModel.GetNumUsersWithPreferenceFor(itemID1, itemID2);

            if (preferring1and2 == 0)
            {
                return(Double.NaN);
            }
            long   preferring2   = dataModel.GetNumUsersWithPreferenceFor(itemID2);
            double logLikelihood =
                LogLikelihood.logLikelihoodRatio(preferring1and2,
                                                 preferring2 - preferring1and2,
                                                 preferring1 - preferring1and2,
                                                 numUsers - preferring1 - preferring2 + preferring1and2);

            return(1.0 - 1.0 / (1.0 + logLikelihood));
        }
Exemple #7
0
        public virtual int GetNumUsersWithPreferenceFor(long itemID)
        {
            if (tempPrefs == null)
            {
                return(_delegate.GetNumUsersWithPreferenceFor(itemID));
            }
            bool found = false;

            for (int i = 0; i < tempPrefs.Length(); i++)
            {
                if (tempPrefs.GetItemID(i) == itemID)
                {
                    found = true;
                    break;
                }
            }
            return(_delegate.GetNumUsersWithPreferenceFor(itemID) + (found ? 1 : 0));
        }
Exemple #8
0
        public override double[] ItemSimilarities(long itemID1, long[] itemID2s)
        {
            IDataModel dataModel   = getDataModel();
            long       preferring1 = dataModel.GetNumUsersWithPreferenceFor(itemID1);
            long       numUsers    = dataModel.GetNumUsers();
            int        length      = itemID2s.Length;

            double[] result = new double[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = doItemSimilarity(itemID1, itemID2s[i], preferring1, numUsers);
            }
            return(result);
        }
 public override int GetNumUsersWithPreferenceFor(long itemID)
 {
     return(_delegate.GetNumUsersWithPreferenceFor(itemID));
 }