File inputFile = getTestTempFile("prefs.txt"); File outputDir = getTestTempDir("output"); outputDir.delete(); File similaritiesOutputDir = getTestTempDir("outputSimilarities"); similaritiesOutputDir.delete(); File tmpDir = getTestTempDir("tmp"); writeLines(inputFile, "1,1,5", "1,2,5", Configuration conf = getConfiguration(); conf.set("mapred.input.dir", inputFile.getAbsolutePath()); conf.set("mapred.output.dir", outputDir.getAbsolutePath()); Map<Long,List<RecommendedItem>> recommendations = readRecommendations(new File(outputDir, "part-r-00000")); assertEquals(4, recommendations.size()); assertNotNull(items); RecommendedItem item1 = items.get(0); assertEquals(1, items.size()); assertEquals(4L, item1.getItemID()); assertEquals(4.3, item1.getValue(), 0.05); assertEquals(1, items.size()); assertEquals(2L, item1.getItemID()); assertEquals(3.3, item1.getValue(), 0.05);
File inputFile = getTestTempFile("prefs.txt"); File userFile = getTestTempFile("users.txt"); File filterFile = getTestTempFile("filter.txt"); File outputDir = getTestTempDir("output"); outputDir.delete(); File tmpDir = getTestTempDir("tmp"); writeLines(inputFile, "1,1,5", "1,2,5", writeLines(userFile, "4"); writeLines(filterFile, "4,2"); Configuration conf = getConfiguration(); conf.set("mapred.input.dir", inputFile.getAbsolutePath()); conf.set("mapred.output.dir", outputDir.getAbsolutePath()); Map<Long,List<RecommendedItem>> recommendations = readRecommendations(new File(outputDir, "part-r-00000")); assertEquals(1, recommendations.size()); assertTrue(recommendations.containsKey(4L)); assertEquals(1, recommendations.get(4L).size()); assertEquals(3L, recommendedItem.getItemID()); assertEquals(3.5, recommendedItem.getValue(), 0.05);
/** * tests {@link UserVectorSplitterMapper} in the special case that the number of preferences to be considered * is less than the number of available preferences */ @Test public void testUserVectorSplitterMapperOnlySomePrefsConsidered() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatchesNaN(123L)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 1); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** * tests {@link UserVectorSplitterMapper} */ @Test public void testUserVectorSplitterMapper() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 10); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); EasyMock.verify(context); }
/** * tests {@link ToVectorAndPrefReducer} in the error case that two similarity column vectors a supplied for the same * item (which should never happen) */ @Test public void testToVectorAndPrefReducerExceptionOn2Vectors() throws Exception { Reducer<VarIntWritable,VectorOrPrefWritable,VarIntWritable,VectorAndPrefsWritable>.Context context = EasyMock.createMock(Reducer.Context.class); EasyMock.replay(context); Vector similarityColumn1 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); Vector similarityColumn2 = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); VectorOrPrefWritable similarities1 = new VectorOrPrefWritable(similarityColumn1); VectorOrPrefWritable similarities2 = new VectorOrPrefWritable(similarityColumn2); try { new ToVectorAndPrefReducer().reduce(new VarIntWritable(1), Arrays.asList(similarities1, similarities2), context); fail(); } catch (IllegalStateException e) { // good } EasyMock.verify(context); }
/** * tests {@link UserVectorSplitterMapper} in the special case that some userIDs shall be excluded */ @Test public void testUserVectorSplitterMapperUserExclusion() throws Exception { Mapper<VarLongWritable,VectorWritable, VarIntWritable,VectorOrPrefWritable>.Context context = EasyMock.createMock(Mapper.Context.class); context.write(EasyMock.eq(new VarIntWritable(34)), prefOfVectorOrPrefWritableMatches(123L, 0.5f)); context.write(EasyMock.eq(new VarIntWritable(56)), prefOfVectorOrPrefWritableMatches(123L, 0.7f)); EasyMock.replay(context); FastIDSet usersToRecommendFor = new FastIDSet(); usersToRecommendFor.add(123L); UserVectorSplitterMapper mapper = new UserVectorSplitterMapper(); setField(mapper, "maxPrefsPerUserConsidered", 10); setField(mapper, "usersToRecommendFor", usersToRecommendFor); RandomAccessSparseVector vector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100); vector.set(34, 0.5); vector.set(56, 0.7); mapper.map(new VarLongWritable(123L), new VectorWritable(vector), context); mapper.map(new VarLongWritable(456L), new VectorWritable(vector), context); EasyMock.verify(context); }
public void testCompleteJobBoolean() throws Exception { File inputFile = getTestTempFile("prefs.txt"); File outputDir = getTestTempDir("output"); outputDir.delete(); File tmpDir = getTestTempDir("tmp"); File usersFile = getTestTempFile("users.txt"); writeLines(usersFile, "3"); writeLines(inputFile, "1,1", "1,2", Configuration conf = getConfiguration(); conf.set("mapred.input.dir", inputFile.getAbsolutePath()); conf.set("mapred.output.dir", outputDir.getAbsolutePath()); "--usersFile", usersFile.getAbsolutePath() }); Map<Long,List<RecommendedItem>> recommendations = readRecommendations(new File(outputDir, "part-r-00000")); assertEquals(2, recommendedToCow.size()); assertEquals(1L, item1.getItemID()); assertEquals(3L, item2.getItemID()); assertEquals(3, item1.getValue(), 0.05); assertEquals(2, item2.getValue(), 0.05);