minor code style fixes

This commit is contained in:
Dennis Eichhorn 2022-09-08 19:18:16 +02:00
parent f4dcb64af0
commit 7c8469c114
2 changed files with 17 additions and 14 deletions

View File

@ -100,6 +100,18 @@ final class Kmeans
return $bestCluster; return $bestCluster;
} }
/**
* Get cluster centroids
*
* @return array
*
* @since 1.0.0
*/
public function getCentroids() : array
{
return $this->clusterCenters;
}
/** /**
* Generate the clusters of the points * Generate the clusters of the points
* *
@ -149,7 +161,7 @@ final class Kmeans
if ($min !== $point->group) { if ($min !== $point->group) {
++$changed; ++$changed;
$point->group = ($min); $point->group = $min;
} }
} }
@ -159,7 +171,7 @@ final class Kmeans
} }
foreach ($clusterCenters as $key => $center) { foreach ($clusterCenters as $key => $center) {
$center->group = ($key); $center->group = $key;
$center->name = (string) $key; $center->name = (string) $key;
} }

View File

@ -314,10 +314,6 @@ final class StringUtils
$n1 = \count($from); $n1 = \count($from);
$n2 = \count($to); $n2 = \count($to);
if ($n1 < 1 || $n2 < 1) {
throw new \Exception(); // @codeCoverageIgnore
}
for ($j = -1; $j < $n2; ++$j) { for ($j = -1; $j < $n2; ++$j) {
$dm[-1][$j] = 0; $dm[-1][$j] = 0;
} }
@ -328,14 +324,9 @@ final class StringUtils
for ($i = 0; $i < $n1; ++$i) { for ($i = 0; $i < $n1; ++$i) {
for ($j = 0; $j < $n2; ++$j) { for ($j = 0; $j < $n2; ++$j) {
if ($from[$i] === $to[$j]) { $dm[$i][$j] = $from[$i] === $to[$j]
$ad = $dm[$i - 1][$j - 1]; ? $dm[$i - 1][$j - 1] + 1
$dm[$i][$j] = $ad + 1; : \max($$dm[$i - 1][$j], $dm[$i][$j - 1]);
} else {
$a1 = $dm[$i - 1][$j];
$a2 = $dm[$i][$j - 1];
$dm[$i][$j] = \max($a1, $a2);
}
} }
} }