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 vectors
Vt - the transpose of right singular vectors.
All Implemented Interfaces:
Serializable

public record SVD(int m, int n, Vector s, DenseMatrix U, DenseMatrix Vt) extends Record implements Serializable
Singular Value Decomposition.

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

    Constructors
    Constructor
    Description
    SVD(int m, int n, Vector s)
    Constructor.
    SVD(int m, int n, Vector s, DenseMatrix U, DenseMatrix Vt)
    Creates an instance of a SVD record class.
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the L2 norm condition number, which is max(S) / min(S).
    Returns the diagonal matrix of singular values.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    m()
    Returns the value of the m record component.
    int
    n()
    Returns the value of the n record component.
    double
    Returns the L2 matrix norm that is the largest singular value.
    int
    Returns the dimension of null space.
    Returns the matrix which columns are the orthonormal basis for the null space.
    Returns the pseudo inverse.
    Returns the matrix which columns are the orthonormal basis for the range space.
    int
    Returns the effective numerical matrix rank.
    s()
    Returns the value of the s 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
    Returns a string representation of this record class.
    U()
    Returns the value of the U record component.
    Vt()
    Returns the value of the Vt record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SVD

      public SVD(int m, int n, Vector s)
      Constructor.
      Parameters:
      m - the number of rows of matrix.
      n - the number of columns of matrix.
      s - the singular values in descending order.
    • SVD

      public SVD(Vector s, DenseMatrix U, DenseMatrix Vt)
      Constructor.
      Parameters:
      s - the singular values in descending order.
      U - the left singular vectors
      Vt - the transpose of right singular vectors.
    • SVD

      public SVD(int m, int n, Vector s, DenseMatrix U, DenseMatrix Vt)
      Creates an instance of a SVD record class.
      Parameters:
      m - the value for the m record component
      n - the value for the n record component
      s - the value for the s record component
      U - the value for the U record component
      Vt - the value for the Vt record component
  • Method Details

    • diag

      public DenseMatrix 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

      public DenseMatrix 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

      public DenseMatrix 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

      public DenseMatrix pinv()
      Returns the pseudo inverse.
      Returns:
      the pseudo inverse.
    • solve

      public Vector solve(double[] b)
      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

      public Vector solve(float[] b)
      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

      public Vector solve(Vector b)
      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

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • m

      public int m()
      Returns the value of the m record component.
      Returns:
      the value of the m record component
    • n

      public int n()
      Returns the value of the n record component.
      Returns:
      the value of the n record component
    • s

      public Vector s()
      Returns the value of the s record component.
      Returns:
      the value of the s record component
    • U

      public DenseMatrix U()
      Returns the value of the U record component.
      Returns:
      the value of the U record component
    • Vt

      public DenseMatrix Vt()
      Returns the value of the Vt record component.
      Returns:
      the value of the Vt record component