public class KMeansClusterer
extends java.lang.Object
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 cern.jet.random.engine.RandomEngine |
rand |
Constructor and Description |
---|
KMeansClusterer(int max_iterations,
double convergence_threshold)
Creates an instance for which calls to
cluster will terminate
when either of the two following conditions is true:
the number of iterations is > max_iterations
none of the centroids has moved as much as convergence_threshold
since the previous iteration
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Map |
assignToClusters(java.util.Map object_locations,
java.util.Set centroids)
Assigns each object to the cluster whose centroid is closest to the
object.
|
java.util.Collection |
cluster(java.util.Map 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. |
void |
setSeed(int random_seed) |
protected int max_iterations
protected double convergence_threshold
protected cern.jet.random.engine.RandomEngine rand
public KMeansClusterer(int max_iterations, double convergence_threshold)
cluster
will terminate
when either of the two following conditions is true:
max_iterations
none of the centroids has moved as much as convergence_threshold
since the previous iteration
max_iterations
- convergence_threshold
- public java.util.Collection cluster(java.util.Map 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 Objects to cluster, to
double
arrays that specify their locations in d-dimensional space.num_clusters
- the number of clusters to createKMeansClusterer.NotEnoughClustersException
protected java.util.Map assignToClusters(java.util.Map object_locations, java.util.Set centroids)
object_locations
- a map of objects to locationscentroids
- the centroids of the clusters to be formedpublic void setSeed(int random_seed)