ParallelFactorizationEvaluator extends AbstractJob { @Override public int run(String[] args) throws Exception { addOption("pairs", "p", "path containing the test ratings, each line must be userID,itemID,rating", true); addOption("userFeatures", "u", "path to the user feature matrix", true); addOption("itemFeatures", "i", "path to the item feature matrix", true); addOutputOption(); Map<String,String> parsedArgs = parseArguments(args); if (parsedArgs == null) { return -1; } Path tempDir = new Path(parsedArgs.get("--tempDir")); Path predictions = new Path(tempDir, "predictions"); Path errors = new Path(tempDir, "errors"); ToolRunner.run(getConf(), new PredictionJob(), new String[] { "--output", predictions.toString(), "--pairs", parsedArgs.get("--pairs"), "--userFeatures", parsedArgs.get("--userFeatures"), "--itemFeatures", parsedArgs.get("--itemFeatures"), "--tempDir", tempDir.toString() }); Job estimationErrors = prepareJob(new Path(parsedArgs.get("--pairs") + ',' + predictions), errors, TextInputFormat.class, PairsWithRatingMapper.class, IntPairWritable.class, DoubleWritable.class, ErrorReducer.class, DoubleWritable.class, NullWritable.class, SequenceFileOutputFormat.class); estimationErrors.waitForCompletion(true); BufferedWriter writer = null; try { FileSystem fs = FileSystem.get(getOutputPath().toUri(), getConf()); FSDataOutputStream outputStream = fs.create(new Path(getOutputPath(), "rmse.txt")); double rmse = computeRmse(errors); writer = new BufferedWriter(new OutputStreamWriter(outputStream)); writer.write(String.valueOf(rmse)); } finally { IOUtils.quietClose(writer); } return 0; }  static void main(String[] args); @Override int run(String[] args);  }
@Test public void smallIntegration() throws Exception { File pairs = getTestTempFile("pairs.txt"); File userFeatures = getTestTempFile("userFeatures.seq"); File itemFeatures = getTestTempFile("itemFeatures.seq"); File tempDir = getTestTempDir("temp"); File outputDir = getTestTempDir("out"); outputDir.delete(); Configuration conf = new Configuration(); Path inputPath = new Path(pairs.getAbsolutePath()); FileSystem fs = FileSystem.get(inputPath.toUri(), conf); MathHelper.writeEntries(new double[][] { new double[] { 1.5, -2, 0.3 }, new double[] { -0.7, 2, 0.6 }, new double[] { -1, 2.5, 3 } }, fs, conf, new Path(userFeatures.getAbsolutePath())); MathHelper.writeEntries(new double [][] { new double[] { 2.3, 0.5, 0 }, new double[] { 4.7, -1, 0.2 }, new double[] { 0.6, 2, 1.3 } }, fs, conf, new Path(itemFeatures.getAbsolutePath())); writeLines(pairs, "0,0,3", "2,1,-7", "1,0,-2"); ParallelFactorizationEvaluator evaluator = new ParallelFactorizationEvaluator(); evaluator.setConf(conf); evaluator.run(new String[] { "--output", outputDir.getAbsolutePath(), "--pairs", pairs.getAbsolutePath(), "--userFeatures", userFeatures.getAbsolutePath(), "--itemFeatures", itemFeatures.getAbsolutePath(), "--tempDir", tempDir.getAbsolutePath() }); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(new File(outputDir, "rmse.txt"))); double rmse = Double.parseDouble(reader.readLine()); assertEquals(0.89342, rmse, EPSILON); } finally { IOUtils.quietClose(reader); } }