From 5e34596b985fc253f8342dfaf1dfb9aa5c56f780 Mon Sep 17 00:00:00 2001 From: Benjamin Delespierre Date: Fri, 2 Apr 2021 00:20:07 +0200 Subject: [PATCH] updating readme (and demo) #11 --- README.md | 2 +- demo.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 demo.php diff --git a/README.md b/README.md index 39cbe90..a42620b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ foreach ($clusters as $num => $cluster) { $num, $coordinates[0], $coordinates[1], - count($cluster->getPoints()) + count($cluster) ); } ``` diff --git a/demo.php b/demo.php new file mode 100644 index 0000000..408ad99 --- /dev/null +++ b/demo.php @@ -0,0 +1,40 @@ + $coordinates) { + $space->addPoint($coordinates); +} + +// cluster these 50 points in 3 clusters +$clusters = $space->solve(3); + +// display the cluster centers and attached points +foreach ($clusters as $num => $cluster) { + $coordinates = $cluster->getCoordinates(); + printf( + "Cluster %s [%d,%d]: %d points\n", + $num, + $coordinates[0], + $coordinates[1], + count($cluster) + ); +}