Class LU<T extends MatrixMixin<T,?,?,?,?,?,?,?>>
java.lang.Object
org.flag4j.linalg.decompositions.lu.LU<T>
- All Implemented Interfaces:
Decomposition<T>
public abstract class LU<T extends MatrixMixin<T,?,?,?,?,?,?,?>>
extends Object
implements Decomposition<T>
This abstract class specifies methods for computing the LU decomposition of a matrix.
The LU
decomposition, decomposes a matrix A
into a unit lower triangular matrix L
and an upper triangular matrix U
such that A=LU
.
If partial pivoting is used, the decomposition will also yield a permutation matrix P
such that
PA=LU
.
If full pivoting is used, the decomposition will yield an additional permutation matrix Q
such that
PAQ=LU
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Simple enum containing pivoting options for pivoting in LU decomposition. -
Field Summary
Modifier and TypeFieldDescriptionprotected int[]
(package private) final double
for determining if pivot value is to be considered zero in LU decomposition with no pivoting.protected T
Storage for L and U matrices.protected int
protected int
protected PermutationMatrix
Permutation matrix to store row swaps if partial pivoting is used.final LU.Pivoting
Flag indicating what pivoting to use.protected PermutationMatrix
Permutation matrix to store column swaps if full pivoting is used.protected int[]
(package private) final double
Tolerance for determining if pivot value is to be considered zero in LU decomposition with no pivoting. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAppliesLU
decomposition to the source matrix using the pivoting specified in the constructor.protected abstract void
Computes the LU decomposition using full/rook pivoting (i.e.abstract T
getL()
Gets the unit lower triangular matrix of the decomposition.getLU()
Gets theL
andU
matrices of the decomposition combined in a single matrix.int
Gets the number of column swaps used in the last decomposition.int
Gets the number of row swaps used in the last decomposition.getP()
Gets the row permutation matrix of the decomposition.getQ()
Gets the column permutation matrix of the decomposition.abstract T
getU()
Gets the upper triangular matrix of the decomposition.protected abstract void
Initializes theLU
matrix by copying the source matrix to decompose.protected abstract void
noPivot()
Computes the LU decomposition using no pivoting (i.e.protected abstract void
Computes the LU decomposition using partial pivoting (i.e.protected void
swapCols
(int colIdx1, int colIdx2) Tracks the swapping of two columns during gaussian elimination with full pivoting.protected void
swapRows
(int rowIdx1, int rowIdx2) Tracks the swapping of two rows during gaussian elimination with partial or full pivoting.
-
Field Details
-
pivotFlag
Flag indicating what pivoting to use. -
DEFAULT_ZERO_PIVOT_TOLERANCE
final double DEFAULT_ZERO_PIVOT_TOLERANCEfor determining if pivot value is to be considered zero in LU decomposition with no pivoting.- See Also:
-
zeroPivotTol
final double zeroPivotTolTolerance for determining if pivot value is to be considered zero in LU decomposition with no pivoting. -
LU
Storage for L and U matrices. Stored in a single matrix -
P
Permutation matrix to store row swaps if partial pivoting is used. -
Q
Permutation matrix to store column swaps if full pivoting is used. -
numRowSwaps
protected int numRowSwaps -
numColSwaps
protected int numColSwaps -
rowSwaps
protected int[] rowSwaps -
colSwaps
protected int[] colSwaps
-
-
Constructor Details
-
LU
public LU(int pivoting) Constructs a LU decomposer to decompose the specified matrix.- Parameters:
pivoting
- Pivoting to use. If pivoting is 2, full pivoting will be used. If pivoting is 1, partial pivoting will be used. If pivoting is any other value, no pivoting will be used.
-
LU
public LU(int pivoting, double zeroPivotTol) Constructs a LU decomposer to decompose the specified matrix.- Parameters:
pivoting
- Pivoting to use. If pivoting is 2, full pivoting will be used. If pivoting is 1, partial pivoting will be used. If pivoting is any other value, no pivoting will be used.zeroPivotTol
- Tolerance for considering a pivot to be zero. If a pivot is less than the tolerance in absolute value, then it will be considered zero.
-
-
Method Details
-
decompose
AppliesLU
decomposition to the source matrix using the pivoting specified in the constructor.- Specified by:
decompose
in interfaceDecomposition<T extends MatrixMixin<T,
?, ?, ?, ?, ?, ?, ?>> - Parameters:
src
- The source matrix to decompose. Not modified.- Returns:
- A reference to this decomposer.
-
initLU
Initializes theLU
matrix by copying the source matrix to decompose.- Parameters:
src
- Source matrix to decompose.
-
noPivot
protected abstract void noPivot()Computes the LU decomposition using no pivoting (i.e. rows and columns are not swapped). -
partialPivot
protected abstract void partialPivot()Computes the LU decomposition using partial pivoting (i.e. row swapping). -
fullPivot
protected abstract void fullPivot()Computes the LU decomposition using full/rook pivoting (i.e. row and column swapping). -
getLU
Gets theL
andU
matrices of the decomposition combined in a single matrix.- Returns:
- The
L
andU
matrices of the decomposition stored together in a single matrix. The diagonal ofL
is all ones and is not stored allowing the diagonal ofU
to be stored along the diagonal of the combined matrix.
-
getL
Gets the unit lower triangular matrix of the decomposition.- Returns:
- The unit lower triangular matrix of the decomposition.
-
getU
Gets the upper triangular matrix of the decomposition.- Returns:
- The upper triangular matrix of the decomposition.
-
getP
Gets the row permutation matrix of the decomposition.- Returns:
- The row permutation matrix of the decomposition. If no pivoting was used, null will be returned.
-
getQ
Gets the column permutation matrix of the decomposition.- Returns:
- The column permutation matrix of the decomposition. If full pivoting was not used, null will be returned.
-
getNumRowSwaps
public int getNumRowSwaps()Gets the number of row swaps used in the last decomposition.- Returns:
- The number of row swaps used in the last decomposition.
-
getNumColSwaps
public int getNumColSwaps()Gets the number of column swaps used in the last decomposition.- Returns:
- The number of column swaps used in the last decomposition.
-
swapRows
protected void swapRows(int rowIdx1, int rowIdx2) Tracks the swapping of two rows during gaussian elimination with partial or full pivoting.- Parameters:
rowIdx1
- First row index in swap.rowIdx2
- Second row index in swap.
-
swapCols
protected void swapCols(int colIdx1, int colIdx2) Tracks the swapping of two columns during gaussian elimination with full pivoting.- Parameters:
colIdx1
- First column index in swap.colIdx2
- Second column index in swap.
-