public void testStrategy() { FastIDSet allItemIDs = new FastIDSet(); allItemIDs.AddAll(new long[] { 1L, 2L, 3L }); FastIDSet preferredItemIDs = new FastIDSet(1); preferredItemIDs.Add(2L); var dataModelMock = new DynamicMock( typeof( IDataModel )); dataModelMock.ExpectAndReturn("GetNumItems", 3); dataModelMock.ExpectAndReturn("GetItemIDs", allItemIDs.GetEnumerator()); IPreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray( new List<IPreference>() { new GenericPreference(123L, 2L, 1.0f) } ); ICandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy(); //EasyMock.replay(dataModel); FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance); Assert.AreEqual(2, candidateItems.Count() ); Assert.True(candidateItems.Contains(1L)); Assert.True(candidateItems.Contains(3L)); dataModelMock.Verify(); //EasyMock.verify(dataModel); }
public void testStrategy() { FastIDSet allItemIDs = new FastIDSet(); allItemIDs.AddAll(new long[] { 1L, 2L, 3L }); FastIDSet preferredItemIDs = new FastIDSet(1); preferredItemIDs.Add(2L); var dataModelMock = new DynamicMock(typeof(IDataModel)); dataModelMock.ExpectAndReturn("GetNumItems", 3); dataModelMock.ExpectAndReturn("GetItemIDs", allItemIDs.GetEnumerator()); IPreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray(new List <IPreference>() { new GenericPreference(123L, 2L, 1.0f) }); ICandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy(); //EasyMock.replay(dataModel); FastIDSet candidateItems = strategy.GetCandidateItems(123L, prefArrayOfUser123, (IDataModel)dataModelMock.MockInstance); Assert.AreEqual(2, candidateItems.Count()); Assert.True(candidateItems.Contains(1L)); Assert.True(candidateItems.Contains(3L)); dataModelMock.Verify(); //EasyMock.verify(dataModel); }
protected override FastIDSet doGetCandidateItems(long[] preferredItemIDs, IDataModel dataModel) { FastIDSet candidateItemIDs = new FastIDSet(); foreach (long itemID in preferredItemIDs) { candidateItemIDs.AddAll(similarity.AllSimilarItemIDs(itemID)); } candidateItemIDs.RemoveAll(preferredItemIDs); return candidateItemIDs; }
protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) { IDataModel dataModel = GetDataModel(); FastIDSet possibleItemIDs = new FastIDSet(); foreach (long userID in theNeighborhood) { possibleItemIDs.AddAll(dataModel.GetItemIDsFromUser(userID)); } possibleItemIDs.RemoveAll(dataModel.GetItemIDsFromUser(theUserID)); return possibleItemIDs; }
protected override FastIDSet doGetCandidateItems(long[] preferredItemIDs, IDataModel dataModel) { FastIDSet candidateItemIDs = new FastIDSet(); foreach (long itemID in preferredItemIDs) { candidateItemIDs.AddAll(similarity.AllSimilarItemIDs(itemID)); } candidateItemIDs.RemoveAll(preferredItemIDs); return(candidateItemIDs); }
protected override FastIDSet doGetCandidateItems(long[] preferredItemIDs, IDataModel dataModel) { FastIDSet possibleItemsIDs = new FastIDSet(); foreach (long itemID in preferredItemIDs) { IPreferenceArray itemPreferences = dataModel.GetPreferencesForItem(itemID); int numUsersPreferringItem = itemPreferences.Length(); for (int index = 0; index < numUsersPreferringItem; index++) { possibleItemsIDs.AddAll(dataModel.GetItemIDsFromUser(itemPreferences.GetUserID(index))); } } possibleItemsIDs.RemoveAll(preferredItemIDs); return possibleItemsIDs; }
protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) { IDataModel dataModel = GetDataModel(); FastIDSet possibleItemIDs = new FastIDSet(); foreach (long userID in theNeighborhood) { possibleItemIDs.AddAll(dataModel.GetItemIDsFromUser(userID)); } possibleItemIDs.RemoveAll(dataModel.GetItemIDsFromUser(theUserID)); return(possibleItemIDs); }
private void addSomeOf(FastIDSet possibleItemIDs, FastIDSet itemIDs) { if (itemIDs.Count() > maxItemsPerUser) { var it = new SamplinglongPrimitiveIterator(itemIDs.GetEnumerator(), (double)maxItemsPerUser / itemIDs.Count()); while (it.MoveNext()) { possibleItemIDs.Add(it.Current); } } else { possibleItemIDs.AddAll(itemIDs); } }
protected override FastIDSet doGetCandidateItems(long[] preferredItemIDs, IDataModel dataModel) { FastIDSet possibleItemsIDs = new FastIDSet(); foreach (long itemID in preferredItemIDs) { IPreferenceArray itemPreferences = dataModel.GetPreferencesForItem(itemID); int numUsersPreferringItem = itemPreferences.Length(); for (int index = 0; index < numUsersPreferringItem; index++) { possibleItemsIDs.AddAll(dataModel.GetItemIDsFromUser(itemPreferences.GetUserID(index))); } } possibleItemsIDs.RemoveAll(preferredItemIDs); return(possibleItemsIDs); }
/// <p> /// Creates a new {@link GenericDataModel} from the given users (and their preferences). This /// {@link DataModel} retains all this information in memory and is effectively immutable. /// </p> /// /// @param userData users to include /// @param timestamps optionally, provided timestamps of preferences as milliseconds since the epoch. /// User IDs are mapped to maps of item IDs to long timestamps. public GenericBooleanPrefDataModel(FastByIDMap <FastIDSet> userData, FastByIDMap <FastByIDMap <DateTime?> > timestamps) { //Preconditions.checkArgument(userData != null, "userData is null"); this.preferenceFromUsers = userData; this.preferenceForItems = new FastByIDMap <FastIDSet>(); FastIDSet itemIDSet = new FastIDSet(); foreach (var entry in preferenceFromUsers.EntrySet()) { long userID = entry.Key; FastIDSet itemIDs1 = entry.Value; itemIDSet.AddAll(itemIDs1); var it = itemIDs1.GetEnumerator(); while (it.MoveNext()) { long itemID = it.Current; FastIDSet userIDs1 = preferenceForItems.Get(itemID); if (userIDs1 == null) { userIDs1 = new FastIDSet(2); preferenceForItems.Put(itemID, userIDs1); } userIDs1.Add(userID); } } this.itemIDs = itemIDSet.ToArray(); itemIDSet = null; // Might help GC -- this is big Array.Sort(itemIDs); this.userIDs = new long[userData.Count()]; int i = 0; var it1 = userData.Keys.GetEnumerator(); while (it1.MoveNext()) { userIDs[i++] = it1.Current; } Array.Sort(userIDs); this.timestamps = timestamps; }
/// <p> /// Creates a new {@link GenericDataModel} from the given users (and their preferences). This /// {@link DataModel} retains all this information in memory and is effectively immutable. /// </p> /// /// @param userData users to include /// @param timestamps optionally, provided timestamps of preferences as milliseconds since the epoch. /// User IDs are mapped to maps of item IDs to long timestamps. public GenericBooleanPrefDataModel(FastByIDMap<FastIDSet> userData, FastByIDMap<FastByIDMap<DateTime?>> timestamps) { //Preconditions.checkArgument(userData != null, "userData is null"); this.preferenceFromUsers = userData; this.preferenceForItems = new FastByIDMap<FastIDSet>(); FastIDSet itemIDSet = new FastIDSet(); foreach (var entry in preferenceFromUsers.EntrySet()) { long userID = entry.Key; FastIDSet itemIDs1 = entry.Value; itemIDSet.AddAll(itemIDs1); var it = itemIDs1.GetEnumerator(); while (it.MoveNext()) { long itemID = it.Current; FastIDSet userIDs1 = preferenceForItems.Get(itemID); if (userIDs1 == null) { userIDs1 = new FastIDSet(2); preferenceForItems.Put(itemID, userIDs1); } userIDs1.Add(userID); } } this.itemIDs = itemIDSet.ToArray(); itemIDSet = null; // Might help GC -- this is big Array.Sort(itemIDs); this.userIDs = new long[userData.Count()]; int i = 0; var it1 = userData.Keys.GetEnumerator(); while (it1.MoveNext()) { userIDs[i++] = it1.Current; } Array.Sort(userIDs); this.timestamps = timestamps; }
private void addSomeOf(FastIDSet possibleItemIDs, FastIDSet itemIDs) { if (itemIDs.Count() > maxItemsPerUser) { var it = new SamplinglongPrimitiveIterator(itemIDs.GetEnumerator(), (double) maxItemsPerUser / itemIDs.Count() ); while (it.MoveNext()) { possibleItemIDs.Add(it.Current); } } else { possibleItemIDs.AddAll(itemIDs); } }