/** * Find the median of an array of type int. The input array will * be rearranged. */ public static int median(int[] a) { return QuickSelect.median(a); }
/** * Find the median of an array of type double. The input array will * be rearranged. */ public static double median(double[] a) { return QuickSelect.median(a); }
/** * Find the median of an array of type float. The input array will * be rearranged. */ public static float median(float[] a) { return QuickSelect.median(a); }
/** * Find the median of an array of type double. The input array will * be rearranged. */ public static <T extends Comparable<? super T>> T median(T[] a) { return QuickSelect.median(a); }
@Override public double calculate(int[] samples) { int n = 0; for (int s : samples) { if (s > 0) n++; } double[] r = new double[n]; for (int i = 0, j = 0; i < samples.length; i++) { if (samples[i] > 0) { r[j++] = residual[i]; } } return QuickSelect.median(r); } }
@Override public void learn(Attribute[] attributes, double[][] data) { int n = data.length; int p = data[0].length; mu = new double[p]; std = new double[p]; double[] x = new double[n]; for (int j = 0; j < p; j++) { if (attributes[j].getType() != Attribute.Type.NUMERIC) { mu[j] = Double.NaN; } else { for (int i = 0; i < n; i++) { x[i] = data[i][j]; } mu[j] = QuickSelect.median(x); std[j] = QuickSelect.q3(x) - QuickSelect.q1(x); if (Math.isZero(std[j])) { throw new IllegalArgumentException("Column " + j + " has constant values between Q1 and Q3."); } } } }
@Override public double calculate(int[] samples) { int n = 0; for (int s : samples) { if (s > 0) n++; } double[] res = new double[n]; for (int i = 0, j = 0; i < samples.length; i++) { if (samples[i] > 0) { res[j++] = residual[i]; } } double r = QuickSelect.median(res); double output = 0.0; for (int i = 0; i < samples.length; i++) { if (samples[i] > 0) { double d = residual[i] - r; output += Math.signum(d) * Math.min(delta, Math.abs(d)); } } output = r + output / n; return output; } }
output = new LADNodeOutput(residual); System.arraycopy(y, 0, residual, 0, n); b = QuickSelect.median(residual); response = new double[n]; for (int i = 0; i < n; i++) { response = new double[n]; System.arraycopy(y, 0, residual, 0, n); b = QuickSelect.median(residual); for (int i = 0; i < n; i++) { residual[i] = y[i] - b;