/** * 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 first quantile (p = 1/4) of an array of type float. The input array will * be rearranged. */ public static float q1(float[] a) { return QuickSelect.q1(a); }
/** * Find the third quantile (p = 3/4) of an array of type double. The input array will * be rearranged. */ public static <T extends Comparable<? super T>> T q3(T[] a) { return QuickSelect.q3(a); }
@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."); } } } }
/** * 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 median of an array of type double. */ public static double median(double[] a) { int k = a.length / 2; return select(a, k); }
/** * 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); }
/** * Find the third quantile (p = 3/4) of an array of type double. The input array will * be rearranged. */ public static double q3(double[] a) { return QuickSelect.q3(a); }
/** * Find the first quantile (p = 1/4) of an array of type int. The input array will * be rearranged. */ public static int q1(int[] a) { return QuickSelect.q1(a); }
/** * 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 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 third quantile (p = 3/4) of an array of type float. The input array will * be rearranged. */ public static float q3(float[] a) { return QuickSelect.q3(a); }
/** * Find the first quantile (p = 1/4) of an array of type double. The input array will * be rearranged. */ public static double q1(double[] a) { return QuickSelect.q1(a); }
/** * 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 double. The input array will * be rearranged. */ public static double median(double[] a) { return QuickSelect.median(a); }
/** * Find the third quantile (p = 3/4) of an array of type int. The input array will * be rearranged. */ public static int q3(int[] a) { return QuickSelect.q3(a); }
/** * Find the first quantile (p = 1/4) of an array of type double. The input array will * be rearranged. */ public static <T extends Comparable<? super T>> T q1(T[] a) { return QuickSelect.q1(a); }
/** * Find the median of an array of type float. */ public static float median(float[] a) { int k = a.length / 2; return select(a, k); }
@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); } }