code: public void setup(Matrix m, int[] initialAssignments, int numClusters) {
          // Save the meta data we need to maintain.
          assignments = initialAssignments;
          matrix = new ArrayList<DoubleVector>(m.rows());
          for (int i = 0; i < m.rows(); ++i)
              matrix.add(m.getRowVector(i));
  
          // Initialize the cluster information.
          centroids = new DoubleVector[numClusters];
          clusterSizes = new int[numClusters];
          costs = new double[numClusters];
  
          // Initialize the clusters.
          for (int c = 0; c < numClusters; ++c)
              centroids[c] = new DenseVector(m.columns());
  
          // Form the cluster composite vectors, i.e. unscaled centroids.
          for (int i = 0; i < m.rows(); ++i) {
              int assignment = initialAssignments[i];
              VectorMath.add(centroids[assignment], matrix.get(i));
              clusterSizes[assignment]++;
          }
  
          // Compute the cost of each centroid.
          for (int c = 0; c < numClusters; ++c)
              centroids[c] = new DenseDynamicMagnitudeVector(
                      centroids[c].toArray());
  
          subSetup(m);
  
          SparseDoubleVector empty = new CompactSparseVector(m.columns());
          for (int c = 0; c < numClusters; ++c)
              if (clusterSizes[c] != 0)
                  costs[c] = getOldCentroidScore(empty, c, clusterSizes[c]);
      }
docs: {@inheritDoc}