ac.essex.ooechs.kmeans
Class KMeansAlgorithm

java.lang.Object
  extended by java.lang.Thread
      extended by ac.essex.ooechs.kmeans.KMeansClusterer
All Implemented Interfaces:
java.lang.Runnable

public class KMeansAlgorithm
extends java.lang.Thread

An implementation of the K means clustering algorith, which attempts to find the centroids assumed to be at the center of spherical clusters of points in n dimensional feature space.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  int centroidInitialisationStrategy
           
protected  java.util.Vector<Centroid> centroids
           
static int CHOOSE_FIRST_N_POINTS
          Centroid initialisation strategy 1: For centroid[i] give it the initial position points[i].position.
static int CHOOSE_RANDOM_POINT_OF_SAME_CLASS
          Centroid initialisation strategy 3: Initialise centroids with the position of a random point which has the same classID as the centroid.
static int CHOOSE_RANDOM_POINTS
          Centroid initialisation strategy 2: Initialise centroids with the position of a random point.
protected  java.util.Vector<ClusterClass> classes
           
protected  java.util.Vector<DataPoint> points
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
KMeansAlgorithm(int centroidInitialisationStrategy, java.util.Vector<ClusterClass> classes)
           
 
Method Summary
 void add(DataPoint obj)
           
 DataPoint getRandomPoint()
          Finds a random point.
 DataPoint getRandomPoint(ClusterClass c)
          Finds a random point with a given classID.
 KMeansSolution getSolution()
          Returns a cluster solution object which allows the algorithm to be used as a classifier.
 void run()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHOOSE_FIRST_N_POINTS

public static final int CHOOSE_FIRST_N_POINTS
Centroid initialisation strategy 1: For centroid[i] give it the initial position points[i].position.

See Also:
Constant Field Values

CHOOSE_RANDOM_POINTS

public static final int CHOOSE_RANDOM_POINTS
Centroid initialisation strategy 2: Initialise centroids with the position of a random point.

See Also:
Constant Field Values

CHOOSE_RANDOM_POINT_OF_SAME_CLASS

public static final int CHOOSE_RANDOM_POINT_OF_SAME_CLASS
Centroid initialisation strategy 3: Initialise centroids with the position of a random point which has the same classID as the centroid.

See Also:
Constant Field Values

centroids

protected java.util.Vector<Centroid> centroids

points

protected java.util.Vector<DataPoint> points

classes

protected java.util.Vector<ClusterClass> classes

centroidInitialisationStrategy

protected int centroidInitialisationStrategy
Constructor Detail

KMeansAlgorithm

public KMeansAlgorithm(int centroidInitialisationStrategy,
                       java.util.Vector<ClusterClass> classes)
Method Detail

add

public void add(DataPoint obj)

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

getSolution

public KMeansSolution getSolution()
Returns a cluster solution object which allows the algorithm to be used as a classifier.

See Also:
KMeansSolution

getRandomPoint

public DataPoint getRandomPoint()
Finds a random point. Can be used to initialise the centroids' positions.


getRandomPoint

public DataPoint getRandomPoint(ClusterClass c)
Finds a random point with a given classID. Can be used in the initialisation of the K-means clusterer as a heuristic to find a reasonable starting point for each centroid.