ml.clustering.KMeans Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstat Show documentation
Show all versions of jstat Show documentation
Java Library for Statistical Analysis.
The newest version!
package ml.clustering;
import utils.IterativeAlgorithmResult;
import datastructs.I2DDataSet;
import datastructs.IVector;
import maths.functions.distances.DistanceCalculator;
import maths.functions.generators.IRandomGenerator;
import java.util.List;
public class KMeans{
public class Cluster
{
public int id;
public IVector centroid;
public List points;
public >> void calculateCentorid(DataSetTp dataSet){
for(int i=0; i>,
SimilarityType extends DistanceCalculator, DistanceType>,
RandomGeneratorType extends IRandomGenerator>
IterativeAlgorithmResult cluster(final DataSetType data,
final SimilarityType similarity, final RandomGeneratorType centroidGenerator){
// assign the random centroids
List> centroidsOld = centroidGenerator.generate(data, this.input.k);
while(this.input.iterationContorller.continueIterations()){
if(this.input.showIterations){
System.out.println("KMeans iteration: " + this.input.iterationContorller.getCurrentIteration());
}
//for each point calculate its distance from the centroids
for(int p=0; p, DistanceType>> void clusterPoint(int pointId, IVector point, final SimilarityType similarity){
DistanceType dist = similarity.maxValue();
int clusterIdx = -1;
for(int c=0; c clusters;
}