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;
$factorial = 1;
$pow = $matrix;
$pow = clone $matrix;
for ($i = 1; $i <= $iterations; ++$i) {
$factorial *= $i;
$coeff = 1 / $factorial;
$term = $pow->mult($coeff);
$matrix = $matrix->add($term);
$pow = $pow->mult($matrix); // @todo: maybe wrong order?
$term = clone $pow->mult($this);
$matrix = $matrix->add($term->mult($coeff));
}
return $matrix;

View File

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