// However, if the ratio is less than 1, we want to create a new cluster with probability
// proportional to the distance to the closest cluster.
double sample = random.nextDouble();
if (sample < row.getWeight() * closestPair.getWeight() / distanceCutoff) {
// Add new centroid, note that the vector is copied because we may mutate it later.
centroids.add(row.clone());
} else {
// Merge the new point with the existing centroid. This will update the centroid's actual
// position.
// We know that all the points we inserted in the centroids searcher are (or extend)
// WeightedVector, so the cast will always succeed.