Java Code Examples for weka.clusterers.HierarchicalClusterer#getNumClusters()

The following examples show how to use weka.clusterers.HierarchicalClusterer#getNumClusters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HierarClusterer.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ClusteringResult performClustering(Instances dataset, ParameterSet parameters) {
  HierarchicalClusterer clusterer = new HierarchicalClusterer();
  String[] options = new String[5];
  LinkType link = parameters.getParameter(HierarClustererParameters.linkType).getValue();
  DistanceType distanceType =
      parameters.getParameter(HierarClustererParameters.distanceType).getValue();
  options[0] = "-L";
  options[1] = link.name();
  options[2] = "-A";
  switch (distanceType) {
    case EUCLIDIAN:
      options[3] = "weka.core.EuclideanDistance";
      break;
    case CHEBYSHEV:
      options[3] = "weka.core.ChebyshevDistance";
      break;
    case MANHATTAN:
      options[3] = "weka.core.ManhattanDistance";
      break;
    case MINKOWSKI:
      options[3] = "weka.core.MinkowskiDistance";
      break;
  }

  options[4] = "-P";
  try {
    clusterer.setOptions(options);
    clusterer.setPrintNewick(true);
    clusterer.buildClusterer(dataset);
    // clusterer.graph() gives only the first cluster and in the case
    // there
    // are more than one cluster the variables in the second cluster are
    // missing.
    // I'm using clusterer.toString() which contains all the clusters in
    // Newick format.
    ClusteringResult result =
        new ClusteringResult(null, clusterer.toString(), clusterer.getNumClusters(), null);
    return result;
  } catch (Exception ex) {
    logger.log(Level.SEVERE, null, ex);
    return null;
  }
}
 
Example 2
Source File: HierarClusterer.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ClusteringResult performClustering(Instances dataset, ParameterSet parameters) {
  HierarchicalClusterer clusterer = new HierarchicalClusterer();
  String[] options = new String[5];
  LinkType link = parameters.getParameter(HierarClustererParameters.linkType).getValue();
  DistanceType distanceType =
      parameters.getParameter(HierarClustererParameters.distanceType).getValue();
  options[0] = "-L";
  options[1] = link.name();
  options[2] = "-A";
  switch (distanceType) {
    case EUCLIDIAN:
      options[3] = "weka.core.EuclideanDistance";
      break;
    case CHEBYSHEV:
      options[3] = "weka.core.ChebyshevDistance";
      break;
    case MANHATTAN:
      options[3] = "weka.core.ManhattanDistance";
      break;
    case MINKOWSKI:
      options[3] = "weka.core.MinkowskiDistance";
      break;
  }

  options[4] = "-P";
  try {
    clusterer.setOptions(options);
    clusterer.setPrintNewick(true);
    clusterer.buildClusterer(dataset);
    // clusterer.graph() gives only the first cluster and in the case
    // there
    // are more than one cluster the variables in the second cluster are
    // missing.
    // I'm using clusterer.toString() which contains all the clusters in
    // Newick format.
    ClusteringResult result =
        new ClusteringResult(null, clusterer.toString(), clusterer.getNumClusters(), null);
    return result;
  } catch (Exception ex) {
    logger.log(Level.SEVERE, null, ex);
    return null;
  }
}