Class EconomyQRDecomposer

java.lang.Object
com.irurueta.algebra.Decomposer
com.irurueta.algebra.EconomyQRDecomposer

public class EconomyQRDecomposer extends Decomposer
This decomposer computes economy QR decomposition, which is faster than typical QR decomposition.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Constant defining default round error when determining full rank of matrices.
    static final double
    Constant defining minimum allowed round error value when determining full rank of matrices.
    private Matrix
    Internal matrix containing results of decomposition.
    private double[]
    Internal array containing diagonal of R.

    Fields inherited from class com.irurueta.algebra.Decomposer

    inputMatrix, locked
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor of this class.
    Constructor of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This method computes QR matrix decomposition, which consists on factoring provided input matrix into an orthogonal matrix (Q) and an upper triangular matrix (R).
    Returns decomposer type corresponding to Economy QR decomposition.
    Returns the Householder vectors.
    void
    Computes the Householder vectors and store them in provided matrix.
    Return the economy-sized orthogonal factor matrix.
    void
    Computes the economy-sized orthogonal factor matrix and stores it into provided matrix.
    Return upper triangular factor matrix.
    void
    Computes upper triangular factor matrix and stores it into provided matrix.
    boolean
    Returns boolean indicating whether decomposition has been computed and results can be retrieved.
    boolean
    Returns boolean indicating whether provided input matrix has full rank or not.
    boolean
    isFullRank(double roundingError)
    Returns boolean indicating whether provided input matrix has full rank or not.
    void
    setInputMatrix(Matrix inputMatrix)
    Sets reference to input matrix to be decomposed.
    Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix.
    solve(Matrix b, double roundingError)
    Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix.
    void
    solve(Matrix b, double roundingError, Matrix result)
    Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix.
    void
    solve(Matrix b, Matrix result)
    Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix.

    Methods inherited from class com.irurueta.algebra.Decomposer

    getInputMatrix, isLocked, isReady

    Methods inherited from class java.lang.Object

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

    • DEFAULT_ROUND_ERROR

      public static final double DEFAULT_ROUND_ERROR
      Constant defining default round error when determining full rank of matrices. This value is zero by default
      See Also:
    • MIN_ROUND_ERROR

      public static final double MIN_ROUND_ERROR
      Constant defining minimum allowed round error value when determining full rank of matrices.
      See Also:
    • qr

      private Matrix qr
      Internal matrix containing results of decomposition.
    • rDiag

      private double[] rDiag
      Internal array containing diagonal of R.
  • Constructor Details

    • EconomyQRDecomposer

      public EconomyQRDecomposer()
      Constructor of this class.
    • EconomyQRDecomposer

      public EconomyQRDecomposer(Matrix inputMatrix)
      Constructor of this class.
      Parameters:
      inputMatrix - Reference to input matrix to be decomposed.
  • Method Details

    • getDecomposerType

      public DecomposerType getDecomposerType()
      Returns decomposer type corresponding to Economy QR decomposition.
      Specified by:
      getDecomposerType in class Decomposer
      Returns:
      Decomposer type.
    • setInputMatrix

      public void setInputMatrix(Matrix inputMatrix) throws LockedException
      Sets reference to input matrix to be decomposed.
      Overrides:
      setInputMatrix in class Decomposer
      Parameters:
      inputMatrix - Reference to input matrix to be decomposed.
      Throws:
      LockedException - Exception thrown if attempting to call this method while this instance remains locked.
    • isDecompositionAvailable

      public boolean isDecompositionAvailable()
      Returns boolean indicating whether decomposition has been computed and results can be retrieved. Attempting to retrieve decomposition results when not available, will probably raise a NotAvailableException.
      Specified by:
      isDecompositionAvailable in class Decomposer
      Returns:
      Boolean indicating whether decomposition has been computed and results can be retrieved.
    • decompose

      public void decompose() throws NotReadyException, LockedException
      This method computes QR matrix decomposition, which consists on factoring provided input matrix into an orthogonal matrix (Q) and an upper triangular matrix (R). In other words, if input matrix is A, then: A = Q * R Note: During execution of this method, this instance will be locked. Note: After execution of this method, QR decomposition will be available and operations such as retrieving Q and R matrices or solving systems of linear equations will be able to be done. Attempting to call any of such operations before calling this method will raise a NotAvailableException because they require computation of QR decomposition first.
      Specified by:
      decompose in class Decomposer
      Throws:
      NotReadyException - Exception thrown if attempting to call this method when this instance is not ready (i.e. no input matrix has been provided).
      LockedException - Exception thrown if this decomposer is already locked before calling this method. Notice that this method will actually lock this instance while it is being executed.
    • isFullRank

      public boolean isFullRank() throws NotAvailableException, WrongSizeException
      Returns boolean indicating whether provided input matrix has full rank or not. Squared matrices having full rank also have determinant different from zero. Note: Because of rounding errors, testing whether a matrix has full rank or not, might obtain unreliable results especially for non-square matrices. In such cases matrices usually tend to be considered as full rank even when they are not.
      Returns:
      Boolean indicating whether provided input matrix has full rank or not.
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR).
      See Also:
    • isFullRank

      public boolean isFullRank(double roundingError) throws NotAvailableException, WrongSizeException
      Returns boolean indicating whether provided input matrix has full rank or not. Squared matrices having full rank also have determinant different from zero. Note: Because of rounding errors, testing whether a matrix has full rank or not, might obtain unreliable results especially for non-square matrices. In such cases matrices usually tend to be considered as full rank even when they are not.
      Parameters:
      roundingError - Determines the amount of margin given to determine whether a matrix has full rank or not due to rounding errors. If not provided, by default rounding error is set to zero, but this value can be relaxed if needed.
      Returns:
      Boolean indicating whether provided input matrix has full rank or not.
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if provided input matrix has less rows than columns.
      IllegalArgumentException - Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR).
      See Also:
    • getH

      public void getH(Matrix h) throws NotAvailableException
      Computes the Householder vectors and store them in provided matrix. Provided matrix will be resized if needed
      Parameters:
      h - Matrix where Householder vectors will be stored
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      See Also:
    • getH

      public Matrix getH() throws NotAvailableException
      Returns the Householder vectors.
      Returns:
      Lower trapezoidal matrix whose columns define the reflections.
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      See Also:
    • getR

      public void getR(Matrix r) throws NotAvailableException
      Computes upper triangular factor matrix and stores it into provided matrix. QR decomposition decomposes input matrix into Q (orthogonal matrix) and R, which is an upper triangular matrix.
      Parameters:
      r - Upper triangular factor matrix
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      See Also:
    • getR

      public Matrix getR() throws NotAvailableException
      Return upper triangular factor matrix. QR decomposition decomposes input matrix into Q (orthogonal matrix) and R, which is an upper triangular matrix.
      Returns:
      Upper triangular factor matrix
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      See Also:
    • getQ

      public void getQ(Matrix q) throws NotAvailableException, WrongSizeException
      Computes the economy-sized orthogonal factor matrix and stores it into provided matrix. QR decomposition decomposes input matrix into Q, which is an orthogonal matrix and R (upper triangular matrix).
      Parameters:
      q - Orthogonal factor matrix.
      Throws:
      NotAvailableException - Exception thrown if attempting to call
      WrongSizeException - Exception thrown if provided input matrix has less rows than columns.
      See Also:
    • getQ

      Return the economy-sized orthogonal factor matrix. QR decomposition decomposes input matrix into Q, which is an orthogonal matrix and R (upper triangular matrix).
      Returns:
      Orthogonal factor matrix.
      Throws:
      NotAvailableException - Exception thrown if attempting to call
      WrongSizeException - Exception thrown if provided input matrix has fewer rows than columns.
      See Also:
    • solve

      Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vector/matrices without having to recompute QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first.
      Parameters:
      b - Parameters matrix that determine a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.
      result - Matrix containing solution of linear system of equations on each column for each column of provided matrix of parameters b. Provided matrix will be resized if needed
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if attempting to call this method using an input matrix with fewer rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.
      RankDeficientMatrixException - Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.
    • solve

      public void solve(Matrix b, double roundingError, Matrix result) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException
      Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vector/matrices without having to recompute QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first.
      Parameters:
      b - Parameters matrix that determine a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.
      roundingError - threshold to determine whether matrix b has full rank or not. By default, this is typically a tiny value close to zero.
      result - Matrix containing solution of linear system of equations on each column for each column of provided matrix of parameters b. Provided matrix will be resized if needed
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if attempting to call this method using an input matrix with fewer rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.
      RankDeficientMatrixException - Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.
      IllegalArgumentException - if provided rounding error is negative.
    • solve

      Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vector/matrices without having to recompute QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first.
      Parameters:
      b - Parameters matrix that determine a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.
      Returns:
      Matrix containing solution of linear system of equations on each column for each column of provided matrix of parameters b.
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if attempting to call this method using an input matrix with fewer rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.
      RankDeficientMatrixException - Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.
    • solve

      public Matrix solve(Matrix b, double roundingError) throws NotAvailableException, WrongSizeException, RankDeficientMatrixException
      Solves a linear system of equations of the following form: A * X = B, where A is the input matrix provided for QR decomposition, X is the solution to the system of equations, and B is the parameters vector/matrix. Note: This method can be reused for different b vector/matrices without having to recompute QR decomposition on the same input matrix. Note: Provided b matrix must have the same number of rows as provided input matrix A, otherwise a WrongSizeException will be raised. Note: Provided input matrix "A" must have at least as many rows as columns, otherwise a WrongSizeException will be raised as well. For input matrices having a higher number of rows than columns, the system of equations will be overdetermined and the least squares solution will be found. Note: If provided input matrix A is rank deficient, a RankDeficientMatrixException will be thrown. Note: In order to execute this method, a QR decomposition must be available, otherwise a NotAvailableException will be raised. In order to avoid this exception call decompose() method first.
      Parameters:
      b - Parameters matrix that determine a linear system of equations. Provided matrix must have the same number of rows as provided input matrix for QR decomposition. Besides, each column on parameters matrix will represent a new system of equations, whose solution will be returned on appropriate column as an output of this method.
      roundingError - Determines the amount of margin given to determine whether a matrix has full rank or not due to rounding errors. If not provided, by default rounding error is set to zero, but this value can be relaxed if needed.
      Returns:
      Matrix containing solution of linear system of equations on each column for each column of provided matrix of parameters b.
      Throws:
      NotAvailableException - Exception thrown if attempting to call this method before computing QR decomposition. To avoid this exception call decompose() method first.
      WrongSizeException - Exception thrown if attempting to call this method using an input matrix with less rows than columns; or if provided parameters matrix (b) does not have the same number of rows as input matrix being QR decomposed.
      RankDeficientMatrixException - Exception thrown if provided input matrix to be QR decomposed is rank deficient. In this case linear system of equations cannot be solved.
      IllegalArgumentException - Exception thrown if provided rounding error is lower than minimum allowed value (MIN_ROUND_ERROR)
      See Also: