public PrefAndSimilarityColumnWritable(float prefValue, Vector similarityColumn) { set(prefValue, similarityColumn); }
private void reduceBooleanData(VarLongWritable userID, Iterable<PrefAndSimilarityColumnWritable> values, Context context) throws IOException, InterruptedException { /* having boolean data, each estimated preference can only be 1, * however we can't use this to rank the recommended items, * so we use the sum of similarities for that. */ Iterator<PrefAndSimilarityColumnWritable> columns = values.iterator(); Vector predictions = columns.next().getSimilarityColumn(); while (columns.hasNext()) { predictions.assign(columns.next().getSimilarityColumn(), Functions.PLUS); } writeRecommendedItems(userID, predictions, context); }
Vector simColumn = prefAndSimilarityColumn.getSimilarityColumn(); float prefValue = prefAndSimilarityColumn.getPrefValue();
/** * tests {@link PartialMultiplyMapper} */ @Test public void testPartialMultiplyMapper() throws Exception { Vector similarityColumn = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumn.set(3, 0.5); similarityColumn.set(7, 0.8); Mapper<VarIntWritable,VectorAndPrefsWritable,VarLongWritable,PrefAndSimilarityColumnWritable>.Context context = EasyMock.createMock(Mapper.Context.class); PrefAndSimilarityColumnWritable one = new PrefAndSimilarityColumnWritable(); PrefAndSimilarityColumnWritable two = new PrefAndSimilarityColumnWritable(); one.set(1.0f, similarityColumn); two.set(3.0f, similarityColumn); context.write(EasyMock.eq(new VarLongWritable(123L)), EasyMock.eq(one)); context.write(EasyMock.eq(new VarLongWritable(456L)), EasyMock.eq(two)); EasyMock.replay(context); VectorAndPrefsWritable vectorAndPrefs = new VectorAndPrefsWritable(similarityColumn, Arrays.asList(123L, 456L), Arrays.asList(1.0f, 3.0f)); new PartialMultiplyMapper().map(new VarIntWritable(1), vectorAndPrefs, context); EasyMock.verify(context); }
/** * tests {@link AggregateAndRecommendReducer} with a limit on the recommendations per user */ @Test public void testAggregateAndRecommendReducerLimitNumberOfRecommendations() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); similarityColumnOne.set(2, 0.5); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 1); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
Vector simColumn = prefAndSimilarityColumn.getSimilarityColumn(); float prefValue = prefAndSimilarityColumn.getPrefValue();
/** * tests {@link AggregateAndRecommendReducer} */ @Test public void testAggregateAndRecommendReducerExcludeRecommendationsBasedOnOneItem() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 3); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
Vector simColumn = prefAndSimilarityColumn.getSimilarityColumn(); float prefValue = prefAndSimilarityColumn.getPrefValue();
public PrefAndSimilarityColumnWritable(float prefValue, Vector similarityColumn) { set(prefValue, similarityColumn); }
private void reduceBooleanData(VarLongWritable userID, Iterable<PrefAndSimilarityColumnWritable> values, Context context) throws IOException, InterruptedException { /* having boolean data, each estimated preference can only be 1, * however we can't use this to rank the recommended items, * so we use the sum of similarities for that. */ Iterator<PrefAndSimilarityColumnWritable> columns = values.iterator(); Vector predictions = columns.next().getSimilarityColumn(); while (columns.hasNext()) { predictions.assign(columns.next().getSimilarityColumn(), Functions.PLUS); } writeRecommendedItems(userID, predictions, context); }
/** * tests {@link AggregateAndRecommendReducer} */ @Test public void testAggregateAndRecommendReducer() throws Exception { Reducer<VarLongWritable,PrefAndSimilarityColumnWritable,VarLongWritable,RecommendedItemsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); context.write(EasyMock.eq(new VarLongWritable(123L)), recommendationsMatch(new MutableRecommendedItem(1L, 2.8f), new MutableRecommendedItem(2L, 2.0f))); EasyMock.replay(context); RandomAccessSparseVector similarityColumnOne = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnOne.set(1, 0.1); similarityColumnOne.set(2, 0.5); RandomAccessSparseVector similarityColumnTwo = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); similarityColumnTwo.set(1, 0.9); similarityColumnTwo.set(2, 0.5); List<PrefAndSimilarityColumnWritable> values = Arrays.asList( new PrefAndSimilarityColumnWritable(1.0f, similarityColumnOne), new PrefAndSimilarityColumnWritable(3.0f, similarityColumnTwo)); OpenIntLongHashMap indexItemIDMap = new OpenIntLongHashMap(); indexItemIDMap.put(1, 1L); indexItemIDMap.put(2, 2L); AggregateAndRecommendReducer reducer = new AggregateAndRecommendReducer(); setField(reducer, "indexItemIDMap", indexItemIDMap); setField(reducer, "recommendationsPerUser", 3); reducer.reduce(new VarLongWritable(123L), values, context); EasyMock.verify(context); }
public PrefAndSimilarityColumnWritable(float prefValue, Vector similarityColumn) { set(prefValue, similarityColumn); }
private void reduceBooleanData(VarLongWritable userID, Iterable<PrefAndSimilarityColumnWritable> values, Context context) throws IOException, InterruptedException { /* having boolean data, each estimated preference can only be 1, * however we can't use this to rank the recommended items, * so we use the sum of similarities for that. */ Iterator<PrefAndSimilarityColumnWritable> columns = values.iterator(); Vector predictions = columns.next().getSimilarityColumn(); while (columns.hasNext()) { predictions.assign(columns.next().getSimilarityColumn(), Functions.PLUS); } writeRecommendedItems(userID, predictions, context); }
@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }
@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }
@Override protected void map(VarIntWritable key, VectorAndPrefsWritable vectorAndPrefsWritable, Context context) throws IOException, InterruptedException { Vector similarityMatrixColumn = vectorAndPrefsWritable.getVector(); List<Long> userIDs = vectorAndPrefsWritable.getUserIDs(); List<Float> prefValues = vectorAndPrefsWritable.getValues(); for (int i = 0; i < userIDs.size(); i++) { long userID = userIDs.get(i); float prefValue = prefValues.get(i); if (!Float.isNaN(prefValue)) { prefAndSimilarityColumn.set(prefValue, similarityMatrixColumn); userIDWritable.set(userID); context.write(userIDWritable, prefAndSimilarityColumn); } } }