mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 06:28: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
|
* @param PointInterface $point Point to find the cluster for
|
||||||
*
|
*
|
||||||
* @return PointInterface
|
* @return null|PointInterface
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function cluster(PointInterface $point) : PointInterface
|
public function cluster(PointInterface $point) : ?PointInterface
|
||||||
{
|
{
|
||||||
$bestCluster = null;
|
$bestCluster = null;
|
||||||
$bestDistance = \PHP_FLOAT_MAX;
|
$bestDistance = \PHP_FLOAT_MAX;
|
||||||
|
|
@ -132,7 +132,7 @@ final class Kmeans
|
||||||
$center->setCoordinate($i, 0);
|
$center->setCoordinate($i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$center->setGroup(0);
|
//$center->setGroup(0); done because of bug below?!
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($points as $point) {
|
foreach ($points as $point) {
|
||||||
|
|
@ -149,6 +149,7 @@ final class Kmeans
|
||||||
|
|
||||||
foreach ($clusterCenters as $center) {
|
foreach ($clusterCenters as $center) {
|
||||||
for ($i = 0; $i < $coordinates; ++$i) {
|
for ($i = 0; $i < $coordinates; ++$i) {
|
||||||
|
// todo: here is a bug sometimes center->getGroup() is 0
|
||||||
$center->setCoordinate($i, $center->getCoordinate($i) / $center->getGroup());
|
$center->setCoordinate($i, $center->getCoordinate($i) / $center->getGroup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user