@Override
 double[] aggregate(double[] data) {
   double med = QuickSelect.median(data);
   double[] devs = new double[data.length];
   for (int i = 0; i < data.length; i++) {
     devs[i] = Math.abs(data[i] - med);
   }
   double mad = QuickSelect.median(devs);
   return new double[] {med, mad};
 }
 @Override
 double[] aggregate(double[] data) {
   double med = QuickSelect.median(data);
   double[] devs = new double[data.length];
   double min = med, max = med;
   for (int i = 0; i < data.length; i++) {
     double v = data[i];
     min = (v < min) ? v : min;
     max = (v > max) ? v : max;
     devs[i] = Math.abs(v - med);
   }
   double mad = QuickSelect.median(devs);
   return new double[] {med, mad, min, max};
 }
Exemplo n.º 3
0
 @Override
 public <A> D estimate(A data, NumberArrayAdapter<?, A> adapter) {
   // TODO: detect pre-sorted data?
   final int len = adapter.size(data);
   double min = AbstractLogMOMEstimator.min(data, adapter, 0., 1e-10);
   // Modifiable copy:
   double[] x = new double[len];
   for (int i = 0; i < len; i++) {
     final double val = adapter.getDouble(data, i) - min;
     x[i] = val > 0. ? Math.log(val) : Double.NEGATIVE_INFINITY;
     if (Double.isNaN(x[i])) {
       throw new ArithmeticException("NaN value.");
     }
   }
   double median = QuickSelect.median(x);
   double mad = computeMAD(x, median);
   return estimateFromLogMedianMAD(median, mad, min);
 }
Exemplo n.º 4
0
 /**
  * Compute the median absolute deviation from median.
  *
  * @param x Input data <b>will be modified</b>
  * @param median Median value.
  * @return Median absolute deviation from median.
  */
 public static double computeMAD(double[] x, double median) {
   // Compute deviations:
   for (int i = 0; i < x.length; i++) {
     x[i] = Math.abs(x[i] - median);
   }
   double mad = QuickSelect.median(x);
   // Fallback if we have more than 50% ties to next largest.
   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; // Maybe all constant. No real value.
     }
   }
   return mad;
 }
 @Override
 double[] aggregate(double[] data) {
   double med = QuickSelect.median(data);
   return new double[] {med};
 }