Class KMeansClustering
java.lang.Object
com.compomics.util.math.clustering.KMeansClustering
K-means clustering.
- Author:
- Harald Barsnes
-
Constructor Summary
ConstructorsConstructorDescriptionEmpty default constructorKMeansClustering(double[][] samples, String[] sampleIds, int numClusters) Constructor.KMeansClustering(File dataFile, int numClusters) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiongetClusterMembers(int clusterIndex) Get the sample names of all the members in the given cluster.getClusterMembersData(int clusterIndex) Returns a hashmap with the values for the members in the given cluster.intReturns the maximum number of iterations.intReturns the number of clusters.voidkMeanCluster(WaitingHandler waitingHandler) Run the k-means clustering.static voidMain method for testing purposes.voidPrint the centroids.voidPrint the current clusters.voidsetMaxIterations(int maxIterations) Set the maximum number of iterations.
-
Constructor Details
-
KMeansClustering
public KMeansClustering()Empty default constructor -
KMeansClustering
Constructor.- Parameters:
samples- the datasampleIds- the sample identifiersnumClusters- the number of clusters
-
KMeansClustering
Constructor.- Parameters:
dataFile- the file with the datanumClusters- the number of clusters
-
-
Method Details
-
kMeanCluster
Run the k-means clustering.- Parameters:
waitingHandler- the waiting handler
-
main
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
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
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
-