mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
kmeans initialization by equi-distant distribution across elements
This commit is contained in:
1 parent
be843c8ddf
commit
4c068647bc
15 files changed
+414
-185
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
package com.sap.sailing.domain.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.ScalableInteger;
|
||||
import com.sap.sailing.util.kmeans.Cluster;
|
||||
import com.sap.sailing.util.kmeans.KMeansClustererForComparables;
|
||||
|
||||
public class KMeansTest {
|
||||
@Test
|
||||
public void simpleIntegerTest() {
|
||||
KMeansClustererForComparables<Integer, Integer, ScalableInteger> clusterer = new KMeansClustererForComparables<>(4,
|
||||
Arrays.asList(new ScalableInteger(1), new ScalableInteger(1), new ScalableInteger(11), new ScalableInteger(11), new ScalableInteger(21), new ScalableInteger(21), new ScalableInteger(31), new ScalableInteger(31)));
|
||||
Set<Cluster<Integer, Integer, ScalableInteger>> clusters = clusterer.getClusters();
|
||||
assertEquals(4, clusters.size());
|
||||
Set<Integer> clusterCentroids = new HashSet<>();
|
||||
clusters.stream().map((c)->c.getCentroid()).forEach((e)->clusterCentroids.add(e));
|
||||
assertEquals(new HashSet<Integer>(Arrays.asList(1, 11, 21, 31)), clusterCentroids);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user