Class KMeansClustering

java.lang.Object
com.compomics.util.math.clustering.KMeansClustering

public class KMeansClustering
extends Object
K-means clustering.
Author:
Harald Barsnes
  • Constructor Details

    • KMeansClustering

      public KMeansClustering()
      Empty default constructor
    • KMeansClustering

      public KMeansClustering​(double[][] samples, String[] sampleIds, int numClusters)
      Constructor.
      Parameters:
      samples - the data
      sampleIds - the sample identifiers
      numClusters - the number of clusters
    • KMeansClustering

      public KMeansClustering​(File dataFile, int numClusters)
      Constructor.
      Parameters:
      dataFile - the file with the data
      numClusters - the number of clusters
  • Method Details

    • kMeanCluster

      public void kMeanCluster​(WaitingHandler waitingHandler)
      Run the k-means clustering.
      Parameters:
      waitingHandler - the waiting handler
    • main

      public static void main​(String[] args)
      Main method for testing purposes.
      Parameters:
      args - the command line arguments
    • printCentroids

      public void printCentroids()
      Print the centroids.
    • printClusters

      public void printClusters()
      Print the current clusters.
    • getClusterMembers

      public ArrayList<String> getClusterMembers​(int clusterIndex)
      Get the sample names of all the members in the given cluster.
      Parameters:
      clusterIndex - the index of the cluster
      Returns:
      the sample names of all the members in the given cluster
    • getClusterMembersData

      public HashMap<String,​ArrayList<Double>> getClusterMembersData​(int clusterIndex)
      Returns a hashmap with the values for the members in the given cluster. Key: sample id, value: the data points.
      Parameters:
      clusterIndex - the index of the cluster
      Returns:
      the values for the members in the given cluster
    • getNumberOfClusters

      public int getNumberOfClusters()
      Returns the number of clusters.
      Returns:
      the number of clusters
    • getMaxIterations

      public int getMaxIterations()
      Returns the maximum number of iterations.
      Returns:
      the maximum number of iterations
    • setMaxIterations

      public void setMaxIterations​(int maxIterations)
      Set the maximum number of iterations.
      Parameters:
      maxIterations - the maximum number of iterations