class 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);
  }

}