code: private double getNodeCost(Node node, double[] center) {
          int d = center.length;
          double scatter = 0.0;
          for (int i = 0; i < d; i++) {
              double x = (node.sum[i] / node.count) - center[i];
              scatter += x * x;
          }
          return node.cost + node.count * scatter;
      }
docs: Returns the total contribution of all data in the given kd-tree node,
  assuming they are all assigned to a mean at the given location.
  
  sum_{x \in node} ||x - mean||^2.
  
  If c denotes the mean of mass of the data in this node and n denotes
  the number of data in it, then this quantity is given by
  
  n * ||c - mean||^2 + sum_{x \in node} ||x - c||^2
  
  The sum is precomputed for each node as cost. This formula follows
  from expanding both sides as dot products.