edu.uci.ics.jung.algorithms.cluster
Class KMeansClusterer
java.lang.Object
edu.uci.ics.jung.algorithms.cluster.KMeansClusterer
public class KMeansClusterer
- extends Object
Groups Objects into a specified number of clusters, based on their
proximity in d-dimensional space, using the k-means algorithm.
- Author:
- Joshua O'Madadhain
Constructor Summary |
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
|
Method Summary |
protected Map |
assignToClusters(Map object_locations,
Set centroids)
Assigns each object to the cluster whose centroid is closest to the
object. |
Collection |
cluster(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)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
max_iterations
protected int max_iterations
convergence_threshold
protected double convergence_threshold
rand
protected RandomEngine rand
KMeansClusterer
public 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
- Parameters:
max_iterations
- convergence_threshold
-
cluster
public Collection cluster(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.
- Parameters:
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 create
- Throws:
KMeansClusterer.NotEnoughClustersException
assignToClusters
protected Map assignToClusters(Map object_locations,
Set centroids)
- Assigns each object to the cluster whose centroid is closest to the
object.
- Parameters:
object_locations
- a map of objects to locationscentroids
- the centroids of the clusters to be formed
- Returns:
- a map of objects to assigned clusters
setSeed
public void setSeed(int random_seed)