code: public Assignments cluster(Matrix m,
                                 int maxClusters,
                                 Properties props) {
          int startSize = Integer.parseInt(props.getProperty(
                  NUM_CLUSTERS_START, DEFAULT_NUM_CLUSTERS_START));
          int numGaps = Integer.parseInt(props.getProperty(
                  NUM_REFERENCE_DATA_SETS, DEFAULT_NUM_REFERENCE_DATA_SETS));
          int numIterations = maxClusters - startSize;
          String criterion = props.getProperty(METHOD_PROPERTY, DEFAULT_METHOD);
  
          verbose("Transforming the original data set");
          Transform tfidf = new TfIdfDocStripedTransform();
          Transform rowMag = new RowMagnitudeTransform();
          m = rowMag.transform(tfidf.transform(m));
  
          verbose("Generating the reference data set");
          // Generate the reference data sets.
          ReferenceDataGenerator generator = new ReferenceDataGenerator(m);
          Matrix[] gapMatrices = new Matrix[numGaps];
          for (int i = 0; i < numGaps; ++i)
              gapMatrices[i] = rowMag.transform(tfidf.transform(
                      generator.generateTestData()));
  
          double[] gapResults = new double[numIterations];
          double[] gapStds = new double[numIterations];
          Assignments[] gapAssignments = new Assignments[numIterations];
  
          Assignments bestAssignments = null;
          double bestGap = Double.NEGATIVE_INFINITY;
          int bestK = 0;
          // Compute the gap statistic for each iteration.
          for (int i = 0; i < numIterations; ++i) {
              clusterIteration(i, startSize, criterion, m, gapMatrices,
                               gapResults, gapStds, gapAssignments);
              if (bestGap >= (gapResults[i] - gapStds[i])) {
                  break;
              }
  
              // Otherwise, continue clustering with higher values of k.
              bestGap = gapResults[i];
              bestAssignments = gapAssignments[i];
              bestK = i + startSize;
          }
  
          return bestAssignments;
      }
docs: {@inheritDoc}
  
  </p>
  
  Iteratively computes the k-means clustering of the dataset {@code m}
  using the the Gap Statistic .