Browse Source

[Single/Double.Matrix] Remove redundant calculation of abs in frobenius norm

The formulas found in various references do not have abs. Furthermore,
when multiplying A*A^T or A^T*A (for the frobenius norm we only care
about the diagonal so it doesn't matter which product is used) the
i-ith diagonal element of the final matrix comes from the multiplication
of line i with itself. Therefore, all numbers involved will be multiplied
with themselves resulting in numbers that are always non-negative.

Signed-off-by: Alexander Karatarakis <alex@karatarakis.com>
pull/36/head
Alexander Karatarakis 15 years ago
committed by Marcus Cuda
parent
commit
4889537d50
  1. 2
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  2. 2
      src/Numerics/LinearAlgebra/Single/Matrix.cs

2
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
var norm = 0.0;
for (var i = 0; i < RowCount; i++)
{
norm += Math.Abs(aat.At(i, i));
norm += aat.At(i, i);
}
norm = Math.Sqrt(norm);

2
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -99,7 +99,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var norm = 0.0f;
for (var i = 0; i < RowCount; i++)
{
norm += Math.Abs(aat.At(i, i));
norm += aat.At(i, i);
}
norm = Convert.ToSingle(Math.Sqrt(norm));

Loading…
Cancel
Save