/** * Given a two d array of doubles, create a table. * * @param data * @return */ public static ExampleTable getTable( double[][] data, String[] inputNames, String[] outputNames, int[] inputs, int[] outputs, int count) { Column[] cols = new Column[data.length]; int index = 0; for (int i = 0; i < inputs.length; i++, index++) { if (data.length != count) { double[] tmp = new double[count]; System.arraycopy(data[index], 0, tmp, 0, count); data[index] = tmp; } cols[index] = new DoubleColumn(data[index]); cols[index].setLabel(inputNames[i]); } for (int i = 0; i < outputs.length; i++, index++) { if (data.length != count) { double[] tmp = new double[count]; System.arraycopy(data[index], 0, tmp, 0, count); data[index] = tmp; } cols[index] = new DoubleColumn(data[index]); cols[index].setLabel(outputNames[i]); } MutableTable mt = new MutableTableImpl(cols); ExampleTable et = mt.toExampleTable(); et.setInputFeatures(inputs); et.setOutputFeatures(outputs); return et; }
/** * Rearrange the subarray A[p..r] in place. * * @param A the array to rearrange * @param p the beginning index * @param r the ending index * @param t the Table to swap rows for * @return the partition point */ private int partition(long[] A, int p, int r, MutableTable t) { long x = A[p]; boolean xMissing = this.isValueMissing(p); int i = p - 1; int j = r + 1; while (true) { if (xMissing) { j--; do { i++; } while (!this.isValueMissing(i)); } else { do { j--; } while (this.isValueMissing(j) || (A[j] > x)); do { i++; } while (!this.isValueMissing(i) && (A[i] < x)); } if (i < j) { if (t == null) this.swapRows(i, j); else t.swapRows(i, j); } else return j; } }