Class AlgorithmKMeans

java.lang.Object
  extended by Algorithm
      extended by AlgorithmKMeans
All Implemented Interfaces:
java.lang.Runnable

public class AlgorithmKMeans
extends Algorithm

implements the K nearest neighbor algorithms


Field Summary
static long RAND_SEED
          The random number generator
 
Constructor Summary
AlgorithmKMeans()
           
 
Method Summary
 void classify(DecisionRegion region)
          Classifies the data sets based on the k-means iterative algorithm
 void computeMeans(DecisionRegion region)
          Computes the means of the data sets after each iteraion
 int displayClusterError(int closest, java.util.Vector cluster, int id)
          determines the number of points in error, i.e, not classified by finding the distance of the datapoints from the closest of the vector set
 void generateMeans(int numMeans)
          Generates random initial guesses (means) for the data set
 void generatePool()
          Collects all the data points of all the data sets
 int getClosestSet(MyPoint mean)
          Determines the closest data sets to the cluster
 java.util.Vector<MyPoint> getDecisionRegion(java.util.Vector<MyPoint> vec)
          Computes the k-mean decision region - nearest neighbor algorithm
 boolean initialize()
          Overrides the initialize() method in the base class.
 void initializeKmeans()
          Initializes the kmean array with the original data sets
 void outputDecisionRegion()
          displays the decision region on the output panel
 void run()
          Implementation of the run function from the Runnable interface.
 
Methods inherited from class Algorithm
computeMeans, disableControl, enableControl, nextStep, prevStep, scaleToFitData, setDataPoints, setOutputPanel, setProcessBox
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RAND_SEED

public static final long RAND_SEED
The random number generator

See Also:
Constant Field Values
Constructor Detail

AlgorithmKMeans

public AlgorithmKMeans()
Method Detail

initialize

public boolean initialize()
Overrides the initialize() method in the base class. Initializes member data and prepares for execution of first step. This method "resets" the algorithm.

Specified by:
initialize in class Algorithm
Returns:
Returns false

run

public void run()
Implementation of the run function from the Runnable interface. Determines what the current step is and calls the appropriate method.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class Algorithm

generatePool

public void generatePool()
Collects all the data points of all the data sets


generateMeans

public void generateMeans(int numMeans)
Generates random initial guesses (means) for the data set

Parameters:
numMeans - number of mean points

initializeKmeans

public void initializeKmeans()
Initializes the kmean array with the original data sets


classify

public void classify(DecisionRegion region)
Classifies the data sets based on the k-means iterative algorithm

Parameters:
region - - stored data sets from the classification
See Also:
DecisionRegion

computeMeans

public void computeMeans(DecisionRegion region)
Computes the means of the data sets after each iteraion

Parameters:
region - - classified data sets
See Also:
DecisionRegion

getClosestSet

public int getClosestSet(MyPoint mean)
Determines the closest data sets to the cluster

Parameters:
mean - mean point of the cluster
Returns:
closest data set to the cluster
See Also:
MyPoint

displayClusterError

public int displayClusterError(int closest,
                               java.util.Vector cluster,
                               int id)
determines the number of points in error, i.e, not classified by finding the distance of the datapoints from the closest of the vector set

Parameters:
closest - the data specifying which of the dataset is the closest.
cluster - the data points which form a closest cluster
id - unused in current implementation
Returns:
error number of data points which lie out of the classification

getDecisionRegion

public java.util.Vector<MyPoint> getDecisionRegion(java.util.Vector<MyPoint> vec)
Computes the k-mean decision region - nearest neighbor algorithm

Parameters:
vec - vector of initial guesses
Returns:
vector of desision region points

outputDecisionRegion

public void outputDecisionRegion()
displays the decision region on the output panel