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);
        }
예제 #2
0
        public override long[] getUserNeighborhood(long userID)
        {
            DataModel model = this.getDataModel();

            TopItems.Estimator <long> estimator  = new Estimator(this.getUserSimilarity(), userID, this.minSimilarity);
            IEnumerator <long>        allUserIDs = SamplingLongPrimitiveIterator.maybeWrapIterator(model.getUserIDs(), this.getSamplingRate());

            return(TopItems.getTopUsers(this.n, allUserIDs, null, estimator));
        }
예제 #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());
        }
예제 #4
0
        public static LoadStatistics runLoad(Recommender recommender, int howMany)
        {
            DataModel          model        = recommender.getDataModel();
            int                num          = model.getNumUsers();
            double             samplingRate = 1000.0 / ((double)num);
            IEnumerator <long> enumerator   = SamplingLongPrimitiveIterator.maybeWrapIterator(model.getUserIDs(), samplingRate);

            if (enumerator.MoveNext())
            {
                recommender.recommend(enumerator.Current, howMany);
            }
            List <Action> callables = new List <Action>();

            while (enumerator.MoveNext())
            {
                callables.Add(new Action(new LoadCallable(recommender, enumerator.Current).call));
            }
            AtomicInteger           noEstimateCounter = new AtomicInteger();
            RunningAverageAndStdDev timing            = new FullRunningAverageAndStdDev();

            AbstractDifferenceRecommenderEvaluator.execute(callables, noEstimateCounter, timing);
            return(new LoadStatistics(timing));
        }