Random random = new Random();
final DoubleVector[] principles = new DoubleVector[numPrincipleVectors];
for (int i = 0; i < principles.length; ++i)
principles[i] = new DenseVector(sspace.getVectorLength());
// Randomly assign the data set to different intitial clusters
final MultiMap<Integer,Integer> clusterAssignment =
new HashMultiMap<Integer,Integer>();
for (int i = 0; i < numTerms; ++i)
clusterAssignment.put(random.nextInt(numPrincipleVectors), i);
int numIters = 1;
for (int iter = 0; iter < numIters; ++iter) {
verbose(LOGGER, "Computing principle vectors (round %d/%d)", iter+1, numIters);
// Compute the centroids
for (Map.Entry<Integer,Set<Integer>> e
: clusterAssignment.asMap().entrySet()) {
int cluster = e.getKey();
DoubleVector principle = new DenseVector(sspace.getVectorLength());
principles[cluster] = principle;
for (Integer row : e.getValue())
VectorMath.add(principle, termVectors.get(row));
}