use of org.apache.ignite.ml.math.distances.EuclideanDistance in project ignite by apache.
the class KMeansDistributedClustererTestMultiNode method testClusterizationOnDatasetWithObviousStructure.
/**
*/
public void testClusterizationOnDatasetWithObviousStructure() throws IOException {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
int ptsCnt = 10000;
int squareSideLen = 10000;
Random rnd = new Random(123456L);
// Let centers be in the vertices of square.
Map<Integer, Vector> centers = new HashMap<>();
centers.put(100, new DenseLocalOnHeapVector(new double[] { 0.0, 0.0 }));
centers.put(900, new DenseLocalOnHeapVector(new double[] { squareSideLen, 0.0 }));
centers.put(3000, new DenseLocalOnHeapVector(new double[] { 0.0, squareSideLen }));
centers.put(6000, new DenseLocalOnHeapVector(new double[] { squareSideLen, squareSideLen }));
SparseDistributedMatrix points = new SparseDistributedMatrix(ptsCnt, 2, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
List<Integer> permutation = IntStream.range(0, ptsCnt).boxed().collect(Collectors.toList());
Collections.shuffle(permutation, rnd);
int totalCnt = 0;
for (Integer count : centers.keySet()) {
for (int i = 0; i < count; i++) {
Vector pnt = new DenseLocalOnHeapVector(2).assign(centers.get(count));
// Perturbate point on random value.
pnt.map(val -> val + rnd.nextDouble() * squareSideLen / 100);
points.assignRow(permutation.get(totalCnt), pnt);
totalCnt++;
}
}
EuclideanDistance dist = new EuclideanDistance();
KMeansDistributedClusterer clusterer = new KMeansDistributedClusterer(dist, 3, 100, 1L);
clusterer.cluster(points, 4);
points.destroy();
}
use of org.apache.ignite.ml.math.distances.EuclideanDistance in project ignite by apache.
the class KMeansDistributedClustererTestMultiNode method testPerformClusterAnalysisDegenerate.
/**
*/
public void testPerformClusterAnalysisDegenerate() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
KMeansDistributedClusterer clusterer = new KMeansDistributedClusterer(new EuclideanDistance(), 1, 1, 1L);
double[] v1 = new double[] { 1959, 325100 };
double[] v2 = new double[] { 1960, 373200 };
SparseDistributedMatrix points = new SparseDistributedMatrix(2, 2, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
points.setRow(0, v1);
points.setRow(1, v2);
clusterer.cluster(points, 1);
points.destroy();
}
Aggregations