public double getSimilarity(FastIDSet cluster1, FastIDSet cluster2)
        {
            if (cluster1.isEmpty() || cluster2.isEmpty())
            {
                return(Double.NaN);
            }
            double leastSimilarity = Double.PositiveInfinity;
            var    someUsers       = SamplingLongPrimitiveIterator.maybeWrapIterator(cluster1.GetEnumerator(), samplingRate);

            while (someUsers.MoveNext())
            {
                long userID1 = someUsers.Current;
                var  it2     = cluster2.GetEnumerator();
                while (it2.MoveNext())
                {
                    double theSimilarity = similarity.userSimilarity(userID1, it2.Current);
                    if (theSimilarity < leastSimilarity)
                    {
                        leastSimilarity = theSimilarity;
                    }
                }
            }
            // We skipped everything? well, at least try comparing the first Users to get some value
            if (leastSimilarity == Double.PositiveInfinity)
            {
                return(similarity.userSimilarity(cluster1.GetEnumerator().Current, cluster2.GetEnumerator().Current));
            }
            return(leastSimilarity);
        }
Exemplo n.º 2
0
        protected override float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID)
        {
            if (theNeighborhood.Length == 0)
            {
                return(float.NaN);
            }
            DataModel      model      = this.getDataModel();
            UserSimilarity similarity = base.getSimilarity();
            float          num        = 0f;
            bool           flag       = false;

            foreach (long num2 in theNeighborhood)
            {
                if ((num2 != theUserID) && model.getPreferenceValue(num2, itemID).HasValue)
                {
                    flag = true;
                    num += (float)similarity.userSimilarity(theUserID, num2);
                }
            }
            return(flag ? num : float.NaN);
        }
Exemplo n.º 3
0
        public override long[] getUserNeighborhood(long userID)
        {
            DataModel          model      = this.getDataModel();
            FastIDSet          set        = new FastIDSet();
            IEnumerator <long> enumerator = SamplingLongPrimitiveIterator.maybeWrapIterator(model.getUserIDs(), this.getSamplingRate());
            UserSimilarity     similarity = this.getUserSimilarity();

            while (enumerator.MoveNext())
            {
                long current = enumerator.Current;
                if (userID != current)
                {
                    double d = similarity.userSimilarity(userID, current);
                    if (!(double.IsNaN(d) || (d < this.threshold)))
                    {
                        set.add(current);
                    }
                }
            }
            return(set.toArray());
        }