Skip to content

Commit

Permalink
Euclidean optimization (#42)
Browse files Browse the repository at this point in the history
* Euclidean optimization

* Euclidean with foreach
  • Loading branch information
MustafaKarabulut authored and akondas committed Feb 9, 2017
1 parent 1d73503 commit 0a58a71
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Phpml/Math/Distance/Euclidean.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ public function distance(array $a, array $b): float
}

$distance = 0;
$count = count($a);

for ($i = 0; $i < $count; ++$i) {
$distance += pow($a[$i] - $b[$i], 2);
foreach ($a as $i => $val) {
$distance += ($val - $b[$i]) ** 2;
}

return sqrt((float) $distance);
Expand Down

0 comments on commit 0a58a71

Please sign in to comment.