Class SingularValueDecomposition


  • public class SingularValueDecomposition
    extends java.lang.Object
    computes IN = U*S*V^T. With diag(S)={fEigenValues(0), fEigenValues(1),..,fEigenValues(n)} and V the fEigenVector matrix of IN

    algorithm according to Golub and Reinsch G. Golub and C. Reinsch, "Handbook for Automatic Computation II, Linear Algebra". Springer, NY, 1971. numerically checked but... TODO: code clean up necessary... code as been translated from FORTRAN -> C -> C++ -> Java ;-)

    Author:
    rstein
    • Constructor Detail

      • SingularValueDecomposition

        public SingularValueDecomposition()
        default constructor.
      • SingularValueDecomposition

        public SingularValueDecomposition​(MatrixD inputMatrix)
        default constructor.
        Parameters:
        inputMatrix - the preset input matrix to be decomposed
    • Method Detail

      • cond

        public double cond()
        Two norm condition number
        Returns:
        max(S)/min(S)
      • decompose

        public boolean decompose()
        Perform the singular value decomposition. (does not use intermediate square matrices)
        Returns:
        true if operation was successful, false otherwise
      • decompose

        public boolean decompose​(boolean useSquareMatrix)
        Perform the singular value decomposition.
        Parameters:
        useSquareMatrix - whether to use intermediate step of transforming the input matrix to a square one.
        Returns:
        true if operation was successful, false otherwise
      • getEigenSolution

        public MatrixD getEigenSolution​(int eigen)
      • getEigenValues

        public MatrixD getEigenValues()
      • getEigenVector

        public MatrixD getEigenVector​(int eigen)
      • getEigenVectorMatrixU

        public MatrixD getEigenVectorMatrixU()
        Returns:
        the eigenvector matrix U (m x n)
      • getEigenVectorMatrixV

        public MatrixD getEigenVectorMatrixV()
        Returns:
        the eigenvector matrix V (n x n)
      • getInverse

        public MatrixD getInverse()
      • getInverse

        public MatrixD getInverse​(boolean timer,
                                  int nEigenValues)
      • getMatrix

        public MatrixD getMatrix()
      • getPseudoInverseEigenvalues

        public MatrixD getPseudoInverseEigenvalues()
      • getSingularValues

        public double[] getSingularValues()
        Returns:
        arrays with computed singular values
      • getThreshold

        public double getThreshold()
      • getTol

        public double getTol()
      • getU

        public MatrixD getU()
        Returns:
        the eigenvector matrix U (n x n)
      • getV

        public MatrixD getV()
        Returns:
        the eigenvector matrix V (n x n)
      • norm2

        @Deprecated
        public double norm2()
        Deprecated.
        used only in old implementation
        Two norm
        Returns:
        max(S)
      • rank

        public int rank()
        Effective numerical matrix rank
        Returns:
        Number of non-negligible singular values.
      • setMatrix

        public void setMatrix​(MatrixD inputMatrix)
        Sets the input matrix to be decomposed.
        Parameters:
        inputMatrix - the input matrix
      • setThreshold

        public void setThreshold​(double val)
      • setTol

        public void setTol​(double val)
      • testInvert

        public boolean testInvert()
        Test of 'inputMatrix'*'pseudo-inverse SVD matrix' == 1. only works for non-singular matrices
        Returns:
        true if test successful, false otherwise
        See Also:
        for more info
      • testInvert

        public boolean testInvert​(double threshold)
        Test of 'inputMatrix'*'pseudo-inverse SVD matrix' == '1' matrix. only works for non-singular matrices
        Parameters:
        threshold - the numerical threshold for the test
        Returns:
        true if test successful, false otherwise
      • testSVD

        public boolean testSVD()
        Tests whether 'inputMatrix' == 'SVD decomposed matrix'. assumes default numerical precision threshold,
        Returns:
        true if test successful, false otherwise
        See Also:
        for more info
      • testSVD

        public boolean testSVD​(double threshold)
        Tests whether 'inputMatrix' == 'SVD decomposed matrix'.
        Parameters:
        threshold - the numerical threshold for the test
        Returns:
        true if test successful, false otherwise
      • main

        public static void main​(java.lang.String[] argc)
        some small test routines to check SVD matrix computation.
        Parameters:
        argc - the input parameter (unused)