Improve micro performance (#21)

* remove unused variable

* added kmeans++ initialize method

referred to https://www.kdnuggets.com/2020/06/centroid-initialization-k-means-clustering.html

* removed unused code

* Remove unnecessary if state logic int the for loop
This commit is contained in:
battlecook 2021-08-31 20:53:48 +09:00 committed by GitHub
parent eded4796cd
commit 38cbae7c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,17 +62,13 @@ class Point implements \ArrayAccess
return $precise ? sqrt($distance) : $distance;
}
public function getClosest(iterable $points): Point
public function getClosest(iterable $points): ?Point
{
$minDistance = PHP_INT_MAX;
$minPoint = null;
foreach ($points as $point) {
$distance = $this->getDistanceWith($point, false);
if (!isset($minDistance)) {
$minDistance = $distance;
$minPoint = $point;
continue;
}
if ($distance < $minDistance) {
$minDistance = $distance;
$minPoint = $point;