fix matrix exp and cosine metric

This commit is contained in:
Dennis Eichhorn 2023-10-22 17:19:44 +00:00
parent c52b6c8863
commit 1f9f97f8d9
2 changed files with 5 additions and 6 deletions

View File

@ -917,15 +917,14 @@ class Matrix implements \ArrayAccess, \Iterator
$matrix = $identity; $matrix = $identity;
$factorial = 1; $factorial = 1;
$pow = $matrix; $pow = clone $matrix;
for ($i = 1; $i <= $iterations; ++$i) { for ($i = 1; $i <= $iterations; ++$i) {
$factorial *= $i; $factorial *= $i;
$coeff = 1 / $factorial; $coeff = 1 / $factorial;
$term = $pow->mult($coeff); $term = clone $pow->mult($this);
$matrix = $matrix->add($term); $matrix = $matrix->add($term->mult($coeff));
$pow = $pow->mult($matrix); // @todo: maybe wrong order?
} }
return $matrix; return $matrix;

View File

@ -111,8 +111,8 @@ final class MetricsND
} }
$dotProduct = 0; $dotProduct = 0;
for ($i = 0; $i < $length; ++$i) { foreach ($a as $id => $_) {
$dotProduct += $a[$i] * $b[$i]; $dotProduct += $a[$id] * $b[$id];
} }
$sumOfSquares = 0; $sumOfSquares = 0;