Class TriangularSolver_FSCC
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
eliminationTree
(FMatrixSparseCSC A, boolean ata, int[] parent, @Nullable IGrowArray gwork) If ata=false then it computes the elimination tree for sparse lower triangular square matrix generated from Cholesky decomposition.static void
postorder
(int[] parent, int N, int[] post, @Nullable IGrowArray gwork) Sorts an elimination treeeliminationTree(org.ejml.data.FMatrixSparseCSC, boolean, int[], org.ejml.data.IGrowArray)
into postorder.protected static int
postorder_dfs
(int j, int k, int[] w, int[] post, int N) Depth First Search used inside ofpostorder(int[], int, int[], org.ejml.data.IGrowArray)
.static float
Computes the quality of a triangular matrix, where the quality of a matrix is defined inLinearSolver.quality()
.static int
searchNzRowsElim
(FMatrixSparseCSC A, int k, int[] parent, int[] s, int[] w) Given an elimination tree compute the non-zero elements in the specified row of L given the symmetric A matrix.static int
searchNzRowsInX
(FMatrixSparseCSC G, FMatrixSparseCSC B, int colB, @org.jetbrains.annotations.Nullable int[] pinv, int[] xi, int[] w) Determines which elements in 'X' will be non-zero when the system below is solved for.static void
solve
(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, FMatrixSparseCSC X, @org.jetbrains.annotations.Nullable int[] pinv, @Nullable FGrowArray g_x, @Nullable IGrowArray g_xi, @Nullable IGrowArray g_w) Computes the solution to the triangular system.static int
solveColB
(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, int colB, float[] x, @org.jetbrains.annotations.Nullable int[] pinv, @Nullable IGrowArray g_xi, int[] w) Computes the solution to a triangular system with (optional) pivots.static void
solveL
(FMatrixSparseCSC L, float[] x) Solves for a lower triangular matrix against a dense matrix.static void
solveTran
(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, FMatrixSparseCSC X, @org.jetbrains.annotations.Nullable int[] pinv, @Nullable FGrowArray g_x, @Nullable IGrowArray g_xi, @Nullable IGrowArray g_w) Solution to a sparse transposed triangular system with sparse B and sparse Xstatic void
solveTranL
(FMatrixSparseCSC L, float[] x) Solves for the transpose of a lower triangular matrix against a dense matrix.static void
solveU
(FMatrixSparseCSC U, float[] x) Solves for an upper triangular matrix against a dense vector.
-
Constructor Details
-
TriangularSolver_FSCC
public TriangularSolver_FSCC()
-
-
Method Details
-
solveL
Solves for a lower triangular matrix against a dense matrix. L*x = b- Parameters:
L
- Lower triangular matrix. Diagonal elements are assumed to be non-zerox
- (Input) Solution matrix 'b'. (Output) matrix 'x'
-
solveTranL
Solves for the transpose of a lower triangular matrix against a dense matrix. LT*x = b- Parameters:
L
- Lower triangular matrix. Diagonal elements are assumed to be non-zerox
- (Input) Solution matrix 'b'. (Output) matrix 'x'
-
solveU
Solves for an upper triangular matrix against a dense vector. U*x = b- Parameters:
U
- Upper triangular matrix. Diagonal elements are assumed to be non-zerox
- (Input) Solution matrix 'b'. (Output) matrix 'x'
-
solveTran
public static void solveTran(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, FMatrixSparseCSC X, @Nullable @org.jetbrains.annotations.Nullable int[] pinv, @Nullable @Nullable FGrowArray g_x, @Nullable @Nullable IGrowArray g_xi, @Nullable @Nullable IGrowArray g_w) Solution to a sparse transposed triangular system with sparse B and sparse XGT*X = B
- Parameters:
G
- (Input) Lower or upper triangular matrix. diagonal elements must be non-zero. Not modified.lower
- true for lower triangular and false for upperB
- (Input) Matrix. Not modified.X
- (Output) Solutionpinv
- (Input, Optional) Permutation vector. Maps col j to G. Null if no pivots.g_x
- (Optional) Storage for workspace.g_xi
- (Optional) Storage for workspace.g_w
- (Optional) Storage for workspace.
-
solve
public static void solve(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, FMatrixSparseCSC X, @Nullable @org.jetbrains.annotations.Nullable int[] pinv, @Nullable @Nullable FGrowArray g_x, @Nullable @Nullable IGrowArray g_xi, @Nullable @Nullable IGrowArray g_w) Computes the solution to the triangular system.- Parameters:
G
- (Input) Lower or upper triangular matrix. diagonal elements must be non-zero. Not modified.lower
- true for lower triangular and false for upperB
- (Input) Matrix. Not modified.X
- (Output) Solutionpinv
- (Input, Optional) Permutation vector. Maps col j to G. Null if no pivots.g_x
- (Optional) Storage for workspace.g_xi
- (Optional) Storage for workspace.g_w
- (Optional) Storage for workspace.
-
solveColB
public static int solveColB(FMatrixSparseCSC G, boolean lower, FMatrixSparseCSC B, int colB, float[] x, @Nullable @org.jetbrains.annotations.Nullable int[] pinv, @Nullable @Nullable IGrowArray g_xi, int[] w) Computes the solution to a triangular system with (optional) pivots. Only a single column in B is solved for. Diagonals in G are assumed to filled in and either the first or last entry for lower or upper triangle, respectively.- Parameters:
G
- (Input) Lower or upper triangular matrix. diagonal elements must be non-zero and last or first entry in a column. Not modified.lower
- true for lower triangular and false for upperB
- (Input) Matrix. Not modified.colB
- The column in B which is solved forx
- (Output) Storage for dense solution. length = G.numRowspinv
- (Input, Optional) Permutation vector. Maps col j to G. Null if no pivots.g_xi
- (Optional) Storage for workspace. Will contain nonzero pattern. SeesearchNzRowsInX(FMatrixSparseCSC, FMatrixSparseCSC, int, int[], int[], int[])
w
- Storage for workspace. Must be of length B.numRows*2 or more. First N elements must be zero.- Returns:
- Return number of zeros in 'x', ignoring cancellations.
-
searchNzRowsInX
public static int searchNzRowsInX(FMatrixSparseCSC G, FMatrixSparseCSC B, int colB, @Nullable @org.jetbrains.annotations.Nullable int[] pinv, int[] xi, int[] w) Determines which elements in 'X' will be non-zero when the system below is solved for.
G*X = Bxi will contain a list of ordered row indexes in B which will be modified starting at xi[top] to xi[n-1]. top is the value returned by this function.
See cs_reach in dsparse library to understand the algorithm. This code follow the spirit but not the details because of differences in the contract.
- Parameters:
G
- (Input) Lower triangular system matrix. Diagonal elements are assumed to be not zero. Not modified.B
- (Input) Matrix B. Not modified.colB
- Column in B being solved forpinv
- (Input, Optional) Column pivots in G. Null if no pivots.xi
- (Output) List of row indices in X which are non-zero in graph order. Must have length G.numColsw
- workspace array used internally. Must have a length of G.numCols*2 or more. Assumed to be filled with 0 in first N elements.- Returns:
- Returns the index of the first element in the xi list. Also known as top.
-
eliminationTree
public static void eliminationTree(FMatrixSparseCSC A, boolean ata, int[] parent, @Nullable @Nullable IGrowArray gwork) If ata=false then it computes the elimination tree for sparse lower triangular square matrix generated from Cholesky decomposition. If ata=true then it computes the elimination tree of ATA without forming ATA explicitly. In an elimination tree the parent of node 'i' is 'j', where the first off-diagonal non-zero in column 'i' has row index 'j'; j > i for which l[k,i] != 0.
This tree encodes the non-zero elements in L given A, e.g. L*L' = A, and enables faster to compute solvers than the general purpose implementations.
Functionally identical to cs_etree in csparse
- Parameters:
A
- (Input) M by N sparse upper triangular matrix. If ata is false then M=N otherwise M ≥ Nata
- If true then it computes elimination treee of A'A without forming A'A otherwise computes elimination tree for cholesky factorizationparent
- (Output) Parent of each node in tree. This is the elimination tree. -1 if no parent. Size N.gwork
- (Optional) Internal workspace. Can be null.
-
postorder
Sorts an elimination tree
eliminationTree(org.ejml.data.FMatrixSparseCSC, boolean, int[], org.ejml.data.IGrowArray)
into postorder. In a postoredered tree, the d proper descendants of any node k are numbered k-d through k-1. Non-recursive implementation for better performance.post[k] = i means node 'i' of the original tree is node 'k' in the postordered tree.
See page 44
- Parameters:
parent
- (Input) The elimination tree.N
- Number of elements in parentpost
- (Output) Postordering permutation.gwork
- (Optional) Internal workspace. Can be null
-
postorder_dfs
protected static int postorder_dfs(int j, int k, int[] w, int[] post, int N) Depth First Search used inside ofpostorder(int[], int, int[], org.ejml.data.IGrowArray)
. -
searchNzRowsElim
Given an elimination tree compute the non-zero elements in the specified row of L given the symmetric A matrix. This is in general much faster than general purpose algorithms
Functionally equivalent to cs_ereach() in csparse
- Parameters:
A
- Symmetric matrix.k
- Row in A being processed.parent
- elimination tree.s
- (Output) s[top:(n-1)] = pattern of L[k,:]. Must have length A.numColsw
- workspace array used internally. All elements must be ≥ 0 on input. Must be of size A.numCols- Returns:
- Returns the index of the first element in the xi list. Also known as top.
-
qualityTriangular
Computes the quality of a triangular matrix, where the quality of a matrix is defined inLinearSolver.quality()
. In this situation the quality os the absolute value of the product of each diagonal element divided by the magnitude of the largest diagonal element. If all diagonal elements are zero then zero is returned.- Parameters:
T
- A matrix.- Returns:
- the quality of the system.
-