All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ml.clustering.KMeans Maven / Gradle / Ivy

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;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy