jsat.clustering.kmeans
Class XMeans
- java.lang.Object
-
- jsat.clustering.ClustererBase
-
- jsat.clustering.KClustererBase
-
- jsat.clustering.kmeans.KMeans
-
- jsat.clustering.kmeans.XMeans
-
- All Implemented Interfaces:
- java.io.Serializable, Clusterer, KClusterer, Parameterized
public class XMeans extends KMeans
This class provides a method of performingKMeansclustering when the value ofKis not known. It works by recursively splitting means up to some specified maximum. value.
When the value ofKis specified, the implementation will simply call the regular KMeans object it was constructed with.
Note, that specifying a minimum value ofK=1has a tendency to not be split by the algorithm, returning the naive result of 1 cluster. It is better to use at leastK=2as the default minimum, which is what the implementation will start from when no range ofKis given.
See: Pelleg, D.,&Moore, A. (2000). X-means: Extending K-means with Efficient Estimation of the Number of Clusters. In ICML (pp. 727–734). San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. Retrieved from here- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class jsat.clustering.kmeans.KMeans
DEFAULT_SEED_SELECTION
-
-
Constructor Summary
Constructors Constructor and Description XMeans()XMeans(KMeans kmeans)XMeans(XMeans toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description XMeansclone()int[]cluster(DataSet dataSet, boolean parallel, int[] designations)Performs clustering on the given data set.int[]cluster(DataSet dataSet, int[] designations)Performs clustering on the given data set.int[]cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)intgetIterationLimit()Returns the maximum number of iterations of the ElkanKMeans algorithm that will be performed.booleangetIterativeRefine()intgetMinClusterSize()SeedSelectionMethods.SeedSelectiongetSeedSelection()booleanisStopAfterFail()voidsetIterationLimit(int iterLimit)Sets the maximum number of iterations allowedvoidsetIterativeRefine(boolean refineCenters)Sets whether or not the set of all cluster centers should be refined at every iteration.voidsetMinClusterSize(int minClusterSize)Sets the minimum size for splitting a cluster.voidsetSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)Sets the method of seed selection to use for this algorithm.voidsetStopAfterFail(boolean stopAfterFail)Each new cluster will be tested for improvement according to the BIC metric.-
Methods inherited from class jsat.clustering.kmeans.KMeans
cluster, getDistanceMetric, getMeans, setStoreMeans, supportsWeightedData
-
Methods inherited from class jsat.clustering.ClustererBase
createClusterListFromAssignmentArray, getDatapointsFromCluster
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
XMeans
public XMeans()
-
XMeans
public XMeans(KMeans kmeans)
-
XMeans
public XMeans(XMeans toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setStopAfterFail
public void setStopAfterFail(boolean stopAfterFail)
Each new cluster will be tested for improvement according to the BIC metric. If this is set totruethen an optimization is done that once a center fails be improved by splitting, it will never be tested again. This is a safe assumption whensetIterativeRefine(boolean)is set tofalse, but otherwise may not quite be true.
WhentrustH0istrue, X-Means will make at most O(k) runs of k-means for the final value of k chosen. Whenfalse(the default option), at most O(k2) runs of k-means will occur.- Parameters:
stopAfterFail-trueif a centroid shouldn't be re-tested once it fails to split.
-
isStopAfterFail
public boolean isStopAfterFail()
- Returns:
trueif clusters that fail to split wont be re-tested.falseif they will.
-
setMinClusterSize
public void setMinClusterSize(int minClusterSize)
Sets the minimum size for splitting a cluster.- Parameters:
minClusterSize- the minimum number of data points that must be present in a cluster to consider splitting it
-
getMinClusterSize
public int getMinClusterSize()
- Returns:
- the minimum number of data points that must be present in a cluster to consider splitting it
-
setIterativeRefine
public void setIterativeRefine(boolean refineCenters)
Sets whether or not the set of all cluster centers should be refined at every iteration. By default this istrueand part of how the X-Means algorithm is described. Setting this tofalsecan result in large speedups at the potential cost of quality.- Parameters:
refineCenters-trueto refine the cluster centers at every step,falseto skip this step of the algorithm.
-
getIterativeRefine
public boolean getIterativeRefine()
- Returns:
trueif the cluster centers are refined at every step,falseif skipping this step of the algorithm.
-
cluster
public int[] cluster(DataSet dataSet, int[] designations)
Description copied from interface:ClustererPerforms clustering on the given data set. Parameters may be estimated by the method, or other heuristics performed.- Specified by:
clusterin interfaceClusterer- Overrides:
clusterin classKMeans- Parameters:
dataSet- the data set to perform clustering ondesignations- the array which will contain the designated values. The array will be altered and returned by the function. If null is given, a new array will be created and returned.- Returns:
- an array indicating for each value indicating the cluster designation. This is the same array as designations, or a new one if the input array was null
-
cluster
public int[] cluster(DataSet dataSet, boolean parallel, int[] designations)
Description copied from interface:ClustererPerforms clustering on the given data set. Parameters may be estimated by the method, or other heuristics performed.- Specified by:
clusterin interfaceClusterer- Overrides:
clusterin classKMeans- Parameters:
dataSet- the data set to perform clustering onparallel-trueif multiple threads should be used to perform clustering.falseif it should be done in a single threaded manner.designations- the array which will contain the designated values. The array will be altered and returned by the function. If null is given, a new array will be created and returned.- Returns:
- the int[]
-
cluster
public int[] cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)
- Specified by:
clusterin interfaceKClusterer- Overrides:
clusterin classKMeans
-
getIterationLimit
public int getIterationLimit()
Description copied from class:KMeansReturns the maximum number of iterations of the ElkanKMeans algorithm that will be performed.- Overrides:
getIterationLimitin classKMeans- Returns:
- the maximum number of iterations of the ElkanKMeans algorithm that will be performed.
-
setIterationLimit
public void setIterationLimit(int iterLimit)
Description copied from class:KMeansSets the maximum number of iterations allowed- Overrides:
setIterationLimitin classKMeans- Parameters:
iterLimit- the maximum number of iterations of the ElkanKMeans algorithm
-
setSeedSelection
public void setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
Description copied from class:KMeansSets the method of seed selection to use for this algorithm.SeedSelectionMethods.SeedSelection.KPPis recommended for this algorithm in particular.- Overrides:
setSeedSelectionin classKMeans- Parameters:
seedSelection- the method of seed selection to use
-
getSeedSelection
public SeedSelectionMethods.SeedSelection getSeedSelection()
- Overrides:
getSeedSelectionin classKMeans- Returns:
- the method of seed selection used
-
-
DataMelt 3.0 © DataMelt by jWork.ORG