Class HouseholderInPlace


  • public class HouseholderInPlace
    extends Object
    Maintains the matrix to be transformed by a sequence of Householder reflections. After all transformation are done, the final transformed matrix and the accumulated transformation matrices can be obtained via getTransformedMatrix(), U(), and Vt() respectively.
    • Constructor Detail

      • HouseholderInPlace

        public HouseholderInPlace​(Matrix A)
        Creates an instance that transforms the given matrix A.
        Parameters:
        A - the matrix to be transformed
      • HouseholderInPlace

        public HouseholderInPlace​(Matrix A,
                                  double epsilon)
        Creates an instance that transforms the given matrix A.
        Parameters:
        A - the matrix to be transformed
        epsilon - a precision parameter: when a number |x| ≤ ε, it is considered 0
      • HouseholderInPlace

        public HouseholderInPlace​(int nRows,
                                  int nCols)
        Creates an instance that transforms an identity matrix with the given dimension.
        Parameters:
        nRows - the number of rows of the identity matrix
        nCols - the number of columns of the identity matrix
    • Method Detail

      • generateAndReflectColumns

        public HouseholderInPlace.Householder generateAndReflectColumns​(int firstColumnIndex,
                                                                        int lastColumnIndex,
                                                                        int firstEntryIndex,
                                                                        int lastEntryIndex)
        Reflects a range of sub-columns with a Householder generated by the first column in the range.
        Parameters:
        firstColumnIndex - the column index of the first sub-column
        lastColumnIndex - the column index of the last sub-column
        firstEntryIndex - the row index of the first entry of the sub-columns
        lastEntryIndex - the row index of the last entry of the sub-columns
        Returns:
        the information of the generated Householder transformation
      • generateLeftHouseholder

        public HouseholderInPlace.Householder generateLeftHouseholder​(int columnIndex,
                                                                      int firstEntryIndex,
                                                                      int lastEntryIndex)
        Generates a left Householder from a sub-column of the underlying matrix, in order to zero out entries (except the first entry) of the sub-column.
        Parameters:
        columnIndex - the column index of the sub-column
        firstEntryIndex - the row index of the first entry of the sub-column
        lastEntryIndex - the row index of the last entry of the sub-column
        Returns:
        the information of the generated Householder transformation
      • reflect

        public void reflect​(HouseholderInPlace.Householder H,
                            int fromColumn,
                            int toColumn)
        Reflects (or left transform) a range of columns in the underlying matrix with a given Householder.
        Parameters:
        H - the Householder
        fromColumn - the column index of the first column
        toColumn - the column index of the last column
      • generateAndReflectRows

        public HouseholderInPlace.Householder generateAndReflectRows​(int firstRowIndex,
                                                                     int lastRowIndex,
                                                                     int firstEntryIndex,
                                                                     int lastEntryIndex)
        Reflects a range of sub-rows with a Householder generated by the first row in the range.
        Parameters:
        firstRowIndex - the row index of the first sub-row
        lastRowIndex - the row index of the last sub-row
        firstEntryIndex - the column index of the first entry of the sub-rows
        lastEntryIndex - the column index of the last entry of the sub-rows
        Returns:
        the information of the generated Householder transformation
      • generateRightHouseholder

        public HouseholderInPlace.Householder generateRightHouseholder​(int rowIndex,
                                                                       int firstEntryIndex,
                                                                       int lastEntryIndex)
        Generates a right Householder from a sub-row of the underlying matrix, in order to zero out entries (except the first entry) of the sub-row.
        Parameters:
        rowIndex - the row index of the sub-row
        firstEntryIndex - the column index of the first entry of the sub-row
        lastEntryIndex - the column index of the last entry of the sub-row
        Returns:
        the information of the generated Householder transformation
      • rightReflect

        public void rightReflect​(HouseholderInPlace.Householder H,
                                 int fromRow,
                                 int toRow)
        Reflects (or right transform) a range of rows in the underlying matrix with a given Householder.
        Parameters:
        H - the Householder
        fromRow - the row index of the first row
        toRow - the row index of the last row
      • getTransformedMatrix

        public Matrix getTransformedMatrix()
        Gets the final matrix transformed by all the Householder transformations.
        Returns:
        the transformed matrix
      • get

        public double get​(int i,
                          int j)
        Gets the value of an entry at (i,j) in the transformed matrix.
        Parameters:
        i - the row index
        j - the column index
        Returns:
        the value at (i,j)
      • U

        public Matrix U()
        Gets the accumulated Householder reflections applied to A. That is, the m x m matrix U, \[ U_k * ... * U_2 * U_1 * A = B U * A = B U = (U_k * ... * U_2 * U_1) U' = (U_1 * U_2 * ... * U_k) \]
        Returns:
        the accumulated Householder reflection
      • Vt

        public Matrix Vt()
        Gets the inverse (or transpose) of accumulated Householder right-reflections applied to A. That is, the n x n matrix V', \[ A * V_1 * V_2 * ... * V_k = B A * V = B A = B * V' V = (V_1 * V_2 * ... * V_k) V' = (V_k * ... * V_2 * V_1) \]
        Returns:
        the transpose of the accumulated Householder right-reflections
      • getLeftHouseholders

        public List<HouseholderInPlace.Householder> getLeftHouseholders()
        Gets all the accumulated left Householders.
        Returns:
        a list of the left Householders
      • getRightHouseholders

        public List<HouseholderInPlace.Householder> getRightHouseholders()
        Gets all the accumulated right Householders.
        Returns:
        a list of the right Householders