edu.uci.ics.jung.algorithms.cluster
Class KMeansClusterer

java.lang.Object
  extended by 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

Nested Class Summary
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.
 
Field Summary
protected  double convergence_threshold
           
protected  int max_iterations
           
protected  RandomEngine rand
           
 
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
     

    Field Detail

    max_iterations

    protected int max_iterations

    convergence_threshold

    protected double convergence_threshold

    rand

    protected RandomEngine rand
    Constructor Detail

    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:

    Parameters:
    max_iterations -
    convergence_threshold -
    Method Detail

    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 locations
    centroids - the centroids of the clusters to be formed
    Returns:
    a map of objects to assigned clusters

    setSeed

    public void setSeed(int random_seed)