public class KMeansClusterer<T> extends Object
cluster
will terminate when either of the two following
conditions is true:
max_iterations
convergence_threshold
since the previous iteration
Modifier and Type | Class and Description |
---|---|
static class |
KMeansClusterer.NotEnoughClustersException
An exception that indicates that the specified data points cannot be
clustered into the number of clusters requested by the user.
|
Modifier and Type | Field and Description |
---|---|
protected double |
convergence_threshold |
protected int |
max_iterations |
protected Random |
rand |
Constructor and Description |
---|
KMeansClusterer()
Creates an instance with max iterations of 100 and convergence threshold
of 0.001.
|
KMeansClusterer(int max_iterations,
double convergence_threshold)
Creates an instance which will terminate when either the maximum number of
iterations has been reached, or all changes are smaller than the convergence threshold.
|
Modifier and Type | Method and Description |
---|---|
protected Map<double[],Map<T,double[]>> |
assignToClusters(Map<T,double[]> object_locations,
Set<double[]> centroids)
Assigns each object to the cluster whose centroid is closest to the
object.
|
Collection<Map<T,double[]>> |
cluster(Map<T,double[]> object_locations,
int num_clusters)
Returns a
Collection of clusters, where each cluster is
represented as a Map of Objects to locations
in d-dimensional space. |
double |
getConvergenceThreshold() |
int |
getMaxIterations() |
void |
setConvergenceThreshold(double convergence_threshold) |
void |
setMaxIterations(int max_iterations) |
void |
setSeed(int random_seed)
Sets the seed used by the internal random number generator.
|
protected int max_iterations
protected double convergence_threshold
protected Random rand
public KMeansClusterer(int max_iterations, double convergence_threshold)
max_iterations
- the maximum number of iterations to employconvergence_threshold
- the smallest change we want to trackpublic KMeansClusterer()
public int getMaxIterations()
public void setMaxIterations(int max_iterations)
max_iterations
- the maximum number of iterationspublic double getConvergenceThreshold()
public void setConvergenceThreshold(double convergence_threshold)
convergence_threshold
- the convergence thresholdpublic Collection<Map<T,double[]>> cluster(Map<T,double[]> object_locations, int num_clusters)
Collection
of clusters, where each cluster is
represented as a Map
of Objects
to locations
in d-dimensional space.object_locations
- a map of the items to cluster, to
double
arrays that specify their locations in d-dimensional space.num_clusters
- the number of clusters to createKMeansClusterer.NotEnoughClustersException
- if num_clusters
is larger than the number of
distinct points in object_locationsprotected Map<double[],Map<T,double[]>> assignToClusters(Map<T,double[]> object_locations, Set<double[]> centroids)
object_locations
- a map of objects to locationscentroids
- the centroids of the clusters to be formedpublic void setSeed(int random_seed)
random_seed
- the random seed to useCopyright © 2015. All rights reserved.