/** * Find the median of an array of type integer. */ public static int median(int[] a) { int k = a.length / 2; return select(a, k); }
/** * Find the third quantile (p = 3/4) of an array of type float. */ public static float q3(float[] a) { int k = 3 * a.length / 4; return select(a, k); }
/** * Find the first quantile (p = 1/4) of an array of type double. */ public static double q1(double[] a) { int k = a.length / 4; return select(a, k); }
/** * Find the first quantile (p = 1/4) of an array of type double. */ public static <T extends Comparable<? super T>> T q1(T[] a) { int k = a.length / 4; return select(a, k); }
/** * Find the median of an array of type double. */ public static double median(double[] a) { int k = a.length / 2; return select(a, k); }
/** * Find the third quantile (p = 3/4) of an array of type integer. */ public static int q3(int[] a) { int k = 3 * a.length / 4; return select(a, k); }
/** * Find the third quantile (p = 3/4) of an array of type double. */ public static <T extends Comparable<? super T>> T q3(T[] a) { int k = 3 * a.length / 4; return select(a, k); } }
/** * Find the median of an array of type float. */ public static float median(float[] a) { int k = a.length / 2; return select(a, k); }
/** * Find the first quantile (p = 1/4) of an array of type integer. */ public static int q1(int[] a) { int k = a.length / 4; return select(a, k); }
/** * Find the third quantile (p = 3/4) of an array of type double. */ public static double q3(double[] a) { int k = 3 * a.length / 4; return select(a, k); }
/** * Find the median of an array of type double. */ public static <T extends Comparable<? super T>> T median(T[] a) { int k = a.length / 2; return select(a, k); }
/** * Find the first quantile (p = 1/4) of an array of type float. */ public static float q1(float[] a) { int k = a.length / 4; return select(a, k); }
@Override public void learn(Attribute[] attributes, double[][] data) { int n = data.length; int p = data[0].length; int i1 = (int) Math.round(lower * n); int i2 = (int) Math.round(upper * n); if (i2 == n) { i2 = n - 1; } lo = new double[p]; hi = new double[p]; double[] x = new double[n]; for (int j = 0; j < p; j++) { if (attributes[j].getType() != Attribute.Type.NUMERIC) { lo[j] = Double.NaN; } else { for (int i = 0; i < n; i++) { x[i] = data[i][j]; } lo[j] = QuickSelect.select(x, i1); hi[j] = QuickSelect.select(x, i2) - lo[j]; if (Math.isZero(hi[j])) { throw new IllegalArgumentException("Attribute " + j + " has constant values in the given range."); } } } }
/** * Constructor. */ public HuberNodeOutput(double[] residual, double[] response, double alpha) { this.residual = residual; this.response = response; this.alpha = alpha; int n = residual.length; for (int i = 0; i < n; i++) { response[i] = Math.abs(residual[i]); } delta = QuickSelect.select(response, (int) (n * alpha)); for (int i = 0; i < n; i++) { if (Math.abs(residual[i]) <= delta) { response[i] = residual[i]; } else { response[i] = delta * Math.signum(residual[i]); } } }