emilklindt/laravel-marker-clusterer

Use distance in K-means convergence check

emilklindt opened this issue · 0 comments

Change convergence check for K-means to use distance instead of direct equality, allowing for minor changes in centroid from iteration to iteration, providing better performance without being critical to result quality.

private function hasConverged(Collection $centroids): bool
{
return $this->clusters
->every(function (Cluster $cluster, int $index) use ($centroids) {
return $cluster->centroid == $centroids->get($index);
});
}