Ejemplo n.º 1
0
        public void testPreferenceShufflerWithSyntheticData()
        {
            setUpSyntheticData();

            ParallelSGDFactorizer.PreferenceShuffler shuffler = new ParallelSGDFactorizer.PreferenceShuffler(dataModel);
            shuffler.shuffle();
            shuffler.stage();

            FastByIDMap <FastByIDMap <bool?> > checkedLst = new FastByIDMap <FastByIDMap <bool?> >();

            for (int i = 0; i < shuffler.size(); i++)
            {
                IPreference pref = shuffler.get(i);

                float?value = dataModel.GetPreferenceValue(pref.GetUserID(), pref.GetItemID());
                Assert.AreEqual(pref.GetValue(), value.Value, 0.0);
                if (!checkedLst.ContainsKey(pref.GetUserID()))
                {
                    checkedLst.Put(pref.GetUserID(), new FastByIDMap <bool?>());
                }

                Assert.IsNull(checkedLst.Get(pref.GetUserID()).Get(pref.GetItemID()));

                checkedLst.Get(pref.GetUserID()).Put(pref.GetItemID(), true);
            }

            var userIDs = dataModel.GetUserIDs();
            int index   = 0;

            while (userIDs.MoveNext())
            {
                long             userID = userIDs.Current;
                IPreferenceArray preferencesFromUser = dataModel.GetPreferencesFromUser(userID);
                foreach (IPreference preference in preferencesFromUser)
                {
                    Assert.True(checkedLst.Get(preference.GetUserID()).Get(preference.GetItemID()).Value);
                    index++;
                }
            }
            Assert.AreEqual(index, shuffler.size());
        }
        public void testPreferenceShufflerWithSyntheticData()
        {
            setUpSyntheticData();

            ParallelSGDFactorizer.PreferenceShuffler shuffler = new ParallelSGDFactorizer.PreferenceShuffler(dataModel);
            shuffler.shuffle();
            shuffler.stage();

            FastByIDMap<FastByIDMap<bool?>> checkedLst = new FastByIDMap<FastByIDMap<bool?>>();

            for (int i = 0; i < shuffler.size(); i++) {
              IPreference pref=shuffler.get(i);

              float? value = dataModel.GetPreferenceValue(pref.GetUserID(), pref.GetItemID());
              Assert.AreEqual(pref.GetValue(), value.Value, 0.0);
              if (!checkedLst.ContainsKey(pref.GetUserID())) {
            checkedLst.Put(pref.GetUserID(), new FastByIDMap<bool?>());
              }

              Assert.IsNull(checkedLst.Get(pref.GetUserID()).Get(pref.GetItemID()));

              checkedLst.Get(pref.GetUserID()).Put(pref.GetItemID(), true);
            }

            var userIDs = dataModel.GetUserIDs();
            int index=0;
            while (userIDs.MoveNext()) {
              long userID = userIDs.Current;
              IPreferenceArray preferencesFromUser = dataModel.GetPreferencesFromUser(userID);
              foreach (IPreference preference in preferencesFromUser) {
            Assert.True(checkedLst.Get(preference.GetUserID()).Get(preference.GetItemID()).Value);
            index++;
              }
            }
            Assert.AreEqual(index, shuffler.size());
        }