Record Class SVD
- Record Components:
m
- the number of rows of matrix.n
- the number of columns of matrix.s
- the singular values in descending order.U
- the left singular vectorsVt
- the transpose of right singular vectors.
- All Implemented Interfaces:
Serializable
For an m-by-n matrix A with m >= n
, the singular value decomposition is
an m-by-n orthogonal matrix U, an n-by-n diagonal matrix Σ, and
an n-by-n orthogonal matrix V so that A = U*Σ*V'.
For m < n
, only the first m columns of V are computed and Σ is m-by-m.
The singular values, σk = Σkk, are ordered so that σ0 ≥ σ1 ≥ ... ≥ σn-1.
The singular value decomposition always exists. The matrix condition number and the effective numerical rank can be computed from this decomposition.
SVD is a very powerful technique for dealing with sets of equations or matrices that are either singular or else numerically very close to singular. In many cases where Gaussian elimination and LU decomposition fail to give satisfactory results, SVD will diagnose precisely what the problem is. SVD is also the method of choice for solving most linear least squares problems.
Applications which employ the SVD include computing the pseudo-inverse, least squares fitting of data, matrix approximation, and determining the rank, range and null space of a matrix. The SVD is also applied extensively to the study of linear inverse problems, and is useful in the analysis of regularization methods such as that of Tikhonov. It is widely used in statistics where it is related to principal component analysis. Yet another usage is latent semantic indexing in natural language text processing.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.SVD
(int m, int n, Vector s, DenseMatrix U, DenseMatrix Vt) Creates an instance of aSVD
record class.SVD
(Vector s, DenseMatrix U, DenseMatrix Vt) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns the L2 norm condition number, which is max(S) / min(S).diag()
Returns the diagonal matrix of singular values.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.int
m()
Returns the value of them
record component.int
n()
Returns the value of then
record component.double
norm()
Returns the L2 matrix norm that is the largest singular value.int
nullity()
Returns the dimension of null space.Returns the matrix which columns are the orthonormal basis for the null space.pinv()
Returns the pseudo inverse.range()
Returns the matrix which columns are the orthonormal basis for the range space.int
rank()
Returns the effective numerical matrix rank.s()
Returns the value of thes
record component.solve
(double[] b) Solves the least squares min || B - A*X ||.solve
(float[] b) Solves the least squares min || B - A*X ||.Solves the least squares min || B - A*X ||.final String
toString()
Returns a string representation of this record class.U()
Returns the value of theU
record component.Vt()
Returns the value of theVt
record component.
-
Constructor Details
-
SVD
Constructor.- Parameters:
m
- the number of rows of matrix.n
- the number of columns of matrix.s
- the singular values in descending order.
-
SVD
Constructor.- Parameters:
s
- the singular values in descending order.U
- the left singular vectorsVt
- the transpose of right singular vectors.
-
SVD
Creates an instance of aSVD
record class.
-
-
Method Details
-
diag
Returns the diagonal matrix of singular values.- Returns:
- the diagonal matrix of singular values.
-
norm
public double norm()Returns the L2 matrix norm that is the largest singular value.- Returns:
- L2 matrix norm.
-
rank
public int rank()Returns the effective numerical matrix rank. The number of non-negligible singular values.- Returns:
- the effective numerical matrix rank.
-
nullity
public int nullity()Returns the dimension of null space. The number of negligible singular values.- Returns:
- the dimension of null space.
-
condition
public double condition()Returns the L2 norm condition number, which is max(S) / min(S). A system of equations is considered to be well-conditioned if a small change in the coefficient matrix or a small change on the right hand side results in a small change in the solution vector. Otherwise, it is called ill-conditioned. Condition number is defined as the product of the norm of A and the norm of A-1. If we use the usual L2 norm on vectors and the associated matrix norm, then the condition number is the ratio of the largest singular value of matrix A to the smallest. The condition number depends on the underlying norm. However, regardless of the norm, it is always greater or equal to 1. If it is close to one, the matrix is well conditioned. If the condition number is large, then the matrix is said to be ill-conditioned. A matrix that is not invertible has the condition number equal to infinity.- Returns:
- L2 norm condition number.
-
range
Returns the matrix which columns are the orthonormal basis for the range space. Returns null if the rank is zero (if and only if zero matrix).- Returns:
- the range space span matrix.
-
nullspace
Returns the matrix which columns are the orthonormal basis for the null space. Returns null if the matrix is of full rank.- Returns:
- the null space span matrix.
-
pinv
-
solve
Solves the least squares min || B - A*X ||.- Parameters:
b
- the right hand side of overdetermined linear system.- Returns:
- the solution vector.
- Throws:
RuntimeException
- when the matrix is rank deficient.
-
solve
Solves the least squares min || B - A*X ||.- Parameters:
b
- the right hand side of overdetermined linear system.- Returns:
- the solution vector.
- Throws:
RuntimeException
- when the matrix is rank deficient.
-
solve
Solves the least squares min || B - A*X ||.- Parameters:
b
- the right hand side of overdetermined linear system.- Returns:
- the solution vector.
- Throws:
RuntimeException
- when the matrix is rank deficient.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object)
; primitive components are compared with thecompare
method from their corresponding wrapper classes. -
m
-
n
-
s
-
U
-
Vt
-