MADlib
1.1 A newer version is available
User Documentation
|
The sparse linear systems module implements solution methods for systems of a consistent linear equations. Systems of linear equations take the form:
\[ Ax = b \]
where \(x \in \mathbb{R}^{n}\), \(A \in \mathbb{R}^{m \times n} \) and \(b \in \mathbb{R}^{m}\). This module accepts sparse matrix input formats for \(A\) and \(b\). We assume that there are no rows of \(A\) where all elements are zero.
The algorithms implemented in this module can handle large sparse square linear systems. Currently, the algorithms implemented in this module solve the linear system using direct or iterative methods.
View short help messages using the following statements:
-- Summary of sparse linear systems SELECT madlib.linear_solver_sparse(); -- Function syntax and output table format SELECT madlib.linear_solver_sparse('usage'); -- Syntax for direct methods SELECT madlib.linear_solver_sparse('direct'); -- Syntax for iterative methods SELECT madlib.linear_solver_sparse('iterative');
linear_solver_sparse(tbl_source_lhs, tbl_source_rhs, tbl_result, row_id, LHS, RHS, grouping_cols := NULL, optimizer := 'direct', optimizer_params := 'algorithm = llt');
Text value. The name of the table containing the left hand side matrix. For the LHS matrix, the input data is expected to be of the following form:
{TABLE|VIEW} sourceName ( ... row_id FLOAT8, col_id FLOAT8, value FLOAT8, ... )
Here, each row represents a single equation using. The rhs refers to the right hand side of the equations while the lhs refers to the multipliers on the variables on the left hand side of the same equations.
Text value. The name of the table containing the right hand side vector. For the RHS matrix, the input data is expected to be of the following form:
{TABLE|VIEW} sourceName ( ... row_id FLOAT8, value FLOAT8 ... )
Here, each row represents a single equation using. The rhs refers to the right hand side of the equations while the lhs refers to the multipliers on the variables on the left hand side of the same equations.
Output is stored in the tbl_result
tbl_result | Data Types --------------------|--------------------- solution | DOUBLE PRECISION[] residual_norm | DOUBLE PRECISIOn iters | INTEGER
SELECT sparse_linear_sytems('tbl_source_lhs', 'tbl_source_rhs', 'tbl_result', 'row_id', 'LHS', 'RHS', NULL, 'direct', 'algorithm = householderqr');
Text value. The name of the table containing the LHS matrix.
Text value. The name of the table containing the RHS vector.
Text value. The name of the table where the output is saved.
Text value. The name of the column storing the 'row id' of the equations.
Text value. The name of the column (in tbl_source_lhs) storing the 'col id' of the equations.
Text value. The name of the column (in tbl_source_lhs) storing the 'value' of the equations.
Text value. The name of the column (in tbl_source_rhs) storing the 'col id' of the equations.
Text value. The name of the column (in tbl_source_rhs) storing the 'value' of the equations.
Integer value. The number of variables in the linear system. equations.
Text value. Type of optimizer. Default: 'direct'.
For each optimizer, there are specific parameters that can be tuned for better performance.
There are several algorithms that can be classified as 'direct' methods of solving linear systems. Madlib functions provide various algorithmic options available for users.
The following table provides a guideline on the choice of algorithm based on conditions on the A matrix, speed of the algorithms and numerical stability.
Algorithm | Contitions on A | Speed | Memory ---------------------------------------------------------- llt | Sym. Pos Def | ++ | --- ldlt | Sym. Pos Def | ++ | ---
For speed '++' is faster than '+', which is faster than '-'. For accuracy '+++' is better than '++'. For memory, '-' uses less memory than '–'.
Note: ldlt is often preferred over llt
There are several algorithms that can be classified as 'iterative' methods of solving linear systems. Madlib functions provide various algorithmic options available for users.
The following table provides a guideline on the choice of algorithm based on conditions on the A matrix, speed of the algorithms and numerical stability.
Algorithm | Contitions on A | Speed | Memory | Convergence ---------------------------------------------------------------------- cg-mem | Sym. Pos Def | +++ | - | ++ bicgstab-mem | Square | ++ | - | + precond-cg-mem | Sym. Pos Def | ++ | - | +++ precond-bicgstab-mem | Square | + | - | ++ For memory, '-' uses less memory than '--'. For speed, '++' is faster than '+'.
Details:
Termination tolerance (applicable only for iterative methods) which determines the stopping criterion (with respect to residual norm) for iterative methods.
The solution is an array (of double precision) with the variables in the same order as that provided as input in the 'left_hand_side' column name of the 'source_table'
Computes the scaled residual norm, defined as \( \frac{|Ax - b|}{|b|} \) gives the user an indication of the accuracy of the solution.
The number of iterations required by the algorithm (only applicable for iterative algorithms) . The output is NULL for direct' methods.
sql> DROP TABLE IF EXISTS sparse_linear_systems_lhs; CREATE TABLE sparse_linear_systems_lhs ( rid INTEGER NOT NULL, cid INTEGER, val DOUBLE PRECISION ); DROP TABLE IF EXISTS sparse_linear_systems_rhs; CREATE TABLE sparse_linear_systems_rhs ( rid INTEGER NOT NULL, val DOUBLE PRECISION ); INSERT INTO sparse_linear_systems_lhs(rid, cid, val) VALUES (0, 0, 1), (1, 1, 1), (2, 2, 1), (3, 3, 1); INSERT INTO sparse_linear_systems_rhs(rid, val) VALUES (0, 10), (1, 20), (2, 30);
sql> SELECT madlib.linear_solver_sparse( 'sparse_linear_systems_lhs', 'sparse_linear_systems_rhs', 'output_table', 'rid', 'cid', 'val', 'rid', 'val', 4);
sql> SELECT * FROM output_table; --------------------+------------------------------------- solution | {10,20,30,0} residual_norm | 0 iters | NULL
drop table if exists result_table; SELECT madlib.linear_solver_sparse( 'sparse_linear_systems_lhs', 'sparse_linear_systems_rhs', 'output_table', 'rid', 'cid', 'val', 'rid', 'val', 4, NULL, 'direct', 'algorithm=llt'); -# Chose a different algorithm than the default algorithm \verbatim drop table if exists result_table; madlib.linear_solver_sparse( 'sparse_linear_systems_lhs', 'sparse_linear_systems_rhs', 'output_table', 'rid', 'cid', 'val', 'rid', 'val', 4, NULL, 'iterative', 'algorithm=cg-mem, toler=1e-5');