コード例 #1
0
ファイル: GenericDataModel.cs プロジェクト: yrinleung/ntaste
        public GenericDataModel(FastByIDMap <PreferenceArray> userData, FastByIDMap <FastByIDMap <DateTime?> > timestamps)
        {
            this.preferenceFromUsers = userData;
            FastByIDMap <List <Preference> > data = new FastByIDMap <List <Preference> >();
            FastIDSet set = new FastIDSet();
            int       num = 0;
            float     negativeInfinity = float.NegativeInfinity;
            float     positiveInfinity = float.PositiveInfinity;

            foreach (KeyValuePair <long, PreferenceArray> pair in this.preferenceFromUsers.entrySet())
            {
                PreferenceArray array = pair.Value;
                array.sortByItem();
                foreach (Preference preference in array)
                {
                    long key = preference.getItemID();
                    set.add(key);
                    List <Preference> list = data.get(key);
                    if (list == null)
                    {
                        list = new List <Preference>(2);
                        data.put(key, list);
                    }
                    list.Add(preference);
                    float num5 = preference.getValue();
                    if (num5 > negativeInfinity)
                    {
                        negativeInfinity = num5;
                    }
                    if (num5 < positiveInfinity)
                    {
                        positiveInfinity = num5;
                    }
                }
                if ((++num % 0x2710) == 0)
                {
                    log.info("Processed {0} users", new object[] { num });
                }
            }
            log.info("Processed {0} users", new object[] { num });
            this.setMinPreference(positiveInfinity);
            this.setMaxPreference(negativeInfinity);
            this.itemIDs = set.toArray();
            set          = null;
            Array.Sort <long>(this.itemIDs);
            this.preferenceForItems = toDataMap(data, false);
            foreach (KeyValuePair <long, PreferenceArray> pair in this.preferenceForItems.entrySet())
            {
                pair.Value.sortByUser();
            }
            this.userIDs = new long[userData.size()];
            int num6 = 0;

            foreach (long num7 in userData.Keys)
            {
                this.userIDs[num6++] = num7;
            }
            Array.Sort <long>(this.userIDs);
            this.timestamps = timestamps;
        }
コード例 #2
0
        public virtual long[] allSimilarItemIDs(long itemID)
        {
            FastIDSet          set        = new FastIDSet();
            IEnumerator <long> enumerator = this.dataModel.getItemIDs();

            while (enumerator.MoveNext())
            {
                long current = enumerator.Current;
                if (!double.IsNaN(this.itemSimilarity(itemID, current)))
                {
                    set.add(current);
                }
            }
            return(set.toArray());
        }
コード例 #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 GenericBooleanPrefDataModel(FastByIDMap <FastIDSet> userData, FastByIDMap <FastByIDMap <DateTime?> > timestamps)
        {
            this.preferenceFromUsers = userData;
            this.preferenceForItems  = new FastByIDMap <FastIDSet>();
            FastIDSet set = new FastIDSet();

            foreach (KeyValuePair <long, FastIDSet> pair in this.preferenceFromUsers.entrySet())
            {
                long      key = pair.Key;
                FastIDSet c   = pair.Value;
                set.addAll(c);
                IEnumerator <long> enumerator = c.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    long      current = enumerator.Current;
                    FastIDSet set3    = this.preferenceForItems.get(current);
                    if (set3 == null)
                    {
                        set3 = new FastIDSet(2);
                        this.preferenceForItems.put(current, set3);
                    }
                    set3.add(key);
                }
            }
            this.itemIDs = set.toArray();
            set          = null;
            Array.Sort <long>(this.itemIDs);
            this.userIDs = new long[userData.size()];
            int num3 = 0;
            IEnumerator <long> enumerator2 = userData.Keys.GetEnumerator();

            while (enumerator2.MoveNext())
            {
                this.userIDs[num3++] = enumerator2.Current;
            }
            Array.Sort <long>(this.userIDs);
            this.timestamps = timestamps;
        }
コード例 #5
0
        public long[] allSimilarItemIDs(long itemID)
        {
            FastIDSet set = this.similarItemIDsIndex.get(itemID);

            return((set != null) ? set.toArray() : NO_IDS);
        }