@Override
	public void train(List<Instance> instances) {
		// TODO Auto-generated method stub
		for (int i = 0 ; i < clustering_training_iterations ; i++) {
			int insIndex = 0;
			ArrayList <Integer> newAssignments = new ArrayList <Integer>();

			for (Instance instance : instances) {
				// get the closest cluster.
				int feaIndex =0;
				double minDistance = Double.MAX_VALUE;
				newAssignments.add(-1);
				for (Cluster cluster : clusters) {
					if (MathUtilities.SquaredL2Distance(cluster.getFeatureVector(), instance) < minDistance) {
						minDistance = MathUtilities.SquaredL2Distance(cluster.getFeatureVector(), instance);						
						
						newAssignments.set(insIndex, feaIndex);
					}
					feaIndex ++;
				}
				
				// update the clusters related to the assignment of the instance if assignment is changed.
				feaIndex = newAssignments.get(insIndex);
				
				if (i == 0) {
					clusters.get(feaIndex).addMember(instance);
				}
				else if (feaIndex != assignments.get(insIndex)) {
					clusters.get(feaIndex).addMember(instance);
					clusters.get(assignments.get(insIndex)).removeMember(instance);
				}
				insIndex ++;
			}
			assignments = newAssignments;
		}
	}