Class MatrixPropertyUtils


  • public final class MatrixPropertyUtils
    extends Object
    These are the boolean operators that take matrices or vectors and check if they satisfy a certain property.
    • Method Detail

      • isSymmetric

        public static boolean isSymmetric​(Matrix A,
                                          double epsilon)
        Checks if a matrix is symmetric.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if
        A.t() == A
      • isSkewSymmetric

        public static boolean isSkewSymmetric​(Matrix A,
                                              double epsilon)
        Checks if a matrix is skew symmetric.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if
        A.t() == -A
      • isIdempotent

        public static boolean isIdempotent​(Matrix A,
                                           double epsilon)
        Checks if a matrix is idempotent.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if
        A = A*A or A = A2
      • isOrthogonal

        public static boolean isOrthogonal​(Matrix A,
                                           double epsilon)
        Checks if a matrix is orthogonal, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if
        AA' = 1
      • isMagicSquare

        @Deprecated
        public static boolean isMagicSquare​(Matrix A)
        Deprecated.
        Not supported yet.
        Checks if a matrix is a magic square. Not yet implemented.
        Parameters:
        A - a matrix
        Returns:
        true if A is a square matrix having distinct positive integers, arranged such that the sums of the numbers in any rows, columns, or diagonals are equal
      • isSingular

        public static boolean isSingular​(Matrix A,
                                         double epsilon)
        Checks if a square matrix is singular, i.e, having no inverse, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A-1 does not exist
      • isDiagonal

        public static boolean isDiagonal​(Matrix A,
                                         double epsilon)
        Checks if a square matrix is a diagonal matrix, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A is square and Aij=0, for all i != j.
      • isIdentity

        public static boolean isIdentity​(Matrix A,
                                         double epsilon)
        Checks if a matrix is an identity matrix, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A is square, and Aij=0 for all i != j, and Aij=1, for all i == j.
      • isUpperTriangular

        public static boolean isUpperTriangular​(Matrix A,
                                                double epsilon)
        Checks if a matrix is upper triangular, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is upper triangular
      • isLowerTriangular

        public static boolean isLowerTriangular​(Matrix A,
                                                double epsilon)
        Checks if a matrix is lower triangular, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is lower triangular
      • isQuasiTriangular

        public static boolean isQuasiTriangular​(Matrix A,
                                                double epsilon)
        Checks if a matrix is quasi (upper) triangular, up to a precision.

        A quasi triangular matrix is upper Hessenberg with no two consecutive non-zero elements on the first subdiagonal.

        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is quasi (upper) triangular
      • isUpperBidiagonal

        public static boolean isUpperBidiagonal​(Matrix A,
                                                double epsilon)
        Checks if a matrix is upper bidiagonal, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is upper bidiagonal
      • isLowerBidiagonal

        public static boolean isLowerBidiagonal​(Matrix A,
                                                double epsilon)
        Checks if a matrix is lower bidiagonal, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is lower bidiagonal
      • isTridiagonal

        public static boolean isTridiagonal​(Matrix A,
                                            double epsilon)
        Checks if a matrix is tridiagonal, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is tridiagonal
      • isRowEchelonForm

        public static boolean isRowEchelonForm​(Matrix A,
                                               double epsilon)
        Checks if a matrix is in the row echelon form, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is in row echelon form
        See Also:
        Wikipedia: Row echelon form
      • isReducedRowEchelonForm

        public static boolean isReducedRowEchelonForm​(Matrix A,
                                                      double epsilon)
        Checks if a matrix is in the reduced row echelon form, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the matrix is in reduced row echelon form
        See Also:
        Wikipedia: Row echelon form
      • isScalar

        @Deprecated
        public static boolean isScalar​(Matrix A,
                                       double epsilon)
        Deprecated.
        Not supported yet.
        Checks if a square matrix is a scalar matrix, up to a precision.
        Parameters:
        A - a matrix
        Returns:
        true if A is diagonal and, aij=c, for all i == j, c is a constant.
      • isSymmetricPositiveDefinite

        public static boolean isSymmetricPositiveDefinite​(Matrix A,
                                                          double epsilon)
        Checks if a square matrix is symmetric and positive definite.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A is symmetric, and z'Mz > 0, for all non-zero real vectors z.
        See Also:
        Wikipedia: Positive-definite matrix
      • isPositiveDefinite

        public static boolean isPositiveDefinite​(Matrix A,
                                                 double epsilon)
        Checks if a square matrix is positive definite; the matrix needs not be symmetric. A real matrix A is positive definite if the symmetric part Asymmetric = 1/2 * (A + A') is symmetric positive definite.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A satisfies z'Mz > 0, for all non-zero real vectors z.
        See Also:
        Wikipedia: Positive-definite matrix
      • isPositiveSemiDefinite

        public static boolean isPositiveSemiDefinite​(Matrix A,
                                                     double epsilon)
        Checks if a square matrix is positive definite, up to a precision.
        Parameters:
        A - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if A satisfies z'Mz > 0, for all non-zero real vectors z.
        See Also:
        Wikipedia: Negative-definite, semidefinite and indefinite matrices
      • isZero

        public static boolean isZero​(Vector v,
                                     double epsilon)
        Checks if a vector is a zero vector, i.e., all its entries are 0, up to a precision.
        Parameters:
        v - a vector
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if v is a zero vector
      • areEqual

        public static boolean areEqual​(Matrix A1,
                                       Matrix A2,
                                       double epsilon)
        Checks the equality of two matrices up to a precision. Two matrices are equal if
        1. the dimensions are the same;
        2. all entries are equal
        Parameters:
        A1 - a matrix
        A2 - a matrix
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if all entries are equal, entry by entry
      • areEqual

        public static boolean areEqual​(Vector v1,
                                       Vector v2,
                                       double epsilon)
        Checks if two vectors are equal, i.e., v1 - v2 is a zero vector, up to a precision.
        Parameters:
        v1 - a vector
        v2 - a vector
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if all entries are equal, entry by entry
      • areOrthogonal

        public static boolean areOrthogonal​(Vector v1,
                                            Vector v2,
                                            double epsilon)
        Checks if two vectors are orthogonal, i.e., v1 ∙ v2 == 0.
        Parameters:
        v1 - a vector
        v2 - a vector
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true the two vectors are orthogonal
      • areOrthogonal

        public static boolean areOrthogonal​(Vector[] v,
                                            double epsilon)
        Checks if a set of vectors are orthogonal, i.e., for any v1, v2 in v, v1 ∙ v2 == 0.
        Parameters:
        v - a set of vectors
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if any two vectors are orthogonal
      • areOrthogonormal

        public static boolean areOrthogonormal​(Vector v1,
                                               Vector v2,
                                               double epsilon)
        Checks if two vectors are orthogonormal. Two vectors are orthogonormal if
        1. {v1, v2} are orthogonal;
        2. |v1| = |v2| = 1.
        Parameters:
        v1 - a vector
        v2 - a vector
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if the two vectors are orthogonormal
      • areOrthogonormal

        public static boolean areOrthogonormal​(Vector[] v,
                                               double epsilon)
        Checks if a set of vectors are orthogonormal.
        Parameters:
        v - a set of vectors
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
        Returns:
        true if any two vectors are orthogonormal
      • areAllSparse

        public static boolean areAllSparse​(Matrix... matrices)
        Checks if all matrices are SparseMatrix.
        Parameters:
        matrices -
        Returns:
        true if and only if all matrices are SparseMatrix
      • areAllSparse

        public static boolean areAllSparse​(Vector... vectors)
        Checks if all vectors are SparseVector.
        Parameters:
        vectors -
        Returns:
        true if and only if all matrices are SparseVector
      • throwIfNotEqualSize

        public static void throwIfNotEqualSize​(Vector v1,
                                               Vector v2)
        Checks if the input vectors have the same size.
        Parameters:
        v1 - a vector
        v2 - a vector
        Throws:
        VectorSizeMismatch - if sizes do not match
      • throwIfInvalidIndex

        public static void throwIfInvalidIndex​(Vector v,
                                               int index)
        Checks if an index is a valid index.
        Parameters:
        v - a vector
        index - a vector index
        Throws:
        VectorAccessException - if the index is invalid
      • isNaN

        public static boolean isNaN​(Vector v)
        Checks if a vector contains any NaN entry.
        Parameters:
        v - a vector
        Returns:
        true if there is at least one NaN entry.
      • conditionNumber

        public static double conditionNumber​(Matrix A)
        Computes the condition number of a given matrix A. The condition number is computed as the maximal singular value of A divided by the minimal singular value of A. If the condition number is large, A is ill-conditioned. Practically, such a matrix is almost singular, and the computation of its inverse, or solution of a linear system of equations is prone to large numerical errors. A matrix that is not invertible has condition number equal to infinity.
        Parameters:
        A - the matrix
        Returns:
        the condition number of A
        See Also:
        Wikipedia: Condition number