jsat.linear
Class SingularValueDecomposition
- java.lang.Object
-
- jsat.linear.SingularValueDecomposition
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class SingularValueDecomposition extends java.lang.Object implements java.lang.Cloneable, java.io.SerializableThe Singular Value Decomposition (SVD) of a matrix Am,n = Um,n Σn,n VTn,n , where S is the diagonal matrix of the singular values sorted in descending order and are all non negative.
The SVD of a matrix has many practical uses, but is expensive to compute.
Implementation adapted from the Public Domain work of JAMA: A Java Matrix Package
NOTE: The current implementation has been revised and is now passing all test cases. However, it is still being tested. Use with awareness that it used to be bugged. Note left at revision 597- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SingularValueDecomposition(Matrix A)Creates a new SVD of the matrixAsuch that A = U Σ VT.SingularValueDecomposition(Matrix A, int maxIterations)Creates a new SVD of the matrixAsuch that A = U Σ VT.SingularValueDecomposition(Matrix U, Matrix V, double[] s)Sets the values for a SVD explicitly.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubleabsDet()Computes the absolute value of the determinant for the full matrix.SingularValueDecompositionclone()doublegetCondition()Returns the condition number of the matrix.double[]getInverseSingularValues()Returns an array containing the inverse singular values.double[]getInverseSingularValues(double tol)Returns an array containing the inverse singular values.doublegetNorm2()Returns the 2 norm of the matrix, which is the maximal singular value.doublegetPseudoDet()Computes the pseudo determinant of the matrix, which corresponds to absolute value of the determinant of the full rank square sub matrix that contains all non zero singular values.doublegetPseudoDet(double tol)Computes the pseudo determinant of the matrix, which corresponds to absolute value of the determinant of the full rank square sub matrix that contains all non singular values > tol.MatrixgetPseudoInverse()Returns the Moore–Penrose pseudo inverse of the matrix.MatrixgetPseudoInverse(double tol)Returns the Moore–Penrose pseudo inverse of the matrix.intgetRank()Returns the numerical rank of the matrix.intgetRank(double tol)Returns the numerical rank of the matrix.MatrixgetS()Returns the diagonal matrix S such that the SVD product results in the original matrix.double[]getSingularValues()Returns a copy of the sorted array of the singular values, include the near zero ones.MatrixgetU()Returns the backing matrix U of the SVD.MatrixgetV()Returns the backing matrix V of the SVD.booleanisFullRank()Indicates whether or not the input matrix was of full rank, full rank matrices are more numerically stable.Matrixsolve(Matrix B)Solves the linear system of equations for A x = B by using the equationx = A-1 B = V S-1 UT B
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.Matrixsolve(Matrix b, java.util.concurrent.ExecutorService threadpool)Solves the linear system of equations for A x = B by using the equationx = A-1 B = V S-1 UT B
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.Vecsolve(Vec b)Solves the linear system of equations for A x = b by using the equationx = A-1 b = V S-1 UT b
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.
-
-
-
Constructor Detail
-
SingularValueDecomposition
public SingularValueDecomposition(Matrix A)
Creates a new SVD of the matrixAsuch that A = U Σ VT. The matrixAwill be modified and used as temp space when computing the SVD.- Parameters:
A- the matrix to create the SVD of
-
SingularValueDecomposition
public SingularValueDecomposition(Matrix A, int maxIterations)
Creates a new SVD of the matrixAsuch that A = U Σ VT. The matrixAwill be modified and used as temp space when computing the SVD.- Parameters:
A- the matrix to create the SVD ofmaxIterations- the maximum number of iterations to perform per singular value till convergence.
-
SingularValueDecomposition
public SingularValueDecomposition(Matrix U, Matrix V, double[] s)
Sets the values for a SVD explicitly. This is not a copy constructor, and will hold the given values.- Parameters:
U- the U matrix of an SVDV- the V matrix of an SVDs- the singular sorted by magnitude of an SVD
-
-
Method Detail
-
getU
public Matrix getU()
Returns the backing matrix U of the SVD. Do not alter this matrix.- Returns:
- the matrix U of the SVD
-
getV
public Matrix getV()
Returns the backing matrix V of the SVD. Do not later this matrix.- Returns:
- the matrix V of the SVD
-
getSingularValues
public double[] getSingularValues()
Returns a copy of the sorted array of the singular values, include the near zero ones.- Returns:
- a copy of the sorted array of the singular values, including the near zero ones.
-
getS
public Matrix getS()
Returns the diagonal matrix S such that the SVD product results in the original matrix. The diagonal contains the singular values.- Returns:
- a dense diagonal matrix containing the singular values
-
getNorm2
public double getNorm2()
Returns the 2 norm of the matrix, which is the maximal singular value.- Returns:
- the 2 norm of the matrix
-
getCondition
public double getCondition()
Returns the condition number of the matrix. The condition number is a positive measure of the numerical instability of the matrix. The larger the value, the less stable the matrix. For singular matrices, the result isDouble.POSITIVE_INFINITY.- Returns:
- the condition number of the matrix
-
getRank
public int getRank()
Returns the numerical rank of the matrix. Near zero values will be ignored.- Returns:
- the rank of the matrix
-
isFullRank
public boolean isFullRank()
Indicates whether or not the input matrix was of full rank, full rank matrices are more numerically stable.- Returns:
- true if the matrix was of full tank
-
getRank
public int getRank(double tol)
Returns the numerical rank of the matrix. Values <= than tol will be ignored.- Parameters:
tol- the cut of for singular values- Returns:
- the rank of the matrix
-
getInverseSingularValues
public double[] getInverseSingularValues()
Returns an array containing the inverse singular values. Near zero values are converted to zero.- Returns:
- an array containing the inverse singular values
-
getInverseSingularValues
public double[] getInverseSingularValues(double tol)
Returns an array containing the inverse singular values. Values that are <= tol are converted to zero.- Parameters:
tol- the cut of for singular values- Returns:
- an array containing the inverse singular values
-
getPseudoInverse
public Matrix getPseudoInverse()
Returns the Moore–Penrose pseudo inverse of the matrix. The pseudo inverse for a matrix is unique. If a matrix is non singular, the pseudo inverse is the inverse.- Returns:
- the pseudo inverse of the matrix
-
getPseudoInverse
public Matrix getPseudoInverse(double tol)
Returns the Moore–Penrose pseudo inverse of the matrix. The pseudo inverse for a matrix is unique. If a matrix is non singular, the pseudo inverse is the inverse.- Parameters:
tol- the tolerance for singular values to ignore- Returns:
- the pseudo inverse of the matrix
-
getPseudoDet
public double getPseudoDet()
Computes the pseudo determinant of the matrix, which corresponds to absolute value of the determinant of the full rank square sub matrix that contains all non zero singular values.- Returns:
- the pseudo determinant.
-
getPseudoDet
public double getPseudoDet(double tol)
Computes the pseudo determinant of the matrix, which corresponds to absolute value of the determinant of the full rank square sub matrix that contains all non singular values > tol.- Parameters:
tol- the cut of for singular values- Returns:
- the pseudo determinant
-
absDet
public double absDet()
Computes the absolute value of the determinant for the full matrix.- Returns:
abs(determinant)
-
solve
public Vec solve(Vec b)
Solves the linear system of equations for A x = b by using the equationx = A-1 b = V S-1 UT b
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.- Parameters:
b- the vector to solve for- Returns:
- the vector that gives the least squares solution to A x = b
-
solve
public Matrix solve(Matrix B)
Solves the linear system of equations for A x = B by using the equationx = A-1 B = V S-1 UT B
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.- Parameters:
B- the matrix to solve for- Returns:
- the matrix that gives the least squares solution to A x = B
-
solve
public Matrix solve(Matrix b, java.util.concurrent.ExecutorService threadpool)
Solves the linear system of equations for A x = B by using the equationx = A-1 B = V S-1 UT B
When A is not full rank, this results in a more numerically stable approximation that minimizes the least squares error.- Parameters:
b- the matrix to solve forthreadpool-- Returns:
- the matrix that gives the least squares solution to A x = B
-
clone
public SingularValueDecomposition clone()
- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG