private static String printClusterStats(Clusterer clusterer, String fileName)
			throws Exception {
		StringBuffer text = new StringBuffer();
		int i = 0;
		int cnum;
		double loglk = 0.0;
		int cc = clusterer.numberOfClusters();
		double[] instanceStats = new double[cc];
		int unclusteredInstances = 0;

		if (fileName.length() != 0) {
			DataSource source = new DataSource(fileName);
			Instances structure = source.getStructure();
			Instance inst;
			while (source.hasMoreElements(structure)) {
				inst = source.nextElement(structure);
				try {
					cnum = clusterer.clusterInstance(inst);

					if (clusterer instanceof DensityBasedClusterer) {
						loglk += ((DensityBasedClusterer) clusterer)
								.logDensityForInstance(inst);
						// temp = Utils.sum(dist);
					}
					instanceStats[cnum]++;
				} catch (Exception e) {
					unclusteredInstances++;
				}
				i++;
			}

			/*
			 * // count the actual number of used clusters int count = 0; for (i
			 * = 0; i < cc; i++) { if (instanceStats[i] > 0) { count++; } } if
			 * (count > 0) { double[] tempStats = new double [count]; count=0;
			 * for (i=0;i<cc;i++) { if (instanceStats[i] > 0) {
			 * tempStats[count++] = instanceStats[i]; } } instanceStats =
			 * tempStats; cc = instanceStats.length; }
			 */

			int clustFieldWidth = (int) ((Math.log(cc) / Math.log(10)) + 1);
			int numInstFieldWidth = (int) ((Math.log(i) / Math.log(10)) + 1);
			double sum = Utils.sum(instanceStats);
			loglk /= sum;
			text.append("Clustered Instances\n");

			for (i = 0; i < cc; i++) {
				if (instanceStats[i] > 0) {
					text.append(Utils.doubleToString((double) i,
							clustFieldWidth, 0)
							+ "      "
							+ Utils.doubleToString(instanceStats[i],
									numInstFieldWidth, 0)
							+ " ("
							+ Utils.doubleToString(
									(instanceStats[i] / sum * 100.0), 3, 0)
							+ "%)\n");
				}
			}
			if (unclusteredInstances > 0) {
				text
						.append("\nUnclustered Instances : "
								+ unclusteredInstances);
			}

			if (clusterer instanceof DensityBasedClusterer) {
				text.append("\n\nLog likelihood: "
						+ Utils.doubleToString(loglk, 1, 5) + "\n");
			}
		}

		return text.toString();
	}