StatUtils { public static double[] normalize(final double[] sample) { DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < sample.length; i++) { stats.addValue(sample[i]); } double mean = stats.getMean(); double standardDeviation = stats.getStandardDeviation(); double[] standardizedSample = new double[sample.length]; for (int i = 0; i < sample.length; i++) { standardizedSample[i] = (sample[i] - mean) / standardDeviation; } return standardizedSample; } private  StatUtils(); static double sum(final double[] values); static double sum(final double[] values, final int begin,
            final int length); static double sumSq(final double[] values); static double sumSq(final double[] values, final int begin,
            final int length); static double product(final double[] values); static double product(final double[] values, final int begin,
            final int length); static double sumLog(final double[] values); static double sumLog(final double[] values, final int begin,
            final int length); static double mean(final double[] values); static double mean(final double[] values, final int begin,
            final int length); static double geometricMean(final double[] values); static double geometricMean(final double[] values, final int begin,
            final int length); static double variance(final double[] values); static double variance(final double[] values, final int begin,
            final int length); static double variance(final double[] values, final double mean,
            final int begin, final int length); static double variance(final double[] values, final double mean); static double populationVariance(final double[] values); static double populationVariance(final double[] values, final int begin,
            final int length); static double populationVariance(final double[] values, final double mean,
            final int begin, final int length); static double populationVariance(final double[] values, final double mean); static double max(final double[] values); static double max(final double[] values, final int begin,
            final int length); static double min(final double[] values); static double min(final double[] values, final int begin,
            final int length); static double percentile(final double[] values, final double p); static double percentile(final double[] values, final int begin,
            final int length, final double p); static double sumDifference(final double[] sample1, final double[] sample2); static double meanDifference(final double[] sample1, final double[] sample2); static double varianceDifference(final double[] sample1,
            final double[] sample2, double meanDifference); static double[] normalize(final double[] sample); static double[] mode(double[] sample); static double[] mode(double[] sample, final int begin, final int length);  }
@Test public void testNormalize1() { double sample[] = { 50, 100 }; double expectedSample[] = { -25 / FastMath.sqrt(1250), 25 / FastMath.sqrt(1250) }; double[] out = StatUtils.normalize(sample); for (int i = 0; i < out.length; i++) { Assert.assertTrue(Precision.equals(out[i], expectedSample[i], 1)); } }
@Test public void testNormalize2() { int length = 77; double sample[] = new double[length]; for (int i = 0; i < length; i++) { sample[i] = FastMath.random(); } double standardizedSample[] = StatUtils.normalize(sample); DescriptiveStatistics stats = new DescriptiveStatistics(); for (int i = 0; i < length; i++) { stats.addValue(standardizedSample[i]); } double distance = 1E-10; Assert.assertEquals(0.0, stats.getMean(), distance); Assert.assertEquals(1.0, stats.getStandardDeviation(), distance); }