public static double computeMAD(double[] x,double median){
  for (int i=0; i < x.length; i++) {
    x[i]=Math.abs(x[i] - median);
  }
  double mad=QuickSelect.median(x);
  if (!(mad > 0.)) {
    double min=Double.POSITIVE_INFINITY;
    for (    double xi : x) {
      if (xi > 0. && xi < min) {
        min=xi;
      }
    }
    if (min < Double.POSITIVE_INFINITY) {
      mad=min;
    }
 else {
      mad=1.0;
    }
  }
  if (mad == Double.POSITIVE_INFINITY) {
    double max=0.;
    for (    double xi : x) {
      if (xi < Double.POSITIVE_INFINITY && xi > max) {
        max=xi;
      }
    }
    if (max < Double.POSITIVE_INFINITY) {
      mad=max;
    }
 else {
      mad=1.0;
    }
  }
  return mad;
}

public static double computeMAD ( double [ ] x , double median ) { for ( int i = 0 ; i < x . length ; i ++ ) { x [ i ] = Math . abs ( x [ i ] - median ) ; } double mad = QuickSelect . median ( x ) ; if ( ! ( mad > 0. ) ) { double min = Double . POSITIVE_INFINITY ; for ( double xi : x ) { if ( xi > 0. && xi < min ) { min = xi ; } } if ( min < Double . POSITIVE_INFINITY ) { mad = min ; } else { mad = 1.0 ; } } if ( mad == Double . POSITIVE_INFINITY ) { double max = 0. ; for ( double xi : x ) { if ( xi < Double . POSITIVE_INFINITY && xi > max ) { max = xi ; } } if ( max < Double . POSITIVE_INFINITY ) { mad = max ; } else { mad = 1.0 ; } } return mad ; }
compute the median absolute deviation from median .
