jminhep.algorithms
Class KMeansAlg
- java.lang.Object
-
- jminhep.algorithms.KMeansAlg
-
public class KMeansAlg extends java.lang.ObjectThe standard K-means algorithm.
-
-
Constructor Summary
Constructors Constructor and Description KMeansAlg(DataHolder data)Initialize the standard K-means algorithm
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voiddelete()ClearvoidgenerateSeed()Generate random seeds for initial centroidsDataHoldergetCenters()Returns cluster centersintgetClusters()Get number of clustersdoublegetCompactness()This method returns the CompactnessintgetError()Return errorjava.lang.StringgetName()Name for this algorithm.int[]getNumberPoints()Returns the number of points in each clusterdouble[][]getSeed()Return seedsDataHoldergetSeedHolder()Get positions of seedslonggetSize()This method returns the estimated size (steps) for this task.voidrun()Run classic K-Means clustering algorithm.voidrun(int Iter)Runs the k-means several iterations to find best seed values Only iteration with the best compactness is taken.voidrunKM()Classic K-Means clustering algorithm.voidsetClusters(int numClusters)Set the designed number of clustersvoidsetOptions(int maxIterations, double epsilon)Set initial options for calculationsvoidsetSeed(double[][] seed)Set seeds by hand
-
-
-
Constructor Detail
-
KMeansAlg
public KMeansAlg(DataHolder data)
Initialize the standard K-means algorithm- Parameters:
data- input data
-
-
Method Detail
-
setClusters
public void setClusters(int numClusters)
Set the designed number of clusters- Parameters:
numClusters- expected number of clusters
-
getClusters
public int getClusters()
Get number of clusters- Returns:
- number of clusters
-
generateSeed
public void generateSeed()
Generate random seeds for initial centroids
-
setSeed
public void setSeed(double[][] seed)
Set seeds by hand- Parameters:
seed- positions of seeds
-
getSeed
public double[][] getSeed()
Return seeds- Returns:
- seeds
-
setOptions
public void setOptions(int maxIterations, double epsilon)Set initial options for calculations- Parameters:
maxIterations- the maximum number of iterations.epsilon- a small value used to verify if clustering has converged.
-
delete
public void delete()
Clear
-
getCenters
public DataHolder getCenters()
Returns cluster centers- Returns:
- DataHolder with center positions
-
getSeedHolder
public DataHolder getSeedHolder()
Get positions of seeds- Returns:
- seed positions
-
getNumberPoints
public int[] getNumberPoints()
Returns the number of points in each cluster- Returns:
- int[] getNumberPoints
-
run
public void run()
Run classic K-Means clustering algorithm. Seeds will be generated automatically
-
runKM
public void runKM()
Classic K-Means clustering algorithm. Seeds are not set. Instead, consider the method run()
-
getCompactness
public double getCompactness()
This method returns the Compactness- Returns:
- compactness value
-
run
public void run(int Iter)
Runs the k-means several iterations to find best seed values Only iteration with the best compactness is taken.- Parameters:
Iter- Number of iterations
-
getError
public int getError()
Return error- Returns:
- zero if no errors
-
getSize
public long getSize()
This method returns the estimated size (steps) for this task.
-
getName
public java.lang.String getName()
Name for this algorithm.- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG