Conditions | 4 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | public function initializeClusters(PointCollectionInterface $points, int $nbClusters): ClusterCollectionInterface |
||
16 | { |
||
17 | // validate cluster count |
||
18 | if ($nbClusters < 1) { |
||
19 | throw new \InvalidArgumentException("Invalid cluster count: {$nbClusters}"); |
||
20 | } |
||
21 | |||
22 | $clusters = new ClusterCollection($points->getSpace()); |
||
23 | |||
24 | // initialize N clusters with a random point within space boundaries |
||
25 | for ($n = 0; $n < $nbClusters; $n++) { |
||
26 | // assign all points to the first cluster only |
||
27 | $clusters->attach(new Cluster($this->getRandomPoint($points), $n == 0 ? $points : null)); |
||
28 | } |
||
29 | |||
30 | return $clusters; |
||
31 | } |
||
50 |