Class RealSVD


public class RealSVD extends SVD<Matrix>

Instances of this class can be used to compute the singular value decomposition (SVD) of a real dense matrix.

That is, decomposes a rectangular matrix \( M \) into \( M=U\Sigma V^{T} \) where \( U \) and \( V \) are orthogonal matrices whose columns are the left and right singular vectors of \( M \) and Σ is a rectangular diagonal matrix containing the singular values of \( M \).

The SVD may also be used to compute the (numerical) rank of the matrix using SVD.getRank().

The SVD proceeds by an iterative algorithm with possible random behavior. For reproducibility, constructors support specifying a seed for the pseudo-random number generator.

Usage:

The decomposition workflow typically follows these steps:
  1. Instantiate an instance of RealSVD.
  2. Call SVD.decompose(MatrixMixin) to perform the factorization.
  3. Retrieve the resulting matrices using SVD.getU() and SVD.getS().

Efficiency Considerations:

If singular vectors are not required, setting computeUV = false may improve performance.
See Also:
  • Field Summary

    Fields inherited from class org.flag4j.linalg.decompositions.svd.SVD

    computeUV, rank, reduced, S, seed, U, useSeed, V

    Fields inherited from class org.flag4j.linalg.decompositions.Decomposition

    hasDecomposed
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a decomposer to compute the singular value decomposition of a real matrix.
    RealSVD(boolean computeUV)
    Creates a decomposer to compute the singular value decomposition of a real matrix.
    RealSVD(boolean computeUV, boolean reduced)
    Creates a decomposer to compute the singular value decomposition of a real matrix.
    RealSVD(boolean computeUV, boolean reduced, long seed)
    Creates a decomposer to compute the Schur decomposition.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    extractNormalizedCols(Matrix singularVecs, int j)
    Extracts the singular vectors, normalizes them and sets the columns of \( U \) and \( V \) to be the left/right singular vectors.
    protected void
    initUV(Shape src, int cols)
    Initializes the unitary \( U \) and \( V \) matrices for the SVD.
    protected Matrix
    Computes the inverse direct sum of a matrix and its Hermitian transpose.
    protected Matrix
    makeEigenPairs(Matrix B, double[] eigVals)
    Gets the eigen values and vectors of symmetric the block matrix which corresponds to the singular values and vectors of the matrix being decomposed.
    protected void
    makeEigenVals(Matrix B, double[] eigVals)
    Gets the eigen values of the symmetric block matrix which corresponds to the singular values of the matrix being decomposed.

    Methods inherited from class org.flag4j.linalg.decompositions.svd.SVD

    computeRank, decompose, getRank, getS, getSingularValues, getU, getV

    Methods inherited from class org.flag4j.linalg.decompositions.Decomposition

    ensureHasDecomposed

    Methods inherited from class java.lang.Object

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

    • RealSVD

      public RealSVD()
      Creates a decomposer to compute the singular value decomposition of a real matrix. The left and right singular vectors will be computed.
    • RealSVD

      public RealSVD(boolean computeUV)
      Creates a decomposer to compute the singular value decomposition of a real matrix.
      Parameters:
      computeUV - A flag which indicates if the unitary matrices \( U \) and \( V \) should be computed (i.e. the singular vectors).
      • If true, the \( U \) and \( V \) matrices will be computed.
      • If false, the \( U \) and \( V \) matrices will not be computed. If it is not needed, this may provide a performance improvement.
    • RealSVD

      public RealSVD(boolean computeUV, boolean reduced)
      Creates a decomposer to compute the singular value decomposition of a real matrix.
      Parameters:
      computeUV - A flag which indicates if the unitary matrices \( U \) and \( V \) should be computed (i.e. the singular vectors).
      • If true, the \( U \) and \( V \) matrices will be computed.
      • If false, the \( U \) and \( V \) matrices will not be computed. If it is not needed, this may provide a performance improvement.
      computeUV - A flag which indicates if the unitary matrices \( U \) and \( V \) should be computed (i.e. the singular vectors).
      • If true, the \( U \) and \( V \) matrices will be computed.
      • If false, the \( U \) and \( V \) matrices will not be computed. If it is not needed, this may provide a performance improvement.
    • RealSVD

      public RealSVD(boolean computeUV, boolean reduced, long seed)
      Creates a decomposer to compute the Schur decomposition.
      Parameters:
      computeUV - A flag which indicates if the unitary matrices \( U \) and \( V \) should be computed (i.e. the singular vectors).
      • If true, the \( U \) and \( V \) matrices will be computed.
      • If false, the \( U \) and \( V \) matrices will not be computed. If it is not needed, this may provide a performance improvement.
      reduced - Flag which indicates if the reduced (or full) SVD should be computed.
      • If true, reduced SVD is computed.
      • If false, the full SVD is computed.
      seed - Seed to use in pseudo-random number generators. Setting this will allow for reproducibility between multiple calls with the same inputs.
  • Method Details

    • invDirectSum

      protected Matrix invDirectSum(Matrix src)
      Computes the inverse direct sum of a matrix and its Hermitian transpose.
      Specified by:
      invDirectSum in class SVD<Matrix>
      Parameters:
      src - Matrix to inverse direct add with its Hermitian transpose.
      Returns:
      The inverse direct sum of the src matrix with its Hermitian transpose.
    • makeEigenPairs

      protected Matrix makeEigenPairs(Matrix B, double[] eigVals)
      Gets the eigen values and vectors of symmetric the block matrix which corresponds to the singular values and vectors of the matrix being decomposed.
      Specified by:
      makeEigenPairs in class SVD<Matrix>
      Parameters:
      B - Symmetric block matrix to compute the eigenvalues of.
      eigVals - Storage for eigenvalues.
      Returns:
      The eigenvalues and eigenvectors of the symmetric block matrix which corresponds to the singular values and vectors of the matrix being decomposed.
    • makeEigenVals

      protected void makeEigenVals(Matrix B, double[] eigVals)
      Gets the eigen values of the symmetric block matrix which corresponds to the singular values of the matrix being decomposed.
      Specified by:
      makeEigenVals in class SVD<Matrix>
      Parameters:
      B - Symmetric block matrix to compute the eigenvalues of.
      eigVals - Storage for eigenvalues.
    • initUV

      protected void initUV(Shape src, int cols)
      Initializes the unitary \( U \) and \( V \) matrices for the SVD.
      Specified by:
      initUV in class SVD<Matrix>
      Parameters:
      src - Shape of the source matrix being decomposed.
      cols - The number of columns for \( U \) and \( V \).
    • extractNormalizedCols

      protected void extractNormalizedCols(Matrix singularVecs, int j)
      Extracts the singular vectors, normalizes them and sets the columns of \( U \) and \( V \) to be the left/right singular vectors.
      Specified by:
      extractNormalizedCols in class SVD<Matrix>
      Parameters:
      singularVecs - Computed left and right singular vectors.
      j - Index of the column of \( U \) and \( V \) to set.