mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
hopefully fixed devision by 0
This commit is contained in:
parent
18c11fb229
commit
f5494f4b31
|
|
@ -91,11 +91,11 @@ final class Kmeans
|
|||
*
|
||||
* @param PointInterface $point Point to find the cluster for
|
||||
*
|
||||
* @return PointInterface
|
||||
* @return null|PointInterface
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function cluster(PointInterface $point) : PointInterface
|
||||
public function cluster(PointInterface $point) : ?PointInterface
|
||||
{
|
||||
$bestCluster = null;
|
||||
$bestDistance = \PHP_FLOAT_MAX;
|
||||
|
|
@ -132,7 +132,7 @@ final class Kmeans
|
|||
$center->setCoordinate($i, 0);
|
||||
}
|
||||
|
||||
$center->setGroup(0);
|
||||
//$center->setGroup(0); done because of bug below?!
|
||||
}
|
||||
|
||||
foreach ($points as $point) {
|
||||
|
|
@ -149,6 +149,7 @@ final class Kmeans
|
|||
|
||||
foreach ($clusterCenters as $center) {
|
||||
for ($i = 0; $i < $coordinates; ++$i) {
|
||||
// todo: here is a bug sometimes center->getGroup() is 0
|
||||
$center->setCoordinate($i, $center->getCoordinate($i) / $center->getGroup());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user