All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.clusterers.XMeans

java.lang.Object
    |
    +----weka.clusterers.Clusterer
            |
            +----weka.clusterers.XMeans

public class XMeans
extends Clusterer
implements OptionHandler
XMeans clustering class. X-Means is K-Means extended by an Improve-Structure part In this part of the algorithm the centers are attempted to be split in its region. The decision between the children of each center and itself is done comparing the BIC-values of the two structures. See also D. Pelleg and A. Moore's paper 'X-means: Extending K-means with Efficient Estimation of the Number of Clusters'.

Valid options are:

-I
Maximum number of iterations in the overall loop (default = 1).

-M
Maximum number of iterations in the kMeans loop in
the Improve-Parameter part (default = 1000).

-J
Maximum number of iterations in the kMeans loop for the splitted
centroids in the Improve-Structure part (default = 1000).

-L
Specify the number of clusters to start with.

-H
Specify the maximal number of clusters.

-B
Distance value between true and false of binary attributes and
"same" and "different" of nominal attributes (default = 1.0).

-K
KDTrees class and its options (can only use the same distance function as XMeans).

-C
If none of the children are better, percentage of the best splits
to be taken.

-D Distance function class to be used (default = Euclidean distance) -N
Input starting cluster centers from file (ARFF-format).

-O
Output cluster centers to file (ARFF-format).

-S
Specify random number seed.

-U
Set debuglevel.

-Y
Used for debugging: Input random vektors from file.

major TODOS: make BIC-Score replaceable by other scores

Version:
$Revision: 1.6 $
Author:
Gabi Schmidberger
Author:
Mark Hall (mhall@cs.waikato.ac.nz)
Author:
Malcolm Ware
See Also:
Clusterer, OptionHandler

Variable Index

 o D_CONVCHCLOSER
 
 o D_CURR
 
 o D_FOLLOWSPLIT
 
 o D_GENERAL
 
 o D_ITERCOUNT
 
 o D_KDTREE
 
 o D_METH_MISUSE
 
 o D_PRINTCENTERS
 
 o D_RANDOMVEKTOR
 
 o m_CurrDebugFlag
 
 o R_HIGH
 
 o R_LOW
Index in ranges for LOW and HIGH and WIDTH
 o R_WIDTH
 

Constructor Index

 o XMeans()
 

Method Index

 o binValueTipText()
Returns the tip text for this property
 o buildClusterer(Instances)
Generates the X-Means clusterer.
 o checkForNominalAttributes(Instances)
Checks for nominal attributes in the dataset.
 o clusterInstance(Instance)
Classifies a given instance.
 o getBinValue()
Gets value that represents true in a new numeric attribute.
 o getCutOffFactor()
Gets the cutoff factor.
 o getDebugLevel()
Gets the debug level.
 o getDistanceF()
Gets the distance function.
 o getInputCenterFile()
Gets the name of the file to read the list of centers from.
 o getKDTree()
Gets the KDTree class.
 o getMaxIterations()
Gets the maximum number of iterations.
 o getMaxKMeans()
Gets the maximum number of iterations in KMeans.
 o getMaxKMeansForChildren()
Gets the maximum number of iterations in KMeans.
 o getMaxNumClusters()
Gets the maximum number of clusters to generate.
 o getMinNumClusters()
Gets the minimum number of clusters to generate.
 o getNextDebugVektorsInstance(Instances)
Read an instance from debug vektors file.
 o getOptions()
Gets the current settings of SimpleKMeans.
 o getOutputCenterFile()
Gets the name of the file to write the list of centers to.
 o getSeed()
Gets the random number seed.
 o globalInfo()
Returns a string describing this clusterer
 o initDebugVektorsInput()
Initialises the debug vektor input.
 o initializeRanges(Instances, int[])
Function should be in the Instances class!! Initializes the minimum and maximum values based on all instances.
 o listOptions()
Returns an enumeration describing the available options.
 o main(String[])
Main method for testing this class.
 o maxNumClustersTipText()
Returns the tip text for this property
 o minNumClustersTipText()
Returns the tip text for this property
 o numberOfClusters()
Returns the number of clusters.
 o printRanges(Instances, double[][])
Function should be in the Instances class!! Prints a range.
 o seedTipText()
Returns the tip text for this property.
 o setBinValue(double)
Sets the distance e value between true and false of binary attributes and "same" and "different" of nominal attributes
 o setCutOffFactor(double)
Sets a new cutoff factor.
 o setDebugLevel(int)
Sets the debug level.
 o setDebugVektorsFile(String)
Sets a file name for a file that has the random vektors stored.
 o setDistanceF(DistanceFunction)
gets the "binary" distance value
 o setInputCenterFile(String)
Sets the name of the file to read the list of centers from.
 o setKDTree(KDTree)
Sets the KDTree class.
 o setMaxIterations(int)
Sets the maximum number of iterations to perform.
 o setMaxKMeans(int)
Set the maximum number of iterations to perform in KMeans
 o setMaxKMeansForChildren(int)
Sets the maximum number of iterations KMeans that is performed on the child centers.
 o setMaxNumClusters(int)
Sets the maximum number of clusters to generate.
 o setMinNumClusters(int)
Sets the minimum number of clusters to generate.
 o setOptions(String[])
Parses a given list of options.
 o setOutputCenterFile(String)
Sets the name of the file to write the list of centers to.
 o setSeed(int)
Sets the random number seed.
 o toString()
Return a string describing this clusterer.
 o updateRanges(Instance, int, double[][])
Function should be in the Instances class!! Updates the minimum and maximum and width values for all the attributes based on a new instance.
 o updateRangesFirst(Instance, int, double[][])
Function should be in the Instances class!! Used to initialize the ranges.

Field Detail

 o R_LOW
public static int R_LOW
          Index in ranges for LOW and HIGH and WIDTH
 o R_HIGH
public static int R_HIGH
 o R_WIDTH
public static int R_WIDTH
 o D_PRINTCENTERS
public static int D_PRINTCENTERS
 o D_FOLLOWSPLIT
public static int D_FOLLOWSPLIT
 o D_CONVCHCLOSER
public static int D_CONVCHCLOSER
 o D_RANDOMVEKTOR
public static int D_RANDOMVEKTOR
 o D_KDTREE
public static int D_KDTREE
 o D_ITERCOUNT
public static int D_ITERCOUNT
 o D_METH_MISUSE
public static int D_METH_MISUSE
 o D_CURR
public static int D_CURR
 o D_GENERAL
public static int D_GENERAL
 o m_CurrDebugFlag
public boolean m_CurrDebugFlag

Constructor Detail

 o XMeans
public XMeans()

Method Detail

 o globalInfo
public java.lang.String globalInfo()
          Returns a string describing this clusterer
Returns:
a description of the evaluator suitable for displaying in the explorer/experimenter gui
 o initializeRanges
public static double[][] initializeRanges(Instances instances,
                                          int instList[])
          Function should be in the Instances class!! Initializes the minimum and maximum values based on all instances.
Parameters:
instList - list of indexes
 o printRanges
public static void printRanges(Instances model,
                               double ranges[][])
          Function should be in the Instances class!! Prints a range.
Parameters:
ranges - the ranges to print
 o updateRangesFirst
public static void updateRangesFirst(Instance instance,
                                     int numAtt,
                                     double ranges[][])
          Function should be in the Instances class!! Used to initialize the ranges. For this the values of the first instance is used to save time. Sets low and high to the values of the first instance and width to zero.
Parameters:
instance - the new instance
numAtt - number of attributes in the model
 o updateRanges
public static void updateRanges(Instance instance,
                                int numAtt,
                                double ranges[][])
          Function should be in the Instances class!! Updates the minimum and maximum and width values for all the attributes based on a new instance.
Parameters:
instance - the new instance
numAtt - number of attributes in the model
ranges - low, high and width values for all attributes
 o buildClusterer
public void buildClusterer(Instances data) throws java.lang.Exception
          Generates the X-Means clusterer.
Parameters:
data - set of instances serving as training data
Throws:
java.lang.Exception - if the clusterer has not been generated successfully
Overrides:
buildClusterer in class Clusterer
 o checkForNominalAttributes
public boolean checkForNominalAttributes(Instances data)
          Checks for nominal attributes in the dataset. Class attribute is ignored.
Parameters:
data -
Returns:
false if no nominal attributes are present
 o clusterInstance
public int clusterInstance(Instance instance) throws java.lang.Exception
          Classifies a given instance.
Parameters:
instance - the instance to be assigned to a cluster
Returns:
the number of the assigned cluster as an integer if the class is enumerated, otherwise the predicted value
Throws:
if - instance could not be classified successfully
Overrides:
clusterInstance in class Clusterer
 o numberOfClusters
public int numberOfClusters()
          Returns the number of clusters.
Returns:
the number of clusters generated for a training dataset.
Overrides:
numberOfClusters in class Clusterer
 o listOptions
public java.util.Enumeration listOptions()
          Returns an enumeration describing the available options.
Returns:
an enumeration of all the available options
 o minNumClustersTipText
public java.lang.String minNumClustersTipText()
          Returns the tip text for this property
Returns:
tip text for this property
 o maxNumClustersTipText
public java.lang.String maxNumClustersTipText()
          Returns the tip text for this property
Returns:
tip text for this property
 o setMaxIterations
public void setMaxIterations(int i) throws java.lang.Exception
          Sets the maximum number of iterations to perform.
Parameters:
i - the number of iterations
Throws:
java.lang.Exception - if i is less than 1
 o getMaxIterations
public int getMaxIterations()
          Gets the maximum number of iterations.
Returns:
the number of iterations
 o setMaxKMeans
public void setMaxKMeans(int i)
          Set the maximum number of iterations to perform in KMeans
Parameters:
i - the number of iterations
 o getMaxKMeans
public int getMaxKMeans()
          Gets the maximum number of iterations in KMeans.
Returns:
the number of iterations
 o setMaxKMeansForChildren
public void setMaxKMeansForChildren(int i) throws java.lang.Exception
          Sets the maximum number of iterations KMeans that is performed on the child centers.
Parameters:
i - the number of iterations
 o getMaxKMeansForChildren
public int getMaxKMeansForChildren()
          Gets the maximum number of iterations in KMeans.
Returns:
the number of iterations
 o setCutOffFactor
public void setCutOffFactor(double i) throws java.lang.Exception
          Sets a new cutoff factor.
Parameters:
i - the new cutoff factor
 o getCutOffFactor
public double getCutOffFactor()
          Gets the cutoff factor.
Returns:
the cutoff factor
 o setMinNumClusters
public void setMinNumClusters(int n)
          Sets the minimum number of clusters to generate.
Parameters:
n - the minimum number of clusters to generate
 o setMaxNumClusters
public void setMaxNumClusters(int n)
          Sets the maximum number of clusters to generate.
Parameters:
n - the maximum number of clusters to generate
 o binValueTipText
public java.lang.String binValueTipText()
          Returns the tip text for this property
Returns:
tip text for this property suitable for displaying in the explorer/experimenter gui
 o getBinValue
public double getBinValue()
          Gets value that represents true in a new numeric attribute. (False is always represented by 0.0.)
Returns:
the value that represents true in a new numeric attribute
 o setBinValue
public void setBinValue(double value)
          Sets the distance e value between true and false of binary attributes and "same" and "different" of nominal attributes
Parameters:
double - value
 o setDistanceF
public void setDistanceF(DistanceFunction distanceF)
          gets the "binary" distance value
Parameters:
distanceF - the distance function with all options set
 o getDistanceF
public DistanceFunction getDistanceF()
          Gets the distance function.
Returns:
the distance function
 o setDebugVektorsFile
public void setDebugVektorsFile(java.lang.String fileName)
          Sets a file name for a file that has the random vektors stored. Just used for debugging reasons.
Parameters:
fileName - file name for the file to read the random vektors from
 o initDebugVektorsInput
public void initDebugVektorsInput() throws java.lang.Exception
          Initialises the debug vektor input.
 o getNextDebugVektorsInstance
public Instance getNextDebugVektorsInstance(Instances model) throws java.lang.Exception
          Read an instance from debug vektors file.
Parameters:
model - the data model for the instance
 o setInputCenterFile
public void setInputCenterFile(java.lang.String fileName)
          Sets the name of the file to read the list of centers from.
Parameters:
fileName - file name of file to read centers from
 o setOutputCenterFile
public void setOutputCenterFile(java.lang.String fileName)
          Sets the name of the file to write the list of centers to.
Parameters:
fileName - file to write centers to
 o getInputCenterFile
public java.lang.String getInputCenterFile()
          Gets the name of the file to read the list of centers from.
Returns:
filename of the file to read the centers from
 o getOutputCenterFile
public java.lang.String getOutputCenterFile()
          Gets the name of the file to write the list of centers to.
Returns:
filename of the file to write centers to
 o setKDTree
public void setKDTree(KDTree k)
          Sets the KDTree class.
Parameters:
k - a KDTree object with all options set
 o getKDTree
public KDTree getKDTree()
          Gets the KDTree class.
Returns:
flag if KDTrees are used
 o setDebugLevel
public void setDebugLevel(int d)
          Sets the debug level. debug level = 0, means no output
Parameters:
d - debuglevel
 o getDebugLevel
public int getDebugLevel()
          Gets the debug level.
Returns:
debug level
 o getMinNumClusters
public int getMinNumClusters()
          Gets the minimum number of clusters to generate.
Returns:
the minimum number of clusters to generate
 o getMaxNumClusters
public int getMaxNumClusters()
          Gets the maximum number of clusters to generate.
Returns:
the maximum number of clusters to generate
 o seedTipText
public java.lang.String seedTipText()
          Returns the tip text for this property.
Returns:
tip text for this property
 o setSeed
public void setSeed(int s)
          Sets the random number seed.
Parameters:
s - the seed
 o getSeed
public int getSeed()
          Gets the random number seed.
Returns:
the seed
 o setOptions
public void setOptions(java.lang.String options[]) throws java.lang.Exception
          Parses a given list of options.
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported
 o getOptions
public java.lang.String[] getOptions()
          Gets the current settings of SimpleKMeans.
Returns:
an array of strings suitable for passing to setOptions
 o toString
public java.lang.String toString()
          Return a string describing this clusterer.
Returns:
a description of the clusterer as a string
Overrides:
toString in class java.lang.Object
 o main
public static void main(java.lang.String argv[])
          Main method for testing this class.
Parameters:
argv - should contain options

All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home