code: private SparseMatrix retainColumns(Set<Integer> indicesToKeep) {
          int words = termToIndex.numDimensions();
          int cols = indicesToKeep.size();
  
          // Create a mapping from old indices to their new index value.
          Map<Integer, Integer> indexMap = new HashMap<Integer, Integer>();
          int newIndex = 0;
          for (Integer index : indicesToKeep)
              indexMap.put(index, newIndex++);
  
          // Create a reduced matrix that will have only the selected columns in
          // the final space.
          SparseMatrix reduced = new YaleSparseMatrix(
                  words, indicesToKeep.size());
  
          // Iterate over the sparse values in the matrix for added efficiency.
          for (int row = 0; row < words; ++ row) {
              SparseDoubleVector sv = cooccurrenceMatrix.getRowVector(row);
              for (int col : sv.getNonZeroIndices()) {
                  double v = cooccurrenceMatrix.get(row, col);
  
                  // If the original column was retained, get it's new index
                  // value and add it to the reduced matrix.
                  Integer newColIndex = indexMap.get(col);
                  if (newColIndex != null)
                      reduced.set(row, newColIndex, v);
  
                  // If the transposed row column was retained, get it's new index
                  // value and add it to the reduced matrix.  This turns the col
                  // value into the row and the new index as the column.
                  newColIndex = indexMap.get(row + words);
                  if (newColIndex != null)
                      reduced.set(col, newColIndex, v);
              }
          }
  
          return reduced;
      }
docs: Returns a reduced and concatenated version of {@code cooccurrenceMatrix}
  which has only the columns specified in {@code indicesToKeep}.