Skip to content

Commit

Permalink
updating demo.php
Browse files Browse the repository at this point in the history
  • Loading branch information
bdelespierre committed May 4, 2022
1 parent 071ebd2 commit 44f5a4a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@
];

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

// prepare the points
$points = new Kmeans\PointCollection($space);

foreach ($data as $coordinates) {
$points->attach(new Kmeans\Point($space, $coordinates));
}
$points = new Kmeans\PointCollection($space, array_map([$space, 'makePoint'], $data));

// prepare the algorithm
$algorithm = new Kmeans\Algorithm(new Kmeans\RandomInitialization());
$algorithm = new Kmeans\Euclidean\Algorithm(new Kmeans\RandomInitialization());

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

// display the cluster centers and attached points
foreach ($clusters as $num => $cluster) {
$coordinates = $cluster->getCentroid()->getCoordinates();
assert(is_int($num));
printf(
"Cluster #%s [%d,%d] has %d points\n",
$num,
Expand Down

0 comments on commit 44f5a4a

Please sign in to comment.