Search in sources :

Example 1 with KMeansPlusPlusClusterer

use of org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer in project imagingbook-common by imagingbook.

the class KMeansClusteringQuantizerApache method cluster.

// --------------------------------------------------------------
private List<CentroidCluster<DoublePoint>> cluster(int[] pixels) {
    KMeansPlusPlusClusterer<DoublePoint> clusterer = new KMeansPlusPlusClusterer<>(params.maxColors, params.maxIterations);
    List<DoublePoint> points = new ArrayList<>();
    for (int i = 0; i < pixels.length; i++) {
        points.add(new DoublePoint(intToRgbDouble(pixels[i])));
    }
    return clusterer.cluster(points);
}
Also used : DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) ArrayList(java.util.ArrayList) KMeansPlusPlusClusterer(org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint)

Example 2 with KMeansPlusPlusClusterer

use of org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer in project ACManager by kun368.

the class MyTest2 method test6.

@Test
public void test6() throws Exception {
    Clusterer<DoublePoint> clusterer = new KMeansPlusPlusClusterer<DoublePoint>(3);
    List<DoublePoint> list = new ArrayList<>();
    list.add(new DoublePoint(new double[] { 1 }));
    list.add(new DoublePoint(new double[] { 1.5 }));
    list.add(new DoublePoint(new double[] { 1.8 }));
    list.add(new DoublePoint(new double[] { 3.5 }));
    list.add(new DoublePoint(new double[] { 3.6 }));
    list.add(new DoublePoint(new double[] { 4 }));
    list.add(new DoublePoint(new double[] { 4.2 }));
    System.out.println(list);
    List<? extends Cluster<DoublePoint>> res = clusterer.cluster(list);
    System.out.println("!!!");
    System.out.println(res.size());
    for (Cluster<DoublePoint> re : res) {
        System.out.println(re.getPoints());
    }
}
Also used : DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) KMeansPlusPlusClusterer(org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer) Test(org.junit.Test)

Aggregations

DoublePoint (org.apache.commons.math3.ml.clustering.DoublePoint)2 KMeansPlusPlusClusterer (org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1