jsat.clustering.kmeans
Class MiniBatchKMeans
- java.lang.Object
-
- jsat.clustering.ClustererBase
-
- jsat.clustering.KClustererBase
-
- jsat.clustering.kmeans.MiniBatchKMeans
-
- All Implemented Interfaces:
- java.io.Serializable, Clusterer, KClusterer
public class MiniBatchKMeans extends KClustererBase
Implements the mini-batch algorithms for k-means. This is a stochastic algorithm, so it does not find the global solution. This implementation is parallel, but only the methods that specify the exact number of clusters are supported.
See: Sculley, D. (2010). Web-scale k-means clustering. Proceedings of the 19th international conference on World wide web (pp. 1177–1178). New York, New York, USA: ACM Press. doi:10.1145/1772690.1772862- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description MiniBatchKMeans(DistanceMetric dm, int batchSize, int iterations)Creates a new Mini-Batch k-Means object that usesk-means++for seed selection.MiniBatchKMeans(DistanceMetric dm, int batchSize, int iterations, SeedSelectionMethods.SeedSelection seedSelection)Creates a new Mini-Batch k-Means objectMiniBatchKMeans(int batchSize, int iterations)Creates a new Mini-Batch k-Means object that usesk-means++for seed selection and uses theEuclideanDistance.MiniBatchKMeans(MiniBatchKMeans toCopy)Copy constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description MiniBatchKMeansclone()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 clusters, boolean parallel, int[] designations)int[]cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)intgetBatchSize()Returns the batch size used at each iterationDistanceMetricgetDistanceMetric()Returns the distance metric used for determining the nearest cluster centerintgetIterations()Returns the number of mini-batch iterations usedjava.util.List<Vec>getMeans()Returns the raw list of means that were used for each class.SeedSelectionMethods.SeedSelectiongetSeedSelection()Returns the method of seed selection to usevoidsetBatchSize(int batchSize)Sets the batch size to use at each iteration.voidsetDistanceMetric(DistanceMetric dm)Sets the distance metric used for determining the nearest cluster centervoidsetIterations(int iterations)Sets the number of mini-batch iterations to performvoidsetSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)Sets the method of selecting the initial data points to seed the clustering algorithm.voidsetStoreMeans(boolean storeMeans)If set totruethe computed means will be stored after clustering is completed, and can then be retrieved usinggetMeans().-
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.clustering.KClusterer
cluster, cluster, cluster, cluster, cluster, cluster
-
Methods inherited from interface jsat.clustering.Clusterer
cluster, cluster, supportsWeightedData
-
-
-
-
Constructor Detail
-
MiniBatchKMeans
public MiniBatchKMeans(int batchSize, int iterations)Creates a new Mini-Batch k-Means object that usesk-means++for seed selection and uses theEuclideanDistance.- Parameters:
batchSize- the mini-batch sizeiterations- the number of mini batches to perform
-
MiniBatchKMeans
public MiniBatchKMeans(DistanceMetric dm, int batchSize, int iterations)
Creates a new Mini-Batch k-Means object that usesk-means++for seed selection.- Parameters:
dm- the distance metric to usebatchSize- the mini-batch sizeiterations- the number of mini batches to perform
-
MiniBatchKMeans
public MiniBatchKMeans(DistanceMetric dm, int batchSize, int iterations, SeedSelectionMethods.SeedSelection seedSelection)
Creates a new Mini-Batch k-Means object- Parameters:
dm- the distance metric to usebatchSize- the mini-batch sizeiterations- the number of mini batches to performseedSelection- the seed selection algorithm to initiate clustering
-
MiniBatchKMeans
public MiniBatchKMeans(MiniBatchKMeans toCopy)
Copy constructor- Parameters:
toCopy- the object to copy
-
-
Method Detail
-
setStoreMeans
public void setStoreMeans(boolean storeMeans)
If set totruethe computed means will be stored after clustering is completed, and can then be retrieved usinggetMeans().- Parameters:
storeMeans-trueif the means should be stored for later,falseto discard them once clustering is complete.
-
getMeans
public java.util.List<Vec> getMeans()
Returns the raw list of means that were used for each class.- Returns:
- the list of means for each class
-
setDistanceMetric
public void setDistanceMetric(DistanceMetric dm)
Sets the distance metric used for determining the nearest cluster center- Parameters:
dm- the distance metric to use
-
getDistanceMetric
public DistanceMetric getDistanceMetric()
Returns the distance metric used for determining the nearest cluster center- Returns:
- the distance metric in use
-
setBatchSize
public void setBatchSize(int batchSize)
Sets the batch size to use at each iteration. Increasing the batch size can improve the resulting clustering, but increases computational cost at each iteration.
If the batch size is set equal to or larger than data set size, it reduces to thenaive k-meansalgorithm.- Parameters:
batchSize- the number of points to use at each iteration
-
getBatchSize
public int getBatchSize()
Returns the batch size used at each iteration- Returns:
- the batch size in use
-
setIterations
public void setIterations(int iterations)
Sets the number of mini-batch iterations to perform- Parameters:
iterations- the number of algorithm iterations to perform
-
getIterations
public int getIterations()
Returns the number of mini-batch iterations used- Returns:
- the number of algorithm iterations that will be used
-
setSeedSelection
public void setSeedSelection(SeedSelectionMethods.SeedSelection seedSelection)
Sets the method of selecting the initial data points to seed the clustering algorithm.- Parameters:
seedSelection- the seed selection algorithm to use
-
getSeedSelection
public SeedSelectionMethods.SeedSelection getSeedSelection()
Returns the method of seed selection to use- Returns:
- the method of seed selection to use
-
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.- 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.- 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 clusters, boolean parallel, int[] designations)
-
cluster
public int[] cluster(DataSet dataSet, int lowK, int highK, boolean parallel, int[] designations)
-
clone
public MiniBatchKMeans clone()
- Specified by:
clonein interfaceClusterer- Specified by:
clonein interfaceKClusterer- Specified by:
clonein classKClustererBase
-
-
DataMelt 3.0 © DataMelt by jWork.ORG