diff --git a/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs index 61f5d5e7..a2f778c3 100644 --- a/src/Numerics/LinearAlgebra/Complex/Factorization/Svd.cs +++ b/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); } } diff --git a/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs index c4b17da7..c96d2b4f 100644 --- a/src/Numerics/LinearAlgebra/Complex32/Factorization/Svd.cs +++ b/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 /// /// A class which encapsulates the functionality of the singular value decomposition (SVD). - /// Suppose M is an m-by-n matrix whose entries are real numbers. + /// 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. /// /// @@ -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); } } diff --git a/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs index 21622502..ba39ffed 100644 --- a/src/Numerics/LinearAlgebra/Double/Factorization/Svd.cs +++ b/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 { /// /// A class which encapsulates the functionality of the singular value decomposition (SVD). - /// Suppose M is an m-by-n matrix whose entries are real numbers. + /// 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. /// /// @@ -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); } } diff --git a/src/Numerics/LinearAlgebra/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Factorization/Svd.cs index fb762493..ed1c4ce1 100644 --- a/src/Numerics/LinearAlgebra/Factorization/Svd.cs +++ b/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 { /// /// A class which encapsulates the functionality of the singular value decomposition (SVD). - /// Suppose M is an m-by-n matrix whose entries are real numbers. + /// 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. /// /// diff --git a/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs b/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs index dfda2d7b..d83ba9a1 100644 --- a/src/Numerics/LinearAlgebra/Single/Factorization/Svd.cs +++ b/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 { /// /// A class which encapsulates the functionality of the singular value decomposition (SVD). - /// Suppose M is an m-by-n matrix whose entries are real numbers. + /// 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. /// /// @@ -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); } }