blob: 148f73a71bc67411da0f52bfe962bee78a7eb8a8 [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.4"/>
<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="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
$(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</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 src="../mathjax/MathJax.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', 'auto');
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 style="padding-left: 0.5em;">
<div id="projectname">MADlib
&#160;<span id="projectnumber">1.2</span> <span style="font-size:10pt; font-style:italic"><a href="../latest/./group__grp__sparse__linear__solver.html"> A newer version is available</a></span>
</div>
<div id="projectbrief">User Documentation</div>
</td>
<!--BEGIN VERSIONS LINKS-->
<td style="padding-left: 0.5em;">
<div class="versionlist"><ul>
<li class="head">More versions:</li>
<li><a href="../v1.1/index.html">v1.1</li>
<li><a href="../v1.0/index.html">v1.0</li>
<li><a href="../v0.7/index.html">v0.7</li>
<li><a href="../v0.5/index.html">v0.5</li></ul>
</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.4 -->
<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)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Groups</a></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__linear__solver.html">Linear Systems</a></div></div> </div>
</div><!--header-->
<div class="contents">
<div class="toc"><b>Contents</b> </p>
<ul>
<li class="level1">
<a href="#sls_about">About</a> </li>
<li class="level1">
<a href="#sls_online_help">Online Help</a> </li>
<li class="level1">
<a href="#sls_usage">Function Syntax</a> </li>
<li class="level1">
<a href="#sls_args">Arguments</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>
</ul>
</div><p><a class="anchor" id="sls_about"></a></p>
<dl class="section user"><dt>About</dt><dd></dd></dl>
<p>The sparse linear systems module implements solution methods for systems of a 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_online_help"></a></p>
<dl class="section user"><dt>Online Help</dt><dd></dd></dl>
<p>View short help messages using the following statements: </p>
<pre class="fragment">-- 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');
</pre><p><a class="anchor" id="sls_usage"></a></p>
<dl class="section user"><dt>Usage</dt><dd></dd></dl>
<pre class="fragment">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><a class="anchor" id="sls_args"></a></p>
<dl class="section user"><dt>Arguments</dt><dd></dd></dl>
<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 class="fragment">{TABLE|VIEW} &lt;em&gt;sourceName&lt;/em&gt; (
...
&lt;em&gt;row_id&lt;/em&gt; FLOAT8,
&lt;em&gt;col_id&lt;/em&gt; FLOAT8,
&lt;em&gt;value&lt;/em&gt; FLOAT8,
...
)</pre><p> Here, each row represents a single equation using. The <em> rhs </em> refers to the right hand side of the equations while the <em> lhs</em> refers 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> Here, each row represents a single equation using. The <em> rhs </em> refers to the right hand side of the equations while the <em> lhs</em> refers to the multipliers on the variables on the left hand side of the same equations.</p>
<p>Output is stored in the <em>tbl_result</em> </p>
<pre class="fragment"> tbl_result | Data Types
--------------------|---------------------
solution | DOUBLE PRECISION[]
residual_norm | DOUBLE PRECISIOn
iters | INTEGER
</pre> <p class="enddd"></p>
</dd>
<dt>tbl_result </dt>
<dd><p class="startdd">TEXT. The name of the table where the output is saved.</p>
<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. Group by column names. Default: NULL. <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. Type of optimizer. Default: 'direct'.</p>
<p class="enddd"></p>
</dd>
<dt>optimizer_params (optional) </dt>
<dd>TEXT. Optimizer specific parameters. Default: NULL. </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 | 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
</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 | 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 '+'.
</pre><p>Details:</p>
<ol type="1">
<li><b>cg-mem: </b> In memory conjugate gradient with diagonal preconditioners.</li>
<li><b>bicgstab-mem: </b> Bi-conjugate gradient (equivalent to performing CG on the least squares formulation of Ax=b) with incomplete LU preconditioners.</li>
<li><b>precond-cg-mem:</b> In memory conjugate gradient with diagonal preconditioners.</li>
<li><b>bicgstab-mem: </b> Bi-conjugate gradient (equivalent to performing CG on the least squares formulation of Ax=b) with incomplete LU preconditioners. </li>
</ol>
<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_output"></a></p>
<dl class="section user"><dt>Output statistics</dt><dd></dd></dl>
<dl class="arglist">
<dt>solution </dt>
<dd><p class="startdd">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' </p>
<p class="enddd"></p>
</dd>
<dt>residual_norm </dt>
<dd><p class="startdd">FLOAT8. Scaled residual norm, defined as \( \frac{|Ax - b|}{|b|} \). This value is an indication of the accuracy of the solution. </p>
<p class="enddd"></p>
</dd>
<dt>iters </dt>
<dd>INTEGER. Number of iterations required by the algorithm (only applicable for iterative algorithms) . The output is NULL for 'direct' methods. </dd>
</dl>
<p><a class="anchor" id="sls_examples"></a></p>
<dl class="section user"><dt>Examples</dt><dd><ol type="1">
<li>Create the sample data set: <pre class="fragment">sql&gt; 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="fragment">sql&gt; SELECT madlib.linear_solver_sparse(
'sparse_linear_systems_lhs',
'sparse_linear_systems_rhs',
'output_table',
'rid',
'cid',
'val',
'rid',
'val',
4);
</pre></li>
<li>Obtain the output from the output table <pre class="fragment">sql&gt; SELECT * FROM output_table;
--------------------+-------------------------------------
solution | {10,20,30,0}
residual_norm | 0
iters | NULL
</pre></li>
<li>Chose a different algorithm than the default algorithm <pre class="fragment">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');
</pre></li>
</ol>
</dd></dl>
<dl class="section see"><dt>See Also</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 Thu Jan 9 2014 20:35:40 for MADlib by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.4 </li>
</ul>
</div>
</body>
</html>