Skip to content

Commit e9cc661

Browse files
Mark WellonsRahul Iyer
authored andcommitted
Documentation: Correct + improve linear systems
1 parent 01f256e commit e9cc661

File tree

4 files changed

+154
-125
lines changed

4 files changed

+154
-125
lines changed

src/ports/postgres/modules/linear_systems/dense_linear_systems.sql_in

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,24 @@ m4_include(`SQLCommon.m4')
1515
/**
1616
@addtogroup grp_dense_linear_solver
1717

18+
19+
<div class ="toc"><b>Contents</b>
20+
<ul>
21+
<li class="level1"><a href="#dls_about">About</a></li>
22+
<li class="level1"><a href="#dls_online_help">Online Help</a></li>
23+
<li class="level1"><a href="#dls_function">Function Syntax</a></li>
24+
<li class="level1"><a href="#dls_args">Arguments</a></li>
25+
<li class="level1"><a href="#dls_opt_params">Optimizer Parameters</a></li>
26+
<li class="level1"><a href="#dls_output">Output Tables</a></li>
27+
<li class="level1"><a href="#dls_examples">Examples</a></li>
28+
</ul>
29+
</div>
30+
31+
@anchor dls_about
1832
@about
1933

20-
The linear systems module implements solution methods for systems of a consistent
21-
linear equations.
34+
The linear systems module implements solution methods for systems of consistent
35+
linear equations. Systems of linear equations take the form:
2236
\f[
2337
Ax = b
2438
\f]
@@ -27,9 +41,10 @@ where \f$x \in \mathbb{R}^{n}\f$, \f$A \in \mathbb{R}^{m \times n} \f$ and \f$b
2741
We assume that there are no rows of \f$A\f$ where all elements are zero.
2842
The algorithms implemented in this module can handle large dense
2943
linear systems. Currently, the algorithms implemented in this module
30-
solve the lienar system by a direct decomposition. Hence, these methods are
44+
solve the linear system by a direct decomposition. Hence, these methods are
3145
known as <em>direct method</em>.
3246

47+
@anchor dls_online_help
3348
@par Online Help
3449

3550
View short help messages using the following statements:
@@ -44,21 +59,21 @@ SELECT madlib.linear_solver_dense('usage');
4459
SELECT madlib.linear_solver_dense('direct');
4560
@endverbatim
4661

47-
@usage
62+
@anchor dls_function
63+
@par Function Syntax
4864

4965
<pre>
50-
SELECT {schema_madlib}.linear_solve_dense (
51-
'tbl_source', -- Data table
52-
'tbl_result', -- Result table
53-
'row_id', -- Name of column containing row_id
54-
'left_hand_side', -- Left Hand Side of the equations
55-
'right_hand_side', -- Right Hand side of the equations
56-
'grouping_cols', -- Grouping columns (Default: NULL)
57-
'optimizer', -- Name of optimizer. Default: 'direct'
58-
'optimizer_params' -- Text array of optimizer parameters
59-
);
66+
SELECT linear_solver_dense(tbl_source, tbl_result, row_id, LHS,
67+
RHS, grouping_col := NULL, optimizer := 'direct',
68+
optimizer_params := 'algorithm = householderqr');
6069
</pre>
6170

71+
@anchor dls_args
72+
@par Arguments
73+
74+
<DL class="arglist">
75+
<DT>tbl_source</DT>
76+
<DD>Text value. The name of the table containing the training data.
6277
The input data is expected to be of the following form:
6378
<pre>{TABLE|VIEW} <em>sourceName</em> (
6479
...
@@ -68,30 +83,12 @@ The input data is expected to be of the following form:
6883
...
6984
)</pre>
7085

71-
Here, each row represents a single equation using. The <em> rhs </em> refers
72-
to the right hand side of the equations while the <em> lhs_array </em>
86+
Here, each row represents a single equation using. The <em> right_hand_side
87+
</em> refers
88+
to the right hand side of the equations while the <em> left_hand_side </em>
7389
refers to the multipliers on the variables on the left hand side of the same
7490
equations.
75-
76-
Output is stored in the <em>tbl_result</em>
77-
@verbatim
78-
tbl_result | Data Types
79-
--------------------|---------------------
80-
solution | DOUBLE PRECISION[]
81-
residual_norm | DOUBLE PRECISIOn
82-
iters | INTEGER
83-
@endverbatim
84-
85-
@par Syntax
86-
87-
<pre>
88-
SELECT dense_linear_sytems('tbl_source', 'tbl_result', 'row_id', 'LHS',
89-
'RHS', NULL, 'direct', 'algorithm = householderqr');
90-
</pre>
91-
92-
<DL>
93-
<DT>tbl_source</DT>
94-
<DD>Text value. The name of the table containing the training data.</DD>
91+
</DD>
9592

9693
<DT>tbl_result</DT>
9794
<DD>Text value. The name of the table where the output is saved.</DD>
@@ -102,12 +99,12 @@ SELECT dense_linear_sytems('tbl_source', 'tbl_result', 'row_id', 'LHS',
10299
\note For a system with N equations, the row_id's must be a continuous
103100
range of integers from \f$ 0 \ldots n-1 \f$.
104101

105-
<DT>left_hand_size</DT>
106-
<DD>Text value. The name of the column storing the 'left hand size' of the
102+
<DT>LHS</DT>
103+
<DD>Text value. The name of the column storing the 'left hand side' of the
107104
equations stored as an array.</DD>
108105

109-
<DT>right_hand_size</DT>
110-
<DD>Text value. The name of the column storing the 'right hand size' of the
106+
<DT>RHS</DT>
107+
<DD>Text value. The name of the column storing the 'right hand side' of the
111108
equations.</DD>
112109

113110
<DT>grouping_col (optional) </DT>
@@ -121,13 +118,13 @@ equations.</DD>
121118
<DD>Text value. Optimizer specific parameters. Default: NULL.</DD>
122119
</DL>
123120

124-
121+
@anchor dls_opt_params
125122
@par Optimizer Parameters
126123

127124
For each optimizer, there are specific parameters that can be tuned
128125
for better performance.
129-
130-
<DL>
126+
\par
127+
<DL class="arglist">
131128
<DT>algorithm (default: householderqr)</dT>
132129
<DD>
133130

@@ -148,16 +145,19 @@ for better performance.
148145
llt | Pos. Definite | +++ | +
149146
ldlt | Pos. or Neg Def | +++ | ++
150147

148+
For speed '++' is faster than '+', which is faster than '-'.
149+
For accuracy '+++' is better than '++'.
150+
151151
More details about the individual algorithms can be found on the <a href="http://eigen.tuxfamily.org/dox-devel/group__TutorialLinearAlgebra.html"> Eigen documentation</a>. Eigen is an open source library for linear algebra.
152152

153153

154154
</DD>
155155
</DL>
156156

157-
157+
@anchor dls_output
158158
@par Output statistics
159-
160-
<DL>
159+
Output is stored in the <em>tbl_result</em> table.
160+
<DL class="arglist">
161161
<DT>solution</dT>
162162
<DD>
163163
The solution is an array (of double precision) with the variables in the same
@@ -167,8 +167,8 @@ order as that provided as input in the 'left_hand_side' column name of the
167167

168168
<DT>residual_norm</dT>
169169
<DD>
170-
Computes the scaled residual norm, defined as \f$ \frac{|Ax - b|}{|b|} \f$
171-
gives the user an indication of the accuracy of the solution.
170+
Computes the scaled residual norm, defined as \f$ \frac{|Ax - b|}{|b|} \f$.
171+
This value is an indication of the accuracy of the solution.
172172
</DD>
173173

174174
<DT>iters</dT>
@@ -184,27 +184,27 @@ The number of iterations required by the algorithm (only applicable for
184184

185185

186186

187-
187+
@anchor dls_examples
188188
@examp
189189

190190
-# Create the sample data set:
191191
\verbatim
192-
sql> CREATE TABLE source_table (id INTEGER NOT NULL,
192+
sql> CREATE TABLE linear_systems_test_data (id INTEGER NOT NULL,
193193
lhs DOUBLE PRECISION[],
194194
rhs DOUBLE PRECISION);
195-
sql> INSERT INTO linear_systems_test_data(id, a, b) VaLUES
195+
sql> INSERT INTO linear_systems_test_data(id, lhs, rhs) VaLUES
196196
(0, ARRAY[1,0,0], 20),
197197
(1, ARRAY[0,1,0], 15),
198198
(2, ARRAY[0,0,1], 20);
199199
\endverbatim
200200

201201
-# Solve the linear systems with default parameters
202202
\verbatim
203-
sql> SELECT madlib.linregr_train('source_table',
204-
'output_table',
205-
'id',
206-
'lhs',
207-
'rhs');
203+
sql> SELECT madlib.linear_solver_dense('linear_systems_test_data',
204+
'output_table',
205+
'id',
206+
'lhs',
207+
'rhs');
208208
\endverbatim
209209

210210
-# Obtain the output from the output table
@@ -224,17 +224,14 @@ select madlib.linear_solver_dense(
224224
'linear_systems_test_data',
225225
'result_table',
226226
'id',
227-
'a',
228-
'b',
227+
'lhs',
228+
'rhs',
229229
NULL,
230230
'direct',
231231
'algorithm=llt'
232232
);
233233
\endverbatim
234234

235-
\anchor Background
236-
@background
237-
238235

239236
@sa File dense_linear_sytems.sql_in documenting the SQL functions.
240237

0 commit comments

Comments
 (0)