in Java/core/src/main/java/com/amazon/randomcutforest/tree/RandomCutTree.java [134:175]
protected Cut randomCut(double factor, float[] point, BoundingBox box) {
double range = 0.0;
for (int i = 0; i < point.length; i++) {
float minValue = (float) box.getMinValue(i);
float maxValue = (float) box.getMaxValue(i);
if (point[i] < minValue) {
minValue = point[i];
} else if (point[i] > maxValue) {
maxValue = point[i];
}
range += maxValue - minValue;
}
double breakPoint = factor * range;
for (int i = 0; i < box.getDimensions(); i++) {
float minValue = (float) box.getMinValue(i);
float maxValue = (float) box.getMaxValue(i);
if (point[i] < minValue) {
minValue = point[i];
} else if (point[i] > maxValue) {
maxValue = point[i];
}
double gap = maxValue - minValue;
if (breakPoint <= gap) {
float cutValue = (float) (minValue + breakPoint);
// Random cuts have to take a value in the half-open interval [minValue,
// maxValue) to ensure that a
// Node has a valid left child and right child.
if ((cutValue >= maxValue) && (minValue < maxValue)) {
cutValue = Math.nextAfter((float) maxValue, minValue);
}
return new Cut(i, cutValue);
}
breakPoint -= gap;
}
throw new IllegalStateException("The break point did not lie inside the expected range");
}