KDTree { public RealVector[] getMinMaxDistanceVectors(Datum queryDatum) { double[] minDifferences = new double[k]; double[] maxDifferences = new double[k]; RealVector metrics = queryDatum.metrics(); for (int i=0; i<k; i++) { double deltaLo = metrics.getEntry(i) - this.boundaries[i][0]; double deltaHi = this.boundaries[i][1] - metrics.getEntry(i); double minD = Math.abs(deltaLo); double maxD = Math.abs(deltaHi); if (minD < maxD) { minDifferences[i] = minD; maxDifferences[i] = maxD; } else { minDifferences[i] = maxD; maxDifferences[i] = minD; } if (deltaLo > 0 && deltaHi > 0) { minDifferences[i] = 0; } } RealVector[] rtn = new RealVector[2]; rtn[0] = new ArrayRealVector(minDifferences); rtn[1] = new ArrayRealVector(maxDifferences); return rtn; } KDTree(List<Datum> data, int leafCapacity); RealVector[] getMinMaxDistanceVectors(Datum queryDatum); double[] estimateL2DistanceSquared(Datum queryDatum); boolean isInsideBoundaries(Datum queryDatum); List<Datum> getItems(); RealVector getMean(); double[][] getBoundaries(); KDTree getLoChild(); KDTree getHiChild(); boolean isLeaf(); int getnBelow(); int getSplitDimension(); String toString(int indent); String toString();  }
@Test public void testEstimateDistanceVectors() throws Exception { this.setUpVerySimpleCsv(); KDTree node; node = new KDTree(data, 2); double[] zeroArray = {0, 0, 0}; for (Datum datum : data) { assertArrayEquals(zeroArray, node.getMinMaxDistanceVectors(datum)[0].toArray(), 1e-7); } double[] farAwayPoint = {-10, 5, 21}; Datum datum = new Datum(new ArrayList<>(), new ArrayRealVector(farAwayPoint)); double[] minArray = {11, 0, 12}; double[] maxArray = {21, 4, 20}; RealVector[] minMaxVectors= node.getMinMaxDistanceVectors(datum); assertArrayEquals(minArray, minMaxVectors[0].toArray(), 1e-7); assertArrayEquals(maxArray, minMaxVectors[1].toArray(), 1e-7); }