Class KMeansClustering
java.lang.Object
com.compomics.util.math.clustering.KMeansClustering
public class KMeansClustering extends Object
K-means clustering.
- Author:
- Harald Barsnes
-
Constructor Summary
Constructors Constructor Description KMeansClustering()
Empty default constructorKMeansClustering(double[][] samples, String[] sampleIds, int numClusters)
Constructor.KMeansClustering(File dataFile, int numClusters)
Constructor. -
Method Summary
Modifier and Type Method Description ArrayList<String>
getClusterMembers(int clusterIndex)
Get the sample names of all the members in the given cluster.HashMap<String,ArrayList<Double>>
getClusterMembersData(int clusterIndex)
Returns a hashmap with the values for the members in the given cluster.int
getMaxIterations()
Returns the maximum number of iterations.int
getNumberOfClusters()
Returns the number of clusters.void
kMeanCluster(WaitingHandler waitingHandler)
Run the k-means clustering.static void
main(String[] args)
Main method for testing purposes.void
printCentroids()
Print the centroids.void
printClusters()
Print the current clusters.void
setMaxIterations(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
-