BasicStats { public static double stdDev(Path input, Path output, Configuration baseConf) throws IOException, InterruptedException, ClassNotFoundException { return Math.sqrt(variance(input, output, baseConf)); } private  BasicStats(); static double variance(Path input, Path output,
                                Configuration baseConf); static double varianceForGivenMean(Path input, Path output, double mean,
                                Configuration baseConf); static double stdDev(Path input, Path output,
                              Configuration baseConf); static double stdDevForGivenMean(Path input, Path output, double mean,
                              Configuration baseConf);  }
@Test public void testStdDev() throws Exception { Path input = getTestTempFilePath("stdDev/counts.file"); Path output = getTestTempFilePath("stdDev/output.file"); produceTestData(input); double v = BasicStats.stdDev(input, output, conf); assertEquals(1.56, v, 0.01); }
@Test public void testStdDev2() throws Exception { Path input = getTestTempFilePath("stdDev/counts.file"); Path output = getTestTempFilePath("stdDev/output.file"); FileSystem fs = FileSystem.get(input.toUri(), conf); SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, input, IntWritable.class, DoubleWritable.class); Random random = RandomUtils.getRandom(); Normal normal = new Normal(5, 3, random); for (int i = 0; i < 1000000; i++) { writer.append(new IntWritable(i), new DoubleWritable((long) normal.nextInt())); } writer.close(); double v = BasicStats.stdDev(input, output, conf); assertEquals(3, v, 0.02); }