Example usage for weka.core EuclideanDistance closestPoint

List of usage examples for weka.core EuclideanDistance closestPoint

Introduction

In this page you can find the example usage for weka.core EuclideanDistance closestPoint.

Prototype

public int closestPoint(Instance instance, Instances allPoints, int[] pointList) throws Exception 

Source Link

Document

Returns the index of the closest point to the current instance.

Usage

From source file:kmeans.MyKMeans.java

void clusteringInstance() {
    ArrayList<Integer> tempList = new ArrayList<Integer>();
    Instances tempInst = new Instances(dataSource, 0);
    EuclideanDistance ed = new EuclideanDistance(centroid);
    int[] pointList = new int[numCluster];
    int checkNumberChange = 0;
    for (int i = 0; i < numCluster; i++) {
        pointList[i] = i;/*from   w w w. j a  v  a 2s .c o  m*/
    }
    for (int i = 0; i < dataSource.numInstances(); i++) {
        int clusterNumber = -1;
        Instance currentInst = dataSource.get(i);
        try {
            clusterNumber = ed.closestPoint(currentInst, centroid, pointList);
        } catch (Exception ex) {
            System.out.println("************** " + ex.toString());
        }
        int clusterBefore = clusteredInstance.put(i, clusterNumber);
        if (clusterNumber != clusterBefore)
            checkNumberChange++;
    }
    if (checkNumberChange != 0)
        finish = false;
    else
        finish = true;
    updateListClusteredInstance();
    //  printListClusteredInstance();
}

From source file:kmeans_extend.MyKMeans.java

void clusteringInstance() {
    ArrayList<Integer> tempList = new ArrayList<Integer>();
    Instances tempInst = new Instances(dataSource, 0);
    EuclideanDistance ed = new EuclideanDistance(centroid);
    int[] pointList = new int[noOfClusters];
    int checkNumberChange = 0;
    for (int i = 0; i < noOfClusters; i++) {
        pointList[i] = i;//from   w  w  w  .ja  v  a2  s  .c  o m
    }
    for (int i = 0; i < dataSource.numInstances(); i++) {
        int clusterNumber = -1;
        Instance currentInst = dataSource.get(i);
        try {
            clusterNumber = ed.closestPoint(currentInst, centroid, pointList);
        } catch (Exception ex) {
            System.out.println("************** " + ex.toString());
        }
        int clusterBefore = clusteredInstance.put(i, clusterNumber);
        if (clusterNumber != clusterBefore)
            checkNumberChange++;
    }
    if (checkNumberChange != 0)
        finish = false;
    else
        finish = true;
    updateListClusteredInstance();
    //  printListClusteredInstance();
}

From source file:kmeans_extend.MyKMeans.java

public int clusterInstance(Instance instance) {
    int clusterNo = -1;
    EuclideanDistance ed = new EuclideanDistance(centroid);
    int[] pointList = new int[noOfClusters];
    for (int i = 0; i < noOfClusters; i++) {
        pointList[i] = i;//from   www . j a  v a 2 s  . c  om
    }
    try {
        clusterNo = ed.closestPoint(instance, centroid, pointList);
    } catch (Exception ex) {
        System.out.println("************** " + ex.toString());
    }
    return clusterNo;
}