Package dev.brachtendorf.clustering
Class KMeans
- java.lang.Object
-
- dev.brachtendorf.clustering.KMeans
-
- All Implemented Interfaces:
ClusterAlgorithm
- Direct Known Subclasses:
KMeansPlusPlus
public class KMeans extends Object implements ClusterAlgorithm
- Author:
- Kilian
-
-
Field Summary
Fields Modifier and Type Field Description protected DistanceFunctiondistanceFunctionFunction to calculate distance between individual data pointsprotected intkThe number of cluster the data will be partitioned intoprotected intlastIterationCount
-
Constructor Summary
Constructors Constructor Description KMeans(int clusters)Create a KMeans clusterer with k clusters and EuclideanDistance.KMeans(int clusters, DistanceFunction distanceFunction)Create a KMeans clusterer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClusterResultcluster(double[][] data)protected voidcomputeKMeans(DoubleSummaryStatistics[][] clusterMeans, double[][] data, int[] cluster, int dataDimension)protected DoubleSummaryStatistics[][]computeStartingClusters(double[][] data, int k, int dataDimension)intiterations()
-
-
-
Field Detail
-
k
protected int k
The number of cluster the data will be partitioned into
-
distanceFunction
protected DistanceFunction distanceFunction
Function to calculate distance between individual data points
-
lastIterationCount
protected int lastIterationCount
-
-
Constructor Detail
-
KMeans
public KMeans(int clusters)
Create a KMeans clusterer with k clusters and EuclideanDistance.- Parameters:
clusters- the number of cluster to partition the data into
-
KMeans
public KMeans(int clusters, DistanceFunction distanceFunction)Create a KMeans clusterer- Parameters:
clusters- the number of cluster to partition the data intodistanceFunction- the distanceFunction used to compute the distance between data points
-
-
Method Detail
-
cluster
public ClusterResult cluster(double[][] data)
- Specified by:
clusterin interfaceClusterAlgorithm
-
computeStartingClusters
protected DoubleSummaryStatistics[][] computeStartingClusters(double[][] data, int k, int dataDimension)
-
computeKMeans
protected void computeKMeans(DoubleSummaryStatistics[][] clusterMeans, double[][] data, int[] cluster, int dataDimension)
-
iterations
public int iterations()
- Returns:
- the number of iterations used to cluster the data
-
-