code: public double clustering(double[][] centroids, double[][] sums, int[] counts, int[] membership) {
          int k = centroids.length;
  
          Arrays.fill(counts, 0);
          int[] candidates = new int[k];
          for (int i = 0; i < k; i++) {
              candidates[i] = i;
              Arrays.fill(sums[i], 0.0);
          }
  
          return filter(root, centroids, candidates, k, sums, counts, membership);
      }
docs: Given k cluster centroids, this method assigns data to nearest centroids.
  The return value is the distortion to the centroids. The parameter sums
  will hold the sum of data for each cluster. The parameter counts hold
  the number of data of each cluster. If membership is
  not null, it should be an array of size n that will be filled with the
  index of the cluster [0 - k) that each data point is assigned to.