mirror of
https://github.com/bdelespierre/php-kmeans.git
synced 2025-01-17 12:38:28 +01:00
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:
parent
eded4796cd
commit
38cbae7c38
@ -62,17 +62,13 @@ class Point implements \ArrayAccess
|
|||||||
return $precise ? sqrt($distance) : $distance;
|
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) {
|
foreach ($points as $point) {
|
||||||
$distance = $this->getDistanceWith($point, false);
|
$distance = $this->getDistanceWith($point, false);
|
||||||
|
|
||||||
if (!isset($minDistance)) {
|
|
||||||
$minDistance = $distance;
|
|
||||||
$minPoint = $point;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($distance < $minDistance) {
|
if ($distance < $minDistance) {
|
||||||
$minDistance = $distance;
|
$minDistance = $distance;
|
||||||
$minPoint = $point;
|
$minPoint = $point;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user