Skip to content

Commit 44f5a4a

Browse files
committed
updating demo.php
1 parent 071ebd2 commit 44f5a4a

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

demo.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,21 @@
1616
];
1717

1818
// create a 2-dimentions space
19-
$space = new Kmeans\Space(2);
19+
$space = new Kmeans\Euclidean\Space(2);
2020

2121
// prepare the points
22-
$points = new Kmeans\PointCollection($space);
23-
24-
foreach ($data as $coordinates) {
25-
$points->attach(new Kmeans\Point($space, $coordinates));
26-
}
22+
$points = new Kmeans\PointCollection($space, array_map([$space, 'makePoint'], $data));
2723

2824
// prepare the algorithm
29-
$algorithm = new Kmeans\Algorithm(new Kmeans\RandomInitialization());
25+
$algorithm = new Kmeans\Euclidean\Algorithm(new Kmeans\RandomInitialization());
3026

3127
// cluster these 50 points in 3 clusters
3228
$clusters = $algorithm->clusterize($points, 3);
3329

3430
// display the cluster centers and attached points
3531
foreach ($clusters as $num => $cluster) {
3632
$coordinates = $cluster->getCentroid()->getCoordinates();
33+
assert(is_int($num));
3734
printf(
3835
"Cluster #%s [%d,%d] has %d points\n",
3936
$num,

0 commit comments

Comments
 (0)