Browse Source

LA: Matrix Rank calculation should use a tolerance based on the matrix size #334

pull/336/merge
Christoph Ruegg 11 years ago
parent
commit
de15eb6dc1
  1. 5
      src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs
  2. 13
      src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs
  3. 13
      src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs
  4. 10
      src/Numerics/LinearAlgebra/Factorization/Svd.cs
  5. 13
      src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs

5
src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -71,7 +71,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex.Factorization
{
get
{
return S.Count(t => !t.Magnitude.AlmostEqual(0.0));
double tolerance = Precision.DoublePrecision*Math.Max(U.RowCount, VT.RowCount);
return S.Count(t => t.Magnitude > tolerance);
}
}

13
src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -39,13 +39,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
/// <summary>
/// <para>A class which encapsulates the functionality of the singular value decomposition (SVD).</para>
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// Then there exists a factorization of the form M = UΣVT where:
/// - U is an m-by-m unitary matrix;
/// - Σ is m-by-n diagonal matrix with nonnegative real numbers on the diagonal;
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// by M (though the matrices U and V are not). The diagonal entries of Σ are known as the singular values of M.</para>
/// </summary>
/// <remarks>
@ -66,7 +66,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32.Factorization
{
get
{
return S.Count(t => !t.Magnitude.AlmostEqual(0.0f));
double tolerance = Precision.SinglePrecision*Math.Max(U.RowCount, VT.RowCount);
return S.Count(t => t.Magnitude > tolerance);
}
}

13
src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -37,13 +37,13 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
/// <summary>
/// <para>A class which encapsulates the functionality of the singular value decomposition (SVD).</para>
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// Then there exists a factorization of the form M = UΣVT where:
/// - U is an m-by-m unitary matrix;
/// - Σ is m-by-n diagonal matrix with nonnegative real numbers on the diagonal;
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// by M (though the matrices U and V are not). The diagonal entries of Σ are known as the singular values of M.</para>
/// </summary>
/// <remarks>
@ -64,7 +64,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
{
get
{
return S.Count(t => !Math.Abs(t).AlmostEqual(0.0));
double tolerance = Precision.DoublePrecision*Math.Max(U.RowCount, VT.RowCount);
return S.Count(t => Math.Abs(t) > tolerance);
}
}

10
src/Numerics/LinearAlgebra/Factorization/Svd.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -35,13 +35,13 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
{
/// <summary>
/// <para>A class which encapsulates the functionality of the singular value decomposition (SVD).</para>
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// Then there exists a factorization of the form M = UΣVT where:
/// - U is an m-by-m unitary matrix;
/// - Σ is m-by-n diagonal matrix with nonnegative real numbers on the diagonal;
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// by M (though the matrices U and V are not). The diagonal entries of Σ are known as the singular values of M.</para>
/// </summary>
/// <remarks>

13
src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs

@ -4,7 +4,7 @@
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2013 Math.NET
// Copyright (c) 2009-2015 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
@ -37,13 +37,13 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
/// <summary>
/// <para>A class which encapsulates the functionality of the singular value decomposition (SVD).</para>
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// <para>Suppose M is an m-by-n matrix whose entries are real numbers.
/// Then there exists a factorization of the form M = UΣVT where:
/// - U is an m-by-m unitary matrix;
/// - Σ is m-by-n diagonal matrix with nonnegative real numbers on the diagonal;
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// - VT denotes transpose of V, an n-by-n unitary matrix;
/// Such a factorization is called a singular-value decomposition of M. A common convention is to order the diagonal
/// entries Σ(i,i) in descending order. In this case, the diagonal matrix Σ is uniquely determined
/// by M (though the matrices U and V are not). The diagonal entries of Σ are known as the singular values of M.</para>
/// </summary>
/// <remarks>
@ -64,7 +64,8 @@ namespace MathNet.Numerics.LinearAlgebra.Single.Factorization
{
get
{
return S.Count(t => !Math.Abs(t).AlmostEqual(0.0f));
double tolerance = Precision.SinglePrecision*Math.Max(U.RowCount, VT.RowCount);
return S.Count(t => Math.Abs(t) > tolerance);
}
}

Loading…
Cancel
Save