SampleMedianAbsoluteDeviationCalculator extends Function1D<double[], Double> { @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x"); final int n = x.length; Validate.isTrue(n > 1, "Need at least two data points to calculate MAD"); final double median = MEDIAN.evaluate(x); final double[] diff = new double[n]; for (int i = 0; i < n; i++) { diff[i] = Math.abs(x[i] - median); } return MEDIAN.evaluate(diff); }  @Override Double evaluate(final double[] x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { MAD_CALC.evaluate((double[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInsufficientData() { MAD_CALC.evaluate(new double[] {3.}); }
@Test public void test() { assertEquals(STD_CALC.evaluate(NORMAL_DATA), MAD_CALC.evaluate(NORMAL_DATA) / .6745, EPS); }