blob: 07472dc9f9332df77732065a83412fac8b4a5659 [file] [log] [blame]
<!-- HTML header for doxygen 1.8.4-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="keywords" content="madlib,postgres,greenplum,machine learning,data mining,deep learning,ensemble methods,data science,market basket analysis,affinity analysis,pca,lda,regression,elastic net,huber white,proportional hazards,k-means,latent dirichlet allocation,bayes,support vector machines,svm"/>
<title>MADlib: Sparse Linear Systems</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { init_search(); });
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script><script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<!-- hack in the navigation tree -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="madlib_extra.css" rel="stylesheet" type="text/css"/>
<!-- google analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45382226-1', 'madlib.apache.org');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><a href="http://madlib.apache.org"><img alt="Logo" src="madlib.png" height="50" style="padding-left:0.5em;" border="0"/ ></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
<span id="projectnumber">1.18.0</span>
</div>
<div id="projectbrief">User Documentation for Apache MADlib</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__grp__sparse__linear__solver.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Sparse Linear Systems<div class="ingroups"><a class="el" href="group__grp__other__functions.html">Utilities</a> &raquo; <a class="el" href="group__grp__linear__solver.html">Linear Solvers</a></div></div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><b>Contents</b> <ul>
<li class="level1">
<a href="#sls_usage">Solution Function</a> </li>
<li class="level1">
<a href="#sls_opt_params">Optimizer Parameters</a> </li>
<li class="level1">
<a href="#sls_output">Output Tables</a> </li>
<li class="level1">
<a href="#sls_examples">Examples</a> </li>
<li>
<a href="related">Related Topics</a> </li>
</ul>
</div><p>The sparse linear systems module implements solution methods for systems of consistent linear equations. Systems of linear equations take the form: </p><p class="formulaDsp">
\[ Ax = b \]
</p>
<p>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.</p>
<dl class="section note"><dt>Note</dt><dd>Algorithms with fail if there is an row of the input matrix containing all zeros.</dd></dl>
<p>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.</p>
<p><a class="anchor" id="sls_usage"></a></p><dl class="section user"><dt>Sparse Linear Systems Solution Function</dt><dd></dd></dl>
<pre class="syntax">
linear_solver_sparse( tbl_source_lhs,
tbl_source_rhs,
tbl_result,
lhs_row_id,
lhs_col_id,
lhs_value,
rhs_row_id,
rhs_value,
grouping_cols := NULL,
optimizer := 'direct',
optimizer_params :=
'algorithm = llt'
)
</pre><p> <b>Arguments</b> </p><dl class="arglist">
<dt>tbl_source_lhs </dt>
<dd><p class="startdd">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: </p><pre>
{TABLE|VIEW} <em>sourceName</em> (
...
<em>row_id</em> FLOAT8,
<em>col_id</em> FLOAT8,
<em>value</em> FLOAT8,
...
)</pre><p> Each row represents a single equation. The <em>rhs</em> columns refer to the right hand side of the equations and the <em>lhs</em> columns refer to the multipliers on the variables on the left hand side of the same equations. </p>
<p class="enddd"></p>
</dd>
<dt>tbl_source_rhs </dt>
<dd><p class="startdd">TEXT. 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: </p><pre class="fragment">{TABLE|VIEW} &lt;em&gt;sourceName&lt;/em&gt; (
...
&lt;em&gt;row_id&lt;/em&gt; FLOAT8,
&lt;em&gt;value&lt;/em&gt; FLOAT8
...
)</pre><p> Each row represents a single equation. The <em>rhs</em> columns refer to the right hand side of the equations while the <em>lhs</em> columns refers to the multipliers on the variables on the left hand side of the same equations. </p>
<p class="enddd"></p>
</dd>
<dt>tbl_result </dt>
<dd><p class="startdd">TEXT. The name of the table where the output is saved. Output is stored in the tabled named by the <em>tbl_result</em> argument. The table contains the following columns. The output contains the following columns: </p><table class="output">
<tr>
<th>solution </th><td>FLOAT8[]. The solution is an array with the variables in the same order as that provided as input in the 'left_hand_side' column name of the 'source_table' </td></tr>
<tr>
<th>residual_norm </th><td>FLOAT8. Scaled residual norm, defined as \( \frac{|Ax - b|}{|b|} \). This value is an indication of the accuracy of the solution. </td></tr>
<tr>
<th>iters </th><td>INTEGER. Number of iterations required by the algorithm (only applicable for iterative algorithms) . The output is NULL for 'direct' methods. </td></tr>
</table>
<p class="enddd"></p>
</dd>
<dt>lhs_row_id </dt>
<dd>TEXT. The name of the column storing the 'row id' of the equations. <dl class="section note"><dt>Note</dt><dd>For a system with N equations, the row_id's must be a continuous range of integers from \( 0 \ldots n-1 \).</dd></dl>
</dd>
<dt>lhs_col_id </dt>
<dd><p class="startdd">TEXT. The name of the column (in tbl_source_lhs) storing the 'col id' of the equations.</p>
<p class="enddd"></p>
</dd>
<dt>lhs_value </dt>
<dd><p class="startdd">TEXT. The name of the column (in tbl_source_lhs) storing the 'value' of the equations.</p>
<p class="enddd"></p>
</dd>
<dt>rhs_row_id </dt>
<dd><p class="startdd">TEXT. The name of the column (in tbl_source_rhs) storing the 'col id' of the equations.</p>
<p class="enddd"></p>
</dd>
<dt>rhs_value </dt>
<dd><p class="startdd">TEXT. The name of the column (in tbl_source_rhs) storing the 'value' of the equations.</p>
<p class="enddd"></p>
</dd>
<dt>num_vars </dt>
<dd><p class="startdd">INTEGER. The number of variables in the linear system equations.</p>
<p class="enddd"></p>
</dd>
<dt>grouping_col (optional) </dt>
<dd>TEXT, default: NULL. Group by column names. <dl class="section note"><dt>Note</dt><dd>The grouping feature is currently not implemented and this parameter is only a placeholder.</dd></dl>
</dd>
<dt>optimizer (optional) </dt>
<dd><p class="startdd">TEXT, default: 'direct'. Type of optimizer.</p>
<p class="enddd"></p>
</dd>
<dt>optimizer_params (optional) </dt>
<dd>TEXT, default: NULL. Optimizer specific parameters. </dd>
</dl>
<p><a class="anchor" id="sls_opt_params"></a></p><dl class="section user"><dt>Optimizer Parameters</dt><dd></dd></dl>
<p>For each optimizer, there are specific parameters that can be tuned for better performance.</p>
<dl class="arglist">
<dt>algorithm (default: ldlt) </dt>
<dd><p class="startdd"></p>
<p>There are several algorithms that can be classified as 'direct' methods of solving linear systems. Madlib functions provide various algorithmic options available for users.</p>
<p>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.</p>
<pre class="fragment"> Algorithm | Conditions 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
</pre><p>There are several algorithms that can be classified as 'iterative' methods of solving linear systems. Madlib functions provide various algorithmic options available for users.</p>
<p>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.</p>
<pre class="fragment"> Algorithm | Conditions 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 '+'.
</pre><p>Algorithm Details: </p><table class="output">
<tr>
<th>cg-mem</th><td>In memory conjugate gradient with diagonal preconditioners. </td></tr>
<tr>
<th>bicgstab-mem</th><td>Bi-conjugate gradient (equivalent to performing CG on the least squares formulation of Ax=b) with incomplete LU preconditioners. </td></tr>
<tr>
<th>precond-cg-mem</th><td>In memory conjugate gradient with diagonal preconditioners. </td></tr>
<tr>
<th>bicgstab-mem</th><td>Bi-conjugate gradient (equivalent to performing CG on the least squares formulation of Ax=b) with incomplete LU preconditioners. </td></tr>
</table>
<p class="enddd"></p>
</dd>
<dt>toler (default: 1e-5) </dt>
<dd><p class="startdd">Termination tolerance (applicable only for iterative methods) which determines the stopping criterion (with respect to residual norm) for iterative methods. </p>
<p class="enddd"></p>
</dd>
</dl>
<p><a class="anchor" id="sls_examples"></a></p><dl class="section user"><dt>Examples</dt><dd></dd></dl>
<ol type="1">
<li>View online help for the sparse linear systems solver function. <pre class="example">
SELECT madlib.linear_solver_sparse();
</pre></li>
<li>Create the sample data set. <pre class="example">
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);
</pre></li>
<li>Solve the linear systems with default parameters. <pre class="example">
SELECT madlib.linear_solver_sparse( 'sparse_linear_systems_lhs',
'sparse_linear_systems_rhs',
'output_table',
'rid',
'cid',
'val',
'rid',
'val',
4
);
</pre></li>
<li>View the contents of the output table. <pre class="example">
\x on
SELECT * FROM output_table;
</pre> Result: <pre class="result">
--------------------+-------------------------------------
solution | {10,20,30,0}
residual_norm | 0
iters | NULL
</pre></li>
<li>Choose a different algorithm than the default algorithm. <pre class="example">
DROP TABLE IF EXISTS output_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'
);
</pre></li>
<li>Choose a different algorithm than the default algorithm. <pre class="example">
DROP TABLE IF EXISTS output_table;
SELECT 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'
);
</pre></li>
</ol>
<p><a class="anchor" id="related"></a></p><dl class="section user"><dt>Related Topics</dt><dd>File sparse_linear_sytems.sql_in documenting the SQL functions.</dd></dl>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Wed Mar 31 2021 20:45:50 for MADlib by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
</ul>
</div>
</body>
</html>