Class Matrix.SVD

java.lang.Object
smile.math.matrix.Matrix.SVD
All Implemented Interfaces:
Serializable
Enclosing class:
Matrix

public static class Matrix.SVD extends Object 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The number of rows of matrix.
    final int
    The number of columns of matrix.
    final double[]
    The singular values in descending order.
    final Matrix
    The left singular vectors U.
    final Matrix
    The right singular vectors V.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SVD(double[] s, Matrix U, Matrix V)
    Constructor.
    SVD(int m, int n, double[] s)
    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.
    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.
    double[]
    solve(double[] b)
    Solves the least squares min || B - A*X ||.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • m

      public final int m
      The number of rows of matrix.
    • n

      public final int n
      The number of columns of matrix.
    • s

      public final double[] s
      The singular values in descending order.
    • U

      public final Matrix U
      The left singular vectors U.
    • V

      public final Matrix V
      The right singular vectors V.
  • Constructor Details

    • SVD

      public SVD(int m, int n, double[] 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(double[] s, Matrix U, Matrix V)
      Constructor.
      Parameters:
      s - the singular values in descending order.
      U - the left singular vectors
      V - the right singular vectors.
  • Method Details

    • diag

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

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

      public double[] 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 beta that minimizes ||Y - X*beta||.
      Throws:
      RuntimeException - when matrix is rank deficient.