| <!-- 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: Low-Rank Matrix Factorization</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.16</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__lmf.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">Low-Rank Matrix Factorization<div class="ingroups"><a class="el" href="group__grp__datatrans.html">Data Types and Transformations</a> » <a class="el" href="group__grp__arraysmatrix.html">Arrays and Matrices</a> » <a class="el" href="group__grp__matrix__factorization.html">Matrix Factorization</a></div></div> </div> |
| </div><!--header--> |
| <div class="contents"> |
| <div class="toc"><b>Contents</b> <ul> |
| <li> |
| <a href="#syntax">Function Syntax</a> </li> |
| <li> |
| <a href="#examples">Examples</a> </li> |
| <li> |
| <a href="#literature">Literature</a> </li> |
| </ul> |
| </div><p>This module implements "factor model" for representing an incomplete matrix using a low-rank approximation [1]. Mathematically, this model seeks to find matrices U and V (also referred as factors) that, for any given incomplete matrix A, minimizes:</p> |
| <p class="formulaDsp"> |
| \[ \|\boldsymbol A - \boldsymbol UV^{T} \|_2 \] |
| </p> |
| <p>subject to \(rank(\boldsymbol UV^{T}) \leq r\), where \(\|\cdot\|_2\) denotes the Frobenius norm. Let \(A\) be a \(m \times n\) matrix, then \(U\) will be \(m \times r\) and \(V\) will be \(n \times r\), in dimension, and \(1 \leq r \ll \min(m, n)\). This model is not intended to do the full decomposition, or to be used as part of inverse procedure. This model has been widely used in recommendation systems (e.g., Netflix [2]) and feature selection (e.g., image processing [3]).</p> |
| <p><a class="anchor" id="syntax"></a></p><dl class="section user"><dt>Function Syntax</dt><dd></dd></dl> |
| <p>Low-rank matrix factorization of an incomplete matrix into two factors.</p> |
| <pre class="syntax"> |
| lmf_igd_run( rel_output, |
| rel_source, |
| col_row, |
| col_column, |
| col_value, |
| row_dim, |
| column_dim, |
| max_rank, |
| stepsize, |
| scale_factor, |
| num_iterations, |
| tolerance |
| ) |
| </pre><p> <b>Arguments</b> </p><dl class="arglist"> |
| <dt>rel_output </dt> |
| <dd><p class="startdd">TEXT. The name of the table to receive the output.</p> |
| <p>Output factors matrix U and V are in a flattened format. </p><pre>RESULT AS ( |
| matrix_u DOUBLE PRECISION[], |
| matrix_v DOUBLE PRECISION[], |
| rmse DOUBLE PRECISION |
| );</pre><p class="enddd">Features correspond to row i is <code>matrix_u[i:i][1:r]</code>. Features correspond to column j is <code>matrix_v[j:j][1:r]</code>. </p> |
| </dd> |
| <dt>rel_source </dt> |
| <dd><p class="startdd">TEXT. The name of the table containing the input data.</p> |
| <p>The input matrix> is expected to be of the following form: </p><pre>{TABLE|VIEW} <em>input_table</em> ( |
| <em>row</em> INTEGER, |
| <em>col</em> INTEGER, |
| <em>value</em> DOUBLE PRECISION |
| )</pre><p class="enddd">Input is contained in a table that describes an incomplete matrix, with available entries specified as (row, column, value). The input matrix should be 1-based, which means row >= 1, and col >= 1. NULL values are not expected. </p> |
| </dd> |
| <dt>col_row </dt> |
| <dd>TEXT. The name of the column containing the row number. </dd> |
| <dt>col_column </dt> |
| <dd>TEXT. The name of the column containing the column number. </dd> |
| <dt>col_value </dt> |
| <dd>DOUBLE PRECISION. The value at (row, col). </dd> |
| <dt>row_dim (optional) </dt> |
| <dd>INTEGER, default: "SELECT max(col_row) FROM rel_source". The number of columns in the matrix. </dd> |
| <dt>column_dim (optional) </dt> |
| <dd>INTEGER, default: "SELECT max(col_col) FROM rel_source". The number of rows in the matrix. </dd> |
| <dt>max_rank </dt> |
| <dd>INTEGER, default: 20. The rank of desired approximation. </dd> |
| <dt>stepsize (optional) </dt> |
| <dd>DOUBLE PRECISION, default: 0.01. Hyper-parameter that decides how aggressive the gradient steps are. </dd> |
| <dt>scale_factor (optional) </dt> |
| <dd>DOUBLE PRECISION, default: 0.1. Hyper-parameter that decides scale of initial factors. </dd> |
| <dt>num_iterations (optional) </dt> |
| <dd>INTEGER, default: 10. Maximum number if iterations to perform regardless of convergence. </dd> |
| <dt>tolerance (optional) </dt> |
| <dd>DOUBLE PRECISION, default: 0.0001. Acceptable level of error in convergence. </dd> |
| </dl> |
| <p><a class="anchor" id="examples"></a></p><dl class="section user"><dt>Examples</dt><dd></dd></dl> |
| <ol type="1"> |
| <li>Prepare an input table/view: <pre class="example"> |
| DROP TABLE IF EXISTS lmf_data; |
| CREATE TABLE lmf_data ( |
| row INT, |
| col INT, |
| val FLOAT8 |
| ); |
| </pre></li> |
| <li>Populate the input table with some data. <pre class="example"> |
| INSERT INTO lmf_data VALUES (1, 1, 5.0); |
| INSERT INTO lmf_data VALUES (3, 100, 1.0); |
| INSERT INTO lmf_data VALUES (999, 10000, 2.0); |
| </pre></li> |
| <li>Call the <a class="el" href="lmf_8sql__in.html#ac1acb1f0e1f7008118f21c83546a4602" title="Low-rank matrix factorization of a incomplete matrix into two factors. ">lmf_igd_run()</a> stored procedure. <pre class="example"> |
| DROP TABLE IF EXISTS lmf_model; |
| SELECT madlib.lmf_igd_run( 'lmf_model', |
| 'lmf_data', |
| 'row', |
| 'col', |
| 'val', |
| 999, |
| 10000, |
| 3, |
| 0.1, |
| 2, |
| 10, |
| 1e-9 |
| ); |
| </pre> Example result (the exact result may not be the same). <pre class="result"> |
| NOTICE: |
| Finished low-rank matrix factorization using incremental gradient |
| DETAIL: |
| table : lmf_data (row, col, val) |
| Results: |
| RMSE = 0.0145966345300041 |
| Output: |
| view : SELECT * FROM lmf_model WHERE id = 1 |
| lmf_igd_run |
|  ----------- |
| 1 |
| (1 row) |
| </pre></li> |
| <li>Sanity check of the result. You may need a model id returned and also indicated by the function <a class="el" href="lmf_8sql__in.html#ac1acb1f0e1f7008118f21c83546a4602" title="Low-rank matrix factorization of a incomplete matrix into two factors. ">lmf_igd_run()</a>, assuming 1 here: <pre class="example"> |
| SELECT array_dims(matrix_u) AS u_dims, array_dims(matrix_v) AS v_dims |
| FROM lmf_model |
| WHERE id = 1; |
| </pre> Result: <pre class="result"> |
| u_dims | v_dims |
| --------------+---------------- |
| [1:999][1:3] | [1:10000][1:3] |
| (1 row) |
| </pre></li> |
| <li>Query the result value. <pre class="example"> |
| SELECT matrix_u[2:2][1:3] AS row_2_features |
| FROM lmf_model |
| WHERE id = 1; |
| </pre> Example output (the exact result may not be the same): <pre class="result"> |
| row_2_features |
|  --------------------------------------------------------- |
| {{1.12030523084104,0.522217971272767,0.0264869043603539}} |
| (1 row) |
| </pre></li> |
| <li>Make prediction of a missing entry (row=2, col=7654). <pre class="example"> |
| SELECT madlib.array_dot( |
| matrix_u[2:2][1:3], |
| matrix_v[7654:7654][1:3] |
| ) AS row_2_col_7654 |
| FROM lmf_model |
| WHERE id = 1; |
| </pre> Example output (the exact result may not be the same due the randomness of the algorithm): <pre class="result"> |
| row_2_col_7654 |
|  ------------------ |
| 1.3201582940851 |
| (1 row) |
| </pre></li> |
| </ol> |
| <p><a class="anchor" id="literature"></a></p><dl class="section user"><dt>Literature</dt><dd></dd></dl> |
| <p>[1] N. Srebro and T. Jaakkola. “Weighted Low-Rank Approximations.” In: ICML. Ed. by T. Fawcett and N. Mishra. AAAI Press, 2003, pp. 720–727. isbn: 1-57735-189-4.</p> |
| <p>[2] Simon Funk, Netflix Update: Try This at Home, December 11 2006, <a href="http://sifter.org/~simon/journal/20061211.html">http://sifter.org/~simon/journal/20061211.html</a></p> |
| <p>[3] J. Wright, A. Ganesh, S. Rao, Y. Peng, and Y. Ma. “Robust Principal Component Analysis: Exact Recovery of Corrupted Low-Rank Matrices via Convex Optimization.” In: NIPS. Ed. by Y. Bengio, D. Schuurmans, J. D. Lafferty, C. K. I. Williams, and A. Culotta. Curran Associates, Inc., 2009, pp. 2080–2088. isbn: 9781615679119. </p> |
| </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 Tue Jul 2 2019 22:35:51 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> |