diff --git a/Algorithm/Clustering/Kmeans.php b/Algorithm/Clustering/Kmeans.php index 202bea746..11b04c2d0 100644 --- a/Algorithm/Clustering/Kmeans.php +++ b/Algorithm/Clustering/Kmeans.php @@ -100,6 +100,18 @@ final class Kmeans return $bestCluster; } + /** + * Get cluster centroids + * + * @return array + * + * @since 1.0.0 + */ + public function getCentroids() : array + { + return $this->clusterCenters; + } + /** * Generate the clusters of the points * @@ -149,7 +161,7 @@ final class Kmeans if ($min !== $point->group) { ++$changed; - $point->group = ($min); + $point->group = $min; } } @@ -159,7 +171,7 @@ final class Kmeans } foreach ($clusterCenters as $key => $center) { - $center->group = ($key); + $center->group = $key; $center->name = (string) $key; } diff --git a/Utils/StringUtils.php b/Utils/StringUtils.php index e3024ee78..011c466ec 100644 --- a/Utils/StringUtils.php +++ b/Utils/StringUtils.php @@ -314,10 +314,6 @@ final class StringUtils $n1 = \count($from); $n2 = \count($to); - if ($n1 < 1 || $n2 < 1) { - throw new \Exception(); // @codeCoverageIgnore - } - for ($j = -1; $j < $n2; ++$j) { $dm[-1][$j] = 0; } @@ -328,14 +324,9 @@ final class StringUtils for ($i = 0; $i < $n1; ++$i) { for ($j = 0; $j < $n2; ++$j) { - if ($from[$i] === $to[$j]) { - $ad = $dm[$i - 1][$j - 1]; - $dm[$i][$j] = $ad + 1; - } else { - $a1 = $dm[$i - 1][$j]; - $a2 = $dm[$i][$j - 1]; - $dm[$i][$j] = \max($a1, $a2); - } + $dm[$i][$j] = $from[$i] === $to[$j] + ? $dm[$i - 1][$j - 1] + 1 + : \max($$dm[$i - 1][$j], $dm[$i][$j - 1]); } }