try { if (trainFileName.length() != 0) { train = new Instances(new FileReader(trainFileName)); }  if (objectInputFileName.length() != 0) { objectInputStream = new ObjectInputStream(new FileInputStream(objectInputFileName)); }  if (objectOutputFileName.length() != 0) { objectOutputStream = new ObjectOutputStream(new FileOutputStream(objectOutputFileName));
double sum = Utils.sum(instanceStats); loglk /= sum; m_clusteringResults.append("Cluster Instances\n"); int clustFieldWidth = (int)((Math.log(cc)/Math.log(10))+1); for (i = 0; i < cc; i++) { if (instanceStats[i] > 0) { m_clusteringResults.append(Utils.doubleToString((double)i, clustFieldWidth, 0) + "      " + Utils.doubleToString(instanceStats[i], numInstFieldWidth, 0) + " (" + Utils.doubleToString((instanceStats[i] / sum * 100.0) , 3, 0) + "%)\n");
  public static String evaluateClusterer (Clusterer clusterer, String[] options)    throws Exception  {    int seed = 1, folds = 10;    boolean doXval = false;    Instances train = null;    Instances test = null;    Random random;    String trainFileName, testFileName, seedString, foldsString, objectInputFileName, objectOutputFileName;    String[] savedOptions = null;    boolean printClusterAssignments = false;    ObjectInputStream objectInputStream = null;    ObjectOutputStream objectOutputStream = null;    StringBuffer text = new StringBuffer();    try {      if (Utils.getFlag('h', options)) {        throw  new Exception("Help requested.");      }      // Get basic options (options the same for all clusterers      printClusterAssignments = Utils.getFlag('p', options);      objectInputFileName = Utils.getOption('l', options);      objectOutputFileName = Utils.getOption('d', options);      trainFileName = Utils.getOption('t', options);      testFileName = Utils.getOption('T', options);      if (trainFileName.length() == 0) {        if (objectInputFileName.length() == 0) {          throw  new Exception("No training file and no object " 			       + "input file given.");        }        if (testFileName.length() == 0) {          throw  new Exception("No training file and no test file given.");        }      }      else {	if ((objectInputFileName.length() != 0) 	    && (printClusterAssignments == false)) {	  throw  new Exception("Can't use both train and model file " 			       + "unless -p specified.");	}      }      seedString = Utils.getOption('s', options);      if (seedString.length() != 0) {	seed = Integer.parseInt(seedString);      }      foldsString = Utils.getOption('x', options);      if (foldsString.length() != 0) {	folds = Integer.parseInt(foldsString);	doXval = true;      }    }    catch (Exception e) {      throw  new Exception('\n' + e.getMessage() 			   + makeOptionString(clusterer));    }    try {      if (trainFileName.length() != 0) {	train = new Instances(new FileReader(trainFileName));      }      if (objectInputFileName.length() != 0) {	objectInputStream = new ObjectInputStream(new FileInputStream(objectInputFileName));      }      if (objectOutputFileName.length() != 0) {	objectOutputStream = new 	  ObjectOutputStream(new FileOutputStream(objectOutputFileName));      }    }    catch (Exception e) {      throw  new Exception("Can't open file " + e.getMessage() + '.');    }    // Save options    if (options != null) {      savedOptions = new String[options.length];      System.arraycopy(options, 0, savedOptions, 0, options.length);    }    if (objectInputFileName.length() != 0) {      Utils.checkForRemainingOptions(options);    }    // Set options for clusterer    if (clusterer instanceof OptionHandler) {      ((OptionHandler)clusterer).setOptions(options);    }    Utils.checkForRemainingOptions(options);    if (objectInputFileName.length() != 0) {      // Load the clusterer from file      clusterer = (Clusterer)objectInputStream.readObject();      objectInputStream.close();    }    else {      // Build the clusterer if no object file provided      clusterer.buildClusterer(train);    }    /* Output cluster predictions only (for the test data if specified,       otherwise for the training data */    if (printClusterAssignments) {      return  printClusterings(clusterer, train, testFileName);    }    text.append(clusterer.toString());    text.append("\n\n=== Clustering stats for training data ===\n\n" 		+ printClusterStats(clusterer, trainFileName));    if (testFileName.length() != 0) {      text.append("\n\n=== Clustering stats for testing data ===\n\n" 		  + printClusterStats(clusterer, testFileName));    }    if ((clusterer instanceof DistributionClusterer) && 	(doXval == true) && 	(testFileName.length() == 0) && 	(objectInputFileName.length() == 0)) {      // cross validate the log likelihood on the training data      random = new Random(seed);      random.setSeed(seed);      train.randomize(random);      text.append(crossValidateModel(clusterer.getClass().getName()				     , train, folds, savedOptions));    }    // Save the clusterer if an object output file is provided    if (objectOutputFileName.length() != 0) {      objectOutputStream.writeObject(clusterer);      objectOutputStream.flush();      objectOutputStream.close();    }    return  text.toString();  }