Package de.jungblut.clustering
Class KMeansClustering
- java.lang.Object
-
- de.jungblut.clustering.KMeansClustering
-
public final class KMeansClustering extends java.lang.ObjectSequential version of k-means clustering.- Author:
- thomas.jungblut
-
-
Constructor Summary
Constructors Constructor Description KMeansClustering(int k, de.jungblut.math.DoubleVector[] vectors, boolean random)Initializes a newKMeansClustering.KMeansClustering(int k, java.util.List<de.jungblut.math.DoubleVector> vectors, boolean random)Initializes a newKMeansClustering.KMeansClustering(java.util.List<de.jungblut.math.DoubleVector> centers, java.util.List<de.jungblut.math.DoubleVector> vectors)Initializes a newKMeansClustering.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<Cluster>cluster(int iterations, DistanceMeasurer distanceMeasurer, double delta, boolean verbose)Starts the clustering process.de.jungblut.math.DoubleVector[]getCenters()doublegetClusteringCost()
-
-
-
Constructor Detail
-
KMeansClustering
public KMeansClustering(int k, de.jungblut.math.DoubleVector[] vectors, boolean random)Initializes a newKMeansClustering.- Parameters:
k- the number of centers to use.vectors- the vectors to cluster.random- true if use random initialization, else it will just pick the first k vectors.
-
KMeansClustering
public KMeansClustering(int k, java.util.List<de.jungblut.math.DoubleVector> vectors, boolean random)Initializes a newKMeansClustering.- Parameters:
k- the number of centers to use.vectors- the vectors to cluster.random- true if use random initialization, else it will just pick the first k vectors.
-
KMeansClustering
public KMeansClustering(java.util.List<de.jungblut.math.DoubleVector> centers, java.util.List<de.jungblut.math.DoubleVector> vectors)Initializes a newKMeansClustering.- Parameters:
centers- initial centers, maybe seeded fromCanopyClustering.vectors- the vectors to cluster.
-
-
Method Detail
-
cluster
public java.util.List<Cluster> cluster(int iterations, DistanceMeasurer distanceMeasurer, double delta, boolean verbose)
Starts the clustering process.- Parameters:
iterations- the iterations to cluster.distanceMeasurer- the distance measurement to use.delta- is the change in the sum of distances over iterations. If the difference is lower than delta the iteration will stop.if- true, costs in each iteration will be printed.- Returns:
- the clusters, which contain a center and the assigned vectors.
-
getClusteringCost
public double getClusteringCost()
-
getCenters
public de.jungblut.math.DoubleVector[] getCenters()
- Returns:
- the current state of the centers.
-
-