Class HouseholderInPlace
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.operation.householder.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()
, andVt()
respectively.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HouseholderInPlace.Householder
-
Constructor Summary
Constructors Constructor Description HouseholderInPlace(int nRows, int nCols)
Creates an instance that transforms an identity matrix with the given dimension.HouseholderInPlace(Matrix A)
Creates an instance that transforms the given matrix A.HouseholderInPlace(Matrix A, double epsilon)
Creates an instance that transforms the given matrix A.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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.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.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.double
get(int i, int j)
Gets the value of an entry at (i,j) in the transformed matrix.List<HouseholderInPlace.Householder>
getLeftHouseholders()
Gets all the accumulated left Householders.List<HouseholderInPlace.Householder>
getRightHouseholders()
Gets all the accumulated right Householders.Matrix
getTransformedMatrix()
Gets the final matrix transformed by all the Householder transformations.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.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.Matrix
U()
Gets the accumulated Householder reflections applied to A.Matrix
Vt()
Gets the inverse (or transpose) of accumulated Householder right-reflections applied to A.
-
-
-
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 transformedepsilon
- 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 matrixnCols
- 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-columnlastColumnIndex
- the column index of the last sub-columnfirstEntryIndex
- the row index of the first entry of the sub-columnslastEntryIndex
- 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-columnfirstEntryIndex
- the row index of the first entry of the sub-columnlastEntryIndex
- 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 HouseholderfromColumn
- the column index of the first columntoColumn
- 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-rowlastRowIndex
- the row index of the last sub-rowfirstEntryIndex
- the column index of the first entry of the sub-rowslastEntryIndex
- 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-rowfirstEntryIndex
- the column index of the first entry of the sub-rowlastEntryIndex
- 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 HouseholderfromRow
- the row index of the first rowtoRow
- 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 indexj
- 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
-
-