private int doBatchKmeans () {

		System.out.println("\nBegining a new iteration of K-Means...");

		int numReassigned = 0;

		/* Clear records for incremental k-means */

		for (int i = 0; i < this.centroids.length; ++i) {
			this.newClusters[i] = new ArrayList<Instance>();
			this.newCentroids[i] = new HashSparseVector();
			this.newQualities[i] = 0.0f;
		}

		for (int clusterNum = 0; clusterNum < this.centroids.length; ++clusterNum) {    // iterate over clusters
			for (int docNum = 0; docNum < this.assignedClusters[clusterNum].size();	++docNum) {    // iterate over docs

				/*
				 *  Store the document the loops have selected in the 'doc' variable.
				 * Store is vector in the 'docVec' variable for easy access.
				 */
				Instance doc = this.assignedClusters[clusterNum].get(docNum);
				HashSparseVector docVec = (HashSparseVector) doc.getData();

				int bestClusterNum = clusterNum;    // Assume we are already in the best cluster.
				double distanceToCurrentCentroid =
					this.centroids[clusterNum].distanceEuclidean(docVec);
				double squareDistanceOfBestCluster = distanceToCurrentCentroid;

				for (int i = 0; i < this.centroids.length; ++i) {

					double distance = 0.0;

					// see which centroid is closest to docVec
					if (clusterNum == i) {    // We know the distance in its' current cluster.
						distance = distanceToCurrentCentroid;
					} else {
						distance = this.centroids[i].distanceEuclidean(docVec);

					}

					if (distance < squareDistanceOfBestCluster) {
						squareDistanceOfBestCluster = distance;
						bestClusterNum = i;
					}
				}

				if (bestClusterNum != clusterNum) {    // we moved a document!
					++numReassigned;
				}

				this.newClusters[bestClusterNum].add(doc);
				this.newCentroids[bestClusterNum].plus(docVec);
			}
		}

		// Calculate the centroids of the clusters
		for (int i = 0; i < newClusters.length; ++i) {
			this.newCentroids[i].scaleDivide(this.newClusters[i].size());

			this.newQualities[i] = this.calculateClusterQuality(this.newClusters[i],
					this.newCentroids[i]);

			System.out.println("new cluster " + i + " Viarances: " +
					this.newQualities[i] + " Num: "+ newClusters[i].size());
		}

		return (numReassigned);
	}
private int doBatchKmeans ( ) { System . out . println ( "\nBegining a new iteration of K-Means..." ) ; int numReassigned = 0 ; for ( int i = 0 ; i < this . centroids . length ; ++ i ) { this . newClusters [ i ] = new ArrayList < Instance > ( ) ; this . newCentroids [ i ] = new HashSparseVector ( ) ; this . newQualities [ i ] = 0.0f ; } for ( int clusterNum = 0 ; clusterNum < this . centroids . length ; ++ clusterNum ) { for ( int docNum = 0 ; docNum < this . assignedClusters [ clusterNum ] . size ( ) ; ++ docNum ) { Instance doc = this . assignedClusters [ clusterNum ] . get ( docNum ) ; HashSparseVector docVec = ( HashSparseVector ) doc . getData ( ) ; int bestClusterNum = clusterNum ; double distanceToCurrentCentroid = this . centroids [ clusterNum ] . distanceEuclidean ( docVec ) ; double squareDistanceOfBestCluster = distanceToCurrentCentroid ; for ( int i = 0 ; i < this . centroids . length ; ++ i ) { double distance = 0.0 ; if ( clusterNum == i ) { distance = distanceToCurrentCentroid ; } else { distance = this . centroids [ i ] . distanceEuclidean ( docVec ) ; } if ( distance < squareDistanceOfBestCluster ) { squareDistanceOfBestCluster = distance ; bestClusterNum = i ; } } if ( bestClusterNum != clusterNum ) { ++ numReassigned ; } this . newClusters [ bestClusterNum ] . add ( doc ) ; this . newCentroids [ bestClusterNum ] . plus ( docVec ) ; } } for ( int i = 0 ; i < newClusters . length ; ++ i ) { this . newCentroids [ i ] . scaleDivide ( this . newClusters [ i ] . size ( ) ) ; this . newQualities [ i ] = this . calculateClusterQuality ( this . newClusters [ i ] , this . newCentroids [ i ] ) ; System . out . println ( "new cluster " + i + " Viarances: " + this . newQualities [ i ] + " Num: " + newClusters [ i ] . size ( ) ) ; } return ( numReassigned ) ; }
Performs one iteration of batch k-means. Returns the number of documents that
were moved during this iteration. This method also updates the global variables
newClusters[] and newCentroids[] to the values. It's up to the caller to copy these
over the current assignedClusters[] and centroids[] arrays if desired.  Initial centroids of
each initial cluster must be built in the constructor.

@return