You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@madlib.apache.org by ri...@apache.org on 2016/03/30 02:58:50 UTC
[10/51] [partial] incubator-madlib-site git commit: Add all files
from old site (madlib.net)
http://git-wip-us.apache.org/repos/asf/incubator-madlib-site/blob/7258f51a/docs/latest/group__grp__logreg.html
----------------------------------------------------------------------
diff --git a/docs/latest/group__grp__logreg.html b/docs/latest/group__grp__logreg.html
new file mode 100644
index 0000000..bd862cf
--- /dev/null
+++ b/docs/latest/group__grp__logreg.html
@@ -0,0 +1,425 @@
+<!-- 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.10"/>
+<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: Logistic Regression</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);
+ $(window).load(resizeHeight);
+</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 src="../mathjax/MathJax.js"></script>
+<!-- hack in the navigation tree -->
+<script type="text/javascript" src="navtree_hack.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 id="projectlogo"><a href="http://madlib.incubator.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.8</span>
+ </div>
+ <div id="projectbrief">User Documentation for 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.10 -->
+<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__logreg.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">Logistic Regression<div class="ingroups"><a class="el" href="group__grp__super.html">Supervised Learning</a> » <a class="el" href="group__grp__regml.html">Regression Models</a></div></div> </div>
+</div><!--header-->
+<div class="contents">
+<div class="toc"><b>Contents</b></p><ul>
+<li class="level1">
+<a href="#train">Training Function</a> </li>
+<li class="level1">
+<a href="#predict">Prediction Function</a> </li>
+<li class="level1">
+<a href="#examples">Examples</a> </li>
+<li class="level1">
+<a href="#background">Technical Background</a> </li>
+<li class="level1">
+<a href="#literature">Literature</a> </li>
+<li class="level1">
+<a href="#related">Related Topics</a> </li>
+</ul>
+</div><p>Binomial logistic regression models the relationship between a dichotomous dependent variable and one or more predictor variables. The dependent variable may be a Boolean value or a categorial variable that can be represented with a Boolean expression. The probabilities describing the possible outcomes of a single trial are modeled, as a function of the predictor variables, using a logistic function.</p>
+<p><a class="anchor" id="train"></a></p><dl class="section user"><dt>Training Function</dt><dd>The logistic regression training function has the following format: <pre class="syntax">
+logregr_train( source_table,
+ out_table,
+ dependent_varname,
+ independent_varname,
+ grouping_cols,
+ max_iter,
+ optimizer,
+ tolerance,
+ verbose
+ )
+</pre> <b>Arguments</b> <dl class="arglist">
+<dt>source_table </dt>
+<dd><p class="startdd">TEXT. The name of the table containing the training data.</p>
+<p class="enddd"></p>
+</dd>
+<dt>out_table </dt>
+<dd><p class="startdd">TEXT. Name of the generated table containing the output model.</p>
+<p>The output table produced by the logistic regression training function contains the following columns:</p>
+<table class="output">
+<tr>
+<th><...> </th><td><p class="starttd">Text. Grouping columns, if provided in input. This could be multiple columns depending on the <code>grouping_col</code> input. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>coef </th><td><p class="starttd">FLOAT8. Vector of the coefficients of the regression. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>log_likelihood </th><td><p class="starttd">FLOAT8. The log-likelihood \( l(\boldsymbol c) \). </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>std_err </th><td><p class="starttd">FLOAT8[]. Vector of the standard error of the coefficients. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>z_stats </th><td><p class="starttd">FLOAT8[]. Vector of the z-statistics of the coefficients. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>p_values </th><td><p class="starttd">FLOAT8[]. Vector of the p-values of the coefficients. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>odds_ratios </th><td><p class="starttd">FLOAT8[]. The odds ratio, \( \exp(c_i) \). </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>condition_no </th><td><p class="starttd">FLOAT8[]. The condition number of the \(X^{*}X\) matrix. A high condition number is usually an indication that there may be some numeric instability in the result yielding a less reliable model. A high condition number often results when there is a significant amount of colinearity in the underlying design matrix, in which case other regression techniques may be more appropriate. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>num_iterations </th><td>INTEGER. The number of iterations actually completed. This would be different from the <code>nIterations</code> argument if a <code>tolerance</code> parameter is provided and the algorithm converges before all iterations are completed. </td></tr>
+<tr>
+<th>num_rows_processed </th><td>INTEGER. The number of rows actually processed, which is equal to the total number of rows in the source table minus the number of skipped rows. </td></tr>
+<tr>
+<th>num_missing_rows_skipped </th><td>INTEGER. The number of rows skipped during the training. A row will be skipped if the independent_varname is NULL or contains NULL values. </td></tr>
+</table>
+<p>A summary table named <out_table>_summary is also created at the same time, which has the following columns: </p><table class="output">
+<tr>
+<th>source_table </th><td><p class="starttd">The data source table name. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>out_table </th><td><p class="starttd">The output table name. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>dependent_varname </th><td><p class="starttd">The dependent variable. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>independent_varname </th><td><p class="starttd">The independent variables </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>optimizer_params </th><td><p class="starttd">A string that contains all the optimizer parameters, and has the form of 'optimizer=..., max_iter=..., tolerance=...' </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>num_all_groups </th><td><p class="starttd">How many groups of data were fit by the logistic model. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>num_failed_groups </th><td><p class="starttd">How many groups' fitting processes failed. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>num_rows_processed </th><td><p class="starttd">The total number of rows usd in the computation. </p>
+<p class="endtd"></p>
+</td></tr>
+<tr>
+<th>num_missing_rows_skipped </th><td>The total number of rows skipped. </td></tr>
+</table>
+<p class="enddd"></p>
+</dd>
+<dt>dependent_varname </dt>
+<dd><p class="startdd">TEXT. Name of the dependent variable column (of type BOOLEAN) in the training data or an expression evaluating to a BOOLEAN.</p>
+<p class="enddd"></p>
+</dd>
+<dt>independent_varname </dt>
+<dd><p class="startdd">TEXT. Expression list to evaluate for the independent variables. An intercept variable is not assumed. It is common to provide an explicit intercept term by including a single constant <code>1</code> term in the independent variable list.</p>
+<p class="enddd"></p>
+</dd>
+<dt>grouping_cols (optional) </dt>
+<dd><p class="startdd">TEXT, default: NULL. An expression list used to group the input dataset into discrete groups, running one regression per group. Similar to the SQL "GROUP BY" clause. When this value is NULL, no grouping is used and a single result model is generated.</p>
+<p class="enddd"></p>
+</dd>
+<dt>max_iter (optional) </dt>
+<dd><p class="startdd">INTEGER, default: 20. The maximum number of iterations that are allowed.</p>
+<p class="enddd"></p>
+</dd>
+<dt>optimizer (optional) </dt>
+<dd><p class="startdd">TEXT, default: 'irls'. The name of the optimizer to use: </p><table class="output">
+<tr>
+<th>'newton' or 'irls' </th><td>Iteratively reweighted least squares </td></tr>
+<tr>
+<th>'cg' </th><td>conjugate gradient </td></tr>
+<tr>
+<th>'igd' </th><td>incremental gradient descent. </td></tr>
+</table>
+<p class="enddd"></p>
+</dd>
+<dt>tolerance (optional) </dt>
+<dd><p class="startdd">FLOAT8, default: 0.0001. The difference between log-likelihood values in successive iterations that should indicate convergence. A zero disables the convergence criterion, so that execution stops after <code>n</code> iterations have completed.</p>
+<p class="enddd"></p>
+</dd>
+<dt>verbose (optional) </dt>
+<dd>BOOLEAN, default: FALSE. Provides verbose output of the results of training. </dd>
+</dl>
+</dd></dl>
+<dl class="section note"><dt>Note</dt><dd>For p-values, we just return the computation result directly. Other statistical packages, like 'R', produce the same result, but on printing the result to screen, another format function is used and any p-value that is smaller than the machine epsilon (the smallest positive floating-point number 'x' such that '1 + x != 1') will be printed on screen as "< xxx" (xxx is the value of the machine epsilon). Although the result may look different, they are in fact the same.</dd></dl>
+<p><a class="anchor" id="predict"></a></p><dl class="section user"><dt>Prediction Function</dt><dd>Two prediction functions are provided to either predict the boolean value of the dependent variable or the probability of the value of dependent variable being 'True', both functions using the same syntax.</dd></dl>
+<p>The function to predict the boolean value (True/False) of the dependent variable has the following syntax: </p><pre class="syntax">
+logregr_predict(coefficients,
+ ind_var
+ )
+</pre><p>The function to predict the probability of the dependent variable being True has the following syntax: </p><pre class="syntax">
+logregr_predict_prob(coefficients,
+ ind_var
+ )
+</pre><p><b>Arguments</b> </p><dl class="arglist">
+<dt>coefficients </dt>
+<dd><p class="startdd">DOUBLE PRECISION[]. Model coefficients obtained from <a class="el" href="logistic_8sql__in.html#a74210a7ef513dfcbdfdd9f3b37bfe428">logregr_train()</a>.</p>
+<p class="enddd"></p>
+</dd>
+<dt>ind_var </dt>
+<dd>Independent variables, as a DOUBLE array. This should be the same length as the array obtained by evaluation of the 'independent_varname' argument in <a class="el" href="logistic_8sql__in.html#a74210a7ef513dfcbdfdd9f3b37bfe428">logregr_train()</a>. </dd>
+</dl>
+<p><a class="anchor" id="examples"></a></p><dl class="section user"><dt>Examples</dt><dd><ol type="1">
+<li>Create the training data table. <pre class="example">
+CREATE TABLE patients( id INTEGER NOT NULL,
+ second_attack INTEGER,
+ treatment INTEGER,
+ trait_anxiety INTEGER);
+COPY patients FROM STDIN WITH DELIMITER '|';
+ 1 | 1 | 1 | 70
+ 3 | 1 | 1 | 50
+ 5 | 1 | 0 | 40
+ 7 | 1 | 0 | 75
+ 9 | 1 | 0 | 70
+ 11 | 0 | 1 | 65
+ 13 | 0 | 1 | 45
+ 15 | 0 | 1 | 40
+ 17 | 0 | 0 | 55
+ 19 | 0 | 0 | 50
+ 2 | 1 | 1 | 80
+ 4 | 1 | 0 | 60
+ 6 | 1 | 0 | 65
+ 8 | 1 | 0 | 80
+ 10 | 1 | 0 | 60
+ 12 | 0 | 1 | 50
+ 14 | 0 | 1 | 35
+ 16 | 0 | 1 | 50
+ 18 | 0 | 0 | 45
+ 20 | 0 | 0 | 60
+\.
+</pre></li>
+<li>Train a regression model. <pre class="example">
+SELECT madlib.logregr_train( 'patients',
+ 'patients_logregr',
+ 'second_attack',
+ 'ARRAY[1, treatment, trait_anxiety]',
+ NULL,
+ 20,
+ 'irls'
+ );
+</pre></li>
+<li>View the regression results. <pre class="example">
+-- Set extended display on for easier reading of output
+\x on
+SELECT * from patients_logregr;
+</pre> Result: <pre class="result">
+coef | {5.59049410898112,2.11077546770772,-0.237276684606453}
+log_likelihood | -467.214718489873
+std_err | {0.318943457652178,0.101518723785383,0.294509929481773}
+z_stats | {17.5281667482197,20.7919819024719,-0.805666162169712}
+p_values | {8.73403463417837e-69,5.11539430631541e-96,0.420435365338518}
+odds_ratios | {267.867942976278,8.2546400100702,0.788773016471171}
+condition_no | 179.186118573205
+num_iterations | 9
+</pre></li>
+<li>Alternatively, unnest the arrays in the results for easier reading of output: <pre class="example">
+\x off
+SELECT unnest(array['intercept', 'treatment', 'trait_anxiety']) as attribute,
+ unnest(coef) as coefficient,
+ unnest(std_err) as standard_error,
+ unnest(z_stats) as z_stat,
+ unnest(p_values) as pvalue,
+ unnest(odds_ratios) as odds_ratio
+ FROM patients_logregr;
+</pre></li>
+<li>Predicting dependent variable using the logistic regression model. (This example uses the original data table to perform the prediction. Typically a different test dataset with the same features as the original training dataset would be used for prediction.) <pre class="example">
+\x off
+-- Display prediction value along with the original value
+SELECT p.id, madlib.logregr_predict(coef, ARRAY[1, treatment, trait_anxiety]),
+ p.second_attack
+FROM patients p, patients_logregr m
+ORDER BY p.id;
+</pre></li>
+<li>Predicting the probability of the dependent variable being TRUE. <pre class="example">
+\x off
+-- Display prediction value along with the original value
+SELECT p.id, madlib.logregr_predict_prob(coef, ARRAY[1, treatment, trait_anxiety])
+FROM patients p, patients_logregr m
+ORDER BY p.id;
+</pre></li>
+</ol>
+</dd></dl>
+<p><a class="anchor" id="notes"></a></p><dl class="section user"><dt>Notes</dt><dd>All table names can be optionally schema qualified (current_schemas() would be searched if a schema name is not provided) and all table and column names should follow case-sensitivity and quoting rules per the database. (For instance, 'mytable' and 'MyTable' both resolve to the same entity, i.e. 'mytable'. If mixed-case or multi-byte characters are desired for entity names then the string should be double-quoted; in this case the input would be '"MyTable"').</dd></dl>
+<p><a class="anchor" id="background"></a></p><dl class="section user"><dt>Technical Background</dt><dd></dd></dl>
+<p>(Binomial) logistic regression refers to a stochastic model in which the conditional mean of the dependent dichotomous variable (usually denoted \( Y \in \{ 0,1 \} \)) is the logistic function of an affine function of the vector of independent variables (usually denoted \( \boldsymbol x \)). That is, </p><p class="formulaDsp">
+\[ E[Y \mid \boldsymbol x] = \sigma(\boldsymbol c^T \boldsymbol x) \]
+</p>
+<p> for some unknown vector of coefficients \( \boldsymbol c \) and where \( \sigma(x) = \frac{1}{1 + \exp(-x)} \) is the logistic function. Logistic regression finds the vector of coefficients \( \boldsymbol c \) that maximizes the likelihood of the observations.</p>
+<p>Let</p><ul>
+<li>\( \boldsymbol y \in \{ 0,1 \}^n \) denote the vector of observed dependent variables, with \( n \) rows, containing the observed values of the dependent variable,</li>
+<li>\( X \in \mathbf R^{n \times k} \) denote the design matrix with \( k \) columns and \( n \) rows, containing all observed vectors of independent variables \( \boldsymbol x_i \) as rows.</li>
+</ul>
+<p>By definition, </p><p class="formulaDsp">
+\[ P[Y = y_i | \boldsymbol x_i] = \sigma((-1)^{(1 - y_i)} \cdot \boldsymbol c^T \boldsymbol x_i) \,. \]
+</p>
+<p> Maximizing the likelihood \( \prod_{i=1}^n \Pr(Y = y_i \mid \boldsymbol x_i) \) is equivalent to maximizing the log-likelihood \( \sum_{i=1}^n \log \Pr(Y = y_i \mid \boldsymbol x_i) \), which simplifies to </p><p class="formulaDsp">
+\[ l(\boldsymbol c) = -\sum_{i=1}^n \log(1 + \exp((-1)^{(1 - y_i)} \cdot \boldsymbol c^T \boldsymbol x_i)) \,. \]
+</p>
+<p> The Hessian of this objective is \( H = -X^T A X \) where \( A = \text{diag}(a_1, \dots, a_n) \) is the diagonal matrix with \( a_i = \sigma(\boldsymbol c^T \boldsymbol x) \cdot \sigma(-\boldsymbol c^T \boldsymbol x) \,. \) Since \( H \) is non-positive definite, \( l(\boldsymbol c) \) is convex. There are many techniques for solving convex optimization problems. Currently, logistic regression in MADlib can use one of three algorithms:</p><ul>
+<li>Iteratively Reweighted Least Squares</li>
+<li>A conjugate-gradient approach, also known as Fletcher-Reeves method in the literature, where we use the Hestenes-Stiefel rule for calculating the step size.</li>
+<li>Incremental gradient descent, also known as incremental gradient methods or stochastic gradient descent in the literature.</li>
+</ul>
+<p>We estimate the standard error for coefficient \( i \) as </p><p class="formulaDsp">
+\[ \mathit{se}(c_i) = \left( (X^T A X)^{-1} \right)_{ii} \,. \]
+</p>
+<p> The Wald z-statistic is </p><p class="formulaDsp">
+\[ z_i = \frac{c_i}{\mathit{se}(c_i)} \,. \]
+</p>
+<p>The Wald \( p \)-value for coefficient \( i \) gives the probability (under the assumptions inherent in the Wald test) of seeing a value at least as extreme as the one observed, provided that the null hypothesis ( \( c_i = 0 \)) is true. Letting \( F \) denote the cumulative density function of a standard normal distribution, the Wald \( p \)-value for coefficient \( i \) is therefore </p><p class="formulaDsp">
+\[ p_i = \Pr(|Z| \geq |z_i|) = 2 \cdot (1 - F( |z_i| )) \]
+</p>
+<p> where \( Z \) is a standard normally distributed random variable.</p>
+<p>The odds ratio for coefficient \( i \) is estimated as \( \exp(c_i) \).</p>
+<p>The condition number is computed as \( \kappa(X^T A X) \) during the iteration immediately <em>preceding</em> convergence (i.e., \( A \) is computed using the coefficients of the previous iteration). A large condition number (say, more than 1000) indicates the presence of significant multicollinearity.</p>
+<p><a class="anchor" id="literature"></a></p><dl class="section user"><dt>Literature</dt><dd></dd></dl>
+<p>A somewhat random selection of nice write-ups, with valuable pointers into further literature.</p>
+<p>[1] Cosma Shalizi: Statistics 36-350: Data Mining, Lecture Notes, 18 November 2009, <a href="http://www.stat.cmu.edu/~cshalizi/350/lectures/26/lecture-26.pdf">http://www.stat.cmu.edu/~cshalizi/350/lectures/26/lecture-26.pdf</a></p>
+<p>[2] Thomas P. Minka: A comparison of numerical optimizers for logistic regression, 2003 (revised Mar 26, 2007), <a href="http://research.microsoft.com/en-us/um/people/minka/papers/logreg/minka-logreg.pdf">http://research.microsoft.com/en-us/um/people/minka/papers/logreg/minka-logreg.pdf</a></p>
+<p>[3] Paul Komarek, Andrew W. Moore: Making Logistic Regression A Core Data Mining Tool With TR-IRLS, IEEE International Conference on Data Mining 2005, pp. 685-688, <a href="http://komarix.org/ac/papers/tr-irls.short.pdf">http://komarix.org/ac/papers/tr-irls.short.pdf</a></p>
+<p>[4] D. P. Bertsekas: Incremental gradient, subgradient, and proximal methods for convex optimization: a survey, Technical report, Laboratory for Information and Decision Systems, 2010, <a href="http://web.mit.edu/dimitrib/www/Incremental_Survey_LIDS.pdf">http://web.mit.edu/dimitrib/www/Incremental_Survey_LIDS.pdf</a></p>
+<p>[5] A. Nemirovski, A. Juditsky, G. Lan, and A. Shapiro: Robust stochastic approximation approach to stochastic programming, SIAM Journal on Optimization, 19(4), 2009, <a href="http://www2.isye.gatech.edu/~nemirovs/SIOPT_RSA_2009.pdf">http://www2.isye.gatech.edu/~nemirovs/SIOPT_RSA_2009.pdf</a></p>
+<p><a class="anchor" id="related"></a></p><dl class="section user"><dt>Related Topics</dt><dd></dd></dl>
+<p>File <a class="el" href="logistic_8sql__in.html" title="SQL functions for logistic regression. ">logistic.sql_in</a> documenting the training function</p>
+<p><a class="el" href="logistic_8sql__in.html#a74210a7ef513dfcbdfdd9f3b37bfe428" title="Compute logistic-regression coefficients and diagnostic statistics. ">logregr_train()</a></p>
+<p><a class="el" href="elastic__net_8sql__in.html#a735038a5090c112505c740a90a203e83" title="Interface for elastic net. ">elastic_net_train()</a></p>
+<p><a class="el" href="group__grp__linreg.html">Linear Regression</a></p>
+<p><a class="el" href="group__grp__multinom.html">Multinomial Regression</a></p>
+<p><a class="el" href="group__grp__ordinal.html">Ordinal Regression</a></p>
+<p><a class="el" href="group__grp__robust.html">Robust Variance</a></p>
+<p><a class="el" href="group__grp__clustered__errors.html">Clustered Variance</a></p>
+<p><a class="el" href="group__grp__validation.html">Cross Validation</a></p>
+<p><a class="el" href="group__grp__marginal.html">Marginal Effects</a></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 Mon Jul 27 2015 20:37:45 for MADlib by
+ <a href="http://www.doxygen.org/index.html">
+ <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
+ </ul>
+</div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-madlib-site/blob/7258f51a/docs/latest/group__grp__marginal.html
----------------------------------------------------------------------
diff --git a/docs/latest/group__grp__marginal.html b/docs/latest/group__grp__marginal.html
new file mode 100644
index 0000000..3ab5435
--- /dev/null
+++ b/docs/latest/group__grp__marginal.html
@@ -0,0 +1,434 @@
+<!-- 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.10"/>
+<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: Marginal Effects</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);
+ $(window).load(resizeHeight);
+</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 src="../mathjax/MathJax.js"></script>
+<!-- hack in the navigation tree -->
+<script type="text/javascript" src="navtree_hack.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 id="projectlogo"><a href="http://madlib.incubator.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.8</span>
+ </div>
+ <div id="projectbrief">User Documentation for 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.10 -->
+<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__marginal.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">Marginal Effects<div class="ingroups"><a class="el" href="group__grp__super.html">Supervised Learning</a> » <a class="el" href="group__grp__regml.html">Regression Models</a></div></div> </div>
+</div><!--header-->
+<div class="contents">
+<div class="toc"><b>Contents</b> </p><ul>
+<li>
+<a href="#margins">Marginal Effects with Interaction Terms</a> </li>
+<li>
+<a href="#examples">Examples</a> </li>
+<li>
+<a href="#notes">Notes</a> </li>
+<li>
+<a href="#background">Technical Background</a> </li>
+<li>
+<a href="#literature">Literature</a> </li>
+<li>
+<a href="#related">Related Topics</a> </li>
+</ul>
+</div><p>A marginal effect (ME) or partial effect measures the effect on the conditional mean of \( y \) for a change in one of the regressors, say \(X_k\). In the linear regression model, the ME equals the relevant slope coefficient, greatly simplifying analysis. For nonlinear models, specialized algorithms are required for calculating ME. The marginal effect computed is the average of the marginal effect at every data point present in the source table.</p>
+<p>MADlib provides marginal effects regression functions for linear, logistic and multinomial logistic regressions.</p>
+<dl class="section warning"><dt>Warning</dt><dd>The <a class="el" href="marginal_8sql__in.html#a9517d679ee4209126895445cbed51fe3">margins_logregr()</a> and <a class="el" href="marginal_8sql__in.html#ae39ad0e1beca060fd153dba35901a4e7">margins_mlogregr()</a> functions have been deprecated in favor of the <a class="el" href="marginal_8sql__in.html#a36fcae5245ca31517723fce38b183c90" title="Marginal effects with default variable_names. ">margins()</a> function.</dd></dl>
+<p><a class="anchor" id="margins"></a></p><dl class="section user"><dt>Marginal Effects with Interaction Terms</dt><dd><pre class="syntax">
+margins( model_table,
+ output_table,
+ x_design,
+ source_table,
+ marginal_vars
+ )
+</pre> <b>Arguments</b> <dl class="arglist">
+<dt>model_table </dt>
+<dd>VARCHAR. The name of the model table, which is the output of <a class="el" href="logistic_8sql__in.html#a74210a7ef513dfcbdfdd9f3b37bfe428" title="Compute logistic-regression coefficients and diagnostic statistics. ">logregr_train()</a> or <a class="el" href="multilogistic_8sql__in.html#aedc13474e6abbc88451d120ad97e44d4" title="Compute multinomial logistic regression coefficients. ">mlogregr_train()</a>. </dd>
+<dt>output_table </dt>
+<dd>VARCHAR. The name of the result table. The output table has the following columns. <table class="output">
+<tr>
+<th>variables </th><td>INTEGER[]. The indices of the basis variables. </td></tr>
+<tr>
+<th>margins </th><td>DOUBLE PRECISION[]. The marginal effects. </td></tr>
+<tr>
+<th>std_err </th><td>DOUBLE PRECISION[]. An array of the standard errors, computed using the delta method. </td></tr>
+<tr>
+<th>z_stats </th><td>DOUBLE PRECISION[]. An array of the z-stats of the marginal effects. </td></tr>
+<tr>
+<th>p_values </th><td>DOUBLE PRECISION[]. An array of the Wald p-values of the marginal effects. </td></tr>
+</table>
+</dd>
+<dt>x_design (optional) </dt>
+<dd><p class="startdd">VARCHAR, default: NULL. The design of independent variables, necessary only if interaction term or indicator (categorical) terms are present. This parameter is necessary since the independent variables in the underlying regression is not parsed to extract the relationship between variables.</p>
+<p>Example: The <em>independent_varname</em> in the regression method can be specified in either of the following ways:</p><ul>
+<li><code> ‘array[1, color_blue, color_green, gender_female, gpa, gpa^2, gender_female*gpa, gender_female*gpa^2, weight]’ </code></li>
+<li><code> ‘x’ </code></li>
+</ul>
+<p>In the second version, the column <em>x</em> is an array containing data identical to that expressed in the first version, computed in a prior data preparation step. Supply an <em>x_design argument</em> to the <a class="el" href="marginal_8sql__in.html#a36fcae5245ca31517723fce38b183c90" title="Marginal effects with default variable_names. ">margins()</a> function in the following way:</p><ul>
+<li><code> ‘1, i.color_blue.color, i.color_green.color, i.gender_female, gpa, gpa^2, gender_female*gpa, gender_female*gpa^2, weight’</code></li>
+</ul>
+<p>The variable names (<em>'gpa', 'weight', ...</em>), referred to here as <em>identifiers</em>, should be unique for each basis variable and need not be the same as the original variable name in <em>independent_varname</em>. They should, however, be in the same order as the corresponding variables in <em>independent_varname</em>. The length of <em>x_design</em> is expected to be the same as the length of <em>independent_varname</em>. Each <em>identifier</em> name can contain only alphanumeric characters and the underscore.</p>
+<p>Indicator (dummy) variables are prefixed with an 'i.' (This is only necessary for the basis term; it is not needed in the interaction terms.) Indicator variables that are obtained from the same categorical variable (for example, 'color_blue' and 'color_green') need to have a common and unique suffix (for example, '.color'). The '.' is used to add the prefix and suffix. If a reference indicator variable is present, it should contain the prefix 'ir.'.</p>
+<p>An identifier may contain alphanumeric characters and underscores. To include other characters, the string must be double-quoted. Escape-characters are not currently supported. </p>
+<p class="enddd"></p>
+</dd>
+<dt>source_table (optional) </dt>
+<dd><p class="startdd">VARCHAR, default: NULL. Name of the data table to apply marginal effects on. If not provided or NULL then the marginal effects are computed on the training table.</p>
+<p class="enddd"></p>
+</dd>
+<dt>marginal_vars (optional) </dt>
+<dd>VARCHAR, default: NULL. Comma-separated string containing specific variable identifiers to calculate marginal effects on. When NULL, marginal effects for all variables are returned. </dd>
+</dl>
+</dd></dl>
+<dl class="section note"><dt>Note</dt><dd>No output will be provided for the reference indicator variable, since the marginal effect for that variable is undefined. If a reference variable is included in the independent variables and <em>marginal_vars</em>, the <a class="el" href="marginal_8sql__in.html#a36fcae5245ca31517723fce38b183c90" title="Marginal effects with default variable_names. ">margins()</a> function will ignore that variable for the output. The variable can still be included in the regression and margins, since it will affect the values for other related indicator variables.</dd></dl>
+<p><a class="anchor" id="logregr_train"></a></p><dl class="section user"><dt>Marginal Effects for Logistic Regression</dt><dd></dd></dl>
+<dl class="section warning"><dt>Warning</dt><dd>This function has been deprecated in favor of the <a class="el" href="marginal_8sql__in.html#a36fcae5245ca31517723fce38b183c90" title="Marginal effects with default variable_names. ">margins()</a> function.</dd></dl>
+<pre class="syntax">
+margins_logregr( source_table,
+ output_table,
+ dependent_variable,
+ independent_variable,
+ grouping_cols,
+ marginal_vars,
+ max_iter,
+ optimizer,
+ tolerance,
+ verbose_mode
+ )
+</pre><p> <b>Arguments</b> </p><dl class="arglist">
+<dt>source_table </dt>
+<dd>VARCHAR. The name of the data table. </dd>
+<dt>output_table </dt>
+<dd><p class="startdd">VARCHAR. The name of the result table. The output table has the following columns. </p><table class="output">
+<tr>
+<th>margins </th><td>DOUBLE PRECISION[]. The marginal effects. </td></tr>
+<tr>
+<th>std_err </th><td>DOUBLE PRECISION[]. An array of the standard errors, using the delta method. </td></tr>
+<tr>
+<th>z_stats </th><td>DOUBLE PRECISION[]. An array of the z-stats of the marginal effects. </td></tr>
+<tr>
+<th>p_values </th><td>DOUBLE PRECISION[]. An array of the Wald p-values of the marginal effects. </td></tr>
+</table>
+<p>A summary table named <output_table>_summary is also created, which is the same as the summary table created by <a class="el" href="logistic_8sql__in.html#a74210a7ef513dfcbdfdd9f3b37bfe428" title="Compute logistic-regression coefficients and diagnostic statistics. ">logregr_train()</a> function. Refer to the documentation for logistic regression for details.</p>
+<p class="enddd"></p>
+</dd>
+<dt>dependent_variable </dt>
+<dd>VARCHAR. The name of the column for dependent variables. </dd>
+<dt>independent_variable </dt>
+<dd>VARCHAR. The name of the column for independent variables. Can be any SQL expression that evaluates to an array. </dd>
+<dt>grouping_cols (optional) </dt>
+<dd>VARCHAR, default: NULL. <em>Not currently implemented. Any non-NULL value is ignored.</em> An expression list used to group the input dataset into discrete groups, running one regression per group. Similar to the SQL "GROUP BY" clause. When this value is NULL, no grouping is used and a single result model is generated. </dd>
+<dt>marginal_vars (optional) </dt>
+<dd>INTEGER[], default: NULL. An index list (base 1) representing the independent variables to compute marginal effects on. When NULL, computes marginal effects on all variables. </dd>
+<dt>max_iter (optional) </dt>
+<dd>INTEGER, default: 20. The maximum number of iterations for the logistic regression. </dd>
+<dt>optimizer (optional) </dt>
+<dd>VARCHAR, default: 'irls'. The optimizer to use for the logistic regression: newton/irls, cg, or igd. </dd>
+<dt>tolerance (optional) </dt>
+<dd>DOUBLE PRECISION, default: 1e-4. Termination criterion for logistic regression (relative). </dd>
+<dt>verbose_mode (optional) </dt>
+<dd>BOOLEAN, default FALSE. When TRUE, provides verbose output of the results of training. </dd>
+</dl>
+<p><a class="anchor" id="mlogregr_train"></a></p><dl class="section user"><dt>Marginal Effects for Multinomial Logistic Regression</dt><dd></dd></dl>
+<dl class="section warning"><dt>Warning</dt><dd>This function has been deprecated in favor of the <a class="el" href="marginal_8sql__in.html#a36fcae5245ca31517723fce38b183c90" title="Marginal effects with default variable_names. ">margins()</a> function.</dd></dl>
+<pre class="syntax">
+margins_mlogregr( source_table,
+ out_table,
+ dependent_varname,
+ independent_varname,
+ ref_category,
+ grouping_cols,
+ marginal_vars,
+ optimizer_params,
+ verbose_mode
+ )
+</pre><p> <b>Arguments</b> </p><dl class="arglist">
+<dt>source_table </dt>
+<dd>VARCHAR. The name of data table. </dd>
+<dt>out_table </dt>
+<dd><p class="startdd">VARCHAR. The name of result table. The output table has the following columns. </p><table class="output">
+<tr>
+<th>category </th><td>The category. </td></tr>
+<tr>
+<th>ref_category </th><td>The refererence category used for modeling. </td></tr>
+<tr>
+<th>margins </th><td>DOUBLE PRECISION[]. The marginal effects. </td></tr>
+<tr>
+<th>std_err </th><td>DOUBLE PRECISION[]. An array of the standard errors, using the delta method. </td></tr>
+<tr>
+<th>z_stats </th><td>DOUBLE PRECISION[]. An array of the z-stats of the marginal effects. </td></tr>
+<tr>
+<th>p_values </th><td>DOUBLE PRECISION[]. An array of the Wald p-values of the marginal effects. </td></tr>
+</table>
+<p>A summary table named <out_table>_summary is also created, which is the same as the summary table created by <a class="el" href="multilogistic_8sql__in.html#aedc13474e6abbc88451d120ad97e44d4" title="Compute multinomial logistic regression coefficients. ">mlogregr_train()</a> function. Refer to the documentation for multinomial logistic regression for details.</p>
+<p class="enddd"></p>
+</dd>
+<dt>dependent_varname </dt>
+<dd>VARCHAR. The name of the column for dependent variables. </dd>
+<dt>independent_varname </dt>
+<dd>VARCHAR. The name of the column for independent variables. Can be any SQL expression that evaluates to an array. </dd>
+<dt>ref_category (optional) </dt>
+<dd>INTEGER, default: 0. Reference category for the multinomial logistic regression. </dd>
+<dt>grouping_cols (optional) </dt>
+<dd>VARCHAR, default: NULL. <em>Not currently implemented. Any non-NULL value is ignored.</em> An expression list used to group the input dataset into discrete groups, running one regression per group. Similar to the SQL "GROUP BY" clause. When this value is NULL, no grouping is used and a single result model is generated. </dd>
+<dt>marginal_vars(optional) </dt>
+<dd>INTEGER[], default: NULL. An index list (base 1) representing the independent variables to compute marginal effects on. When NULL, computes marginal effects on all variables. </dd>
+<dt>optimizer_params (optional) </dt>
+<dd>TEXT, default: NULL, which uses the default values of optimizer parameters: max_iter=20, optimizer='newton', tolerance=1e-4. It should be a string that contains 'key=value' pairs separated by commas. </dd>
+<dt>verbose_mode (optional) </dt>
+<dd>BOOLEAN, default FALSE. When TRUE, provides verbose output of the results of training. </dd>
+</dl>
+<p><a class="anchor" id="examples"></a></p><dl class="section user"><dt>Examples</dt><dd></dd></dl>
+<ol type="1">
+<li>View online help for the marginal effects function. <pre class="example">
+SELECT madlib.margins();
+</pre></li>
+<li>Create the sample data set. Use the <code>patients</code> dataset from the <a href="group__grp__logreg.html#examples">Logistic Regression examples</a>. <pre class="example">
+SELECT * FROM patients;
+</pre> Result: <pre class="result">
+ id | second_attack | treatment | trait_anxiety
+ ---+---------------+-----------+---------------
+ 1 | 1 | 1 | 70
+ 3 | 1 | 1 | 50
+ 5 | 1 | 0 | 40
+ 7 | 1 | 0 | 75
+ 9 | 1 | 0 | 70
+ 11 | 0 | 1 | 65
+ 13 | 0 | 1 | 45
+ 15 | 0 | 1 | 40
+ 17 | 0 | 0 | 55
+ 19 | 0 | 0 | 50
+ 2 | 1 | 1 | 80
+ 4 | 1 | 0 | 60
+ 6 | 1 | 0 | 65
+ 8 | 1 | 0 | 80
+ 10 | 1 | 0 | 60
+ 12 | 0 | 1 | 50
+ 14 | 0 | 1 | 35
+ 16 | 0 | 1 | 50
+ 18 | 0 | 0 | 45
+ 20 | 0 | 0 | 60
+</pre></li>
+<li>Run logistic regression to get the model, compute the marginal effects of all variables, and view the results. <pre class="example">
+DROP TABLE IF EXISTS model_table;
+DROP TABLE IF EXISTS model_table_summary;
+DROP TABLE IF EXISTS margins_table;
+SELECT madlib.logregr_train( 'patients',
+ 'model_table',
+ 'second_attack',
+ 'ARRAY[1, treatment, trait_anxiety, treatment^2, treatment * trait_anxiety]'
+ );
+SELECT madlib.margins( 'model_table',
+ 'margins_table',
+ 'intercept, treatment, trait_anxiety, treatment^2, treatment*trait_anxiety',
+ NULL,
+ NULL
+ );
+\x ON
+SELECT * FROM margins_table;
+</pre> Result: <pre class="result">
+variables | {intercept, treatment, trait_anxiety}
+margins | {-0.876046514609573,-0.0648833521465306,0.0177196513589633}
+std_err | {0.551714275062467,0.373592457067442,0.00458001207971933}
+z_stats | {-1.58786269307674,-0.173674149247659,3.86890930646828}
+p_values | {0.112317391159946,0.862121554662231,0.000109323294026272}
+</pre></li>
+<li>Compute the marginal effects of the first variable using the previous model and view the results (using different names in 'x_design'). <pre class="example">
+DROP TABLE IF EXISTS result_table;
+SELECT madlib.margins( 'model_table',
+ 'result_table',
+ 'i, tre, tra, tre^2, tre*tra',
+ NULL,
+ 'tre'
+ );
+SELECT * FROM result_table;
+</pre> Result: <pre class="result">
+-[ RECORD 1 ]-------------------
+variables | {tre}
+margins | {-0.110453283517281}
+std_err | {0.228981529064089}
+z_stats | {-0.482367656329023}
+p_values | {0.629544793219806}
+</pre></li>
+<li>Create a sample data set for multinomial logistic regression. (The full dataset has three categories.) Use the dataset from the <a href="group__grp__mlogreg.html#examples">Multinomial Regression example</a>. <pre class="example">
+\x OFF
+SELECT * FROM test3;
+</pre> Result: <pre class="result">
+ feat1 | feat2 | cat
+-------+-------+-----
+ 2 | 33 | 0
+ 2 | 31 | 1
+ 2 | 36 | 1
+ 2 | 31 | 1
+ 2 | 41 | 1
+ 2 | 37 | 1
+ 2 | 44 | 1
+ 2 | 46 | 1
+ 2 | 46 | 2
+ 2 | 39 | 0
+ 2 | 44 | 1
+ 2 | 44 | 0
+ 2 | 67 | 2
+ 2 | 59 | 2
+ 2 | 59 | 0
+...
+</pre></li>
+<li>Run the regression function and then compute the marginal effects of all variables in the regression. <pre class="example">
+DROP TABLE IF EXISTS model_table;
+DROP TABLE IF EXISTS model_table_summary;
+DROP TABLE IF EXISTS result_table;
+SELECT madlib.mlogregr_train('test3', 'model_table', 'cat',
+ 'ARRAY[1, feat1, feat2, feat1*feat2]',
+ 0);
+SELECT madlib.margins('model_table',
+ 'result_table',
+ 'intercept, feat1, feat2, feat1*feat2');
+\x ON
+SELECT * FROM result_table;
+</pre> Result: <pre class="result">
+-[ RECORD 1 ]+-------------------------------------------------------------
+category | 1
+ref_category | 0
+variables | {intercept,feat1,feat2}
+margins | {2.38176571752675,-0.0545733108729351,-0.0147264917310351}
+std_err | {0.851299967007829,0.0697049196489632,0.00374946341567828}
+z_stats | {2.79779843748643,-0.782919070099622,-3.92762646235104}
+p_values | {0.00514522099923651,0.43367463815468,8.57883141882439e-05}
+-[ RECORD 2 ]+-------------------------------------------------------------
+category | 2
+ref_category | 0
+variables | {intercept,feat1,feat2}
+margins | {-1.99279068434949,0.0922540608068343,0.0168049205501686}
+std_err | {0.742790306495022,0.0690712705200096,0.00202015384479213}
+z_stats | {-2.68284422524683,1.33563578767686,8.31863404536785}
+p_values | {0.00729989838349161,0.181668346802398,8.89828265128986e-17}
+</pre></li>
+</ol>
+<p><a class="anchor" id="notes"></a> </p><dl class="section note"><dt>Note</dt><dd>The <em>marginal_vars</em> argument is a list with the names matching those in 'x_design'. If no 'x_design' is present (i.e. no interaction and no indicator variables), then <em>marginal_vars</em> must be the indices (base 1) of variables in 'independent_varname'. Use <em>NULL</em> to use all independent variables. It is important to note that the <em>independent_varname</em> array in the underlying regression is assumed to start with a lower bound index of 1. Arrays that don't follow this would result in an incorrect solution.</dd></dl>
+<p><a class="anchor" id="background"></a></p><dl class="section user"><dt>Technical Background</dt><dd></dd></dl>
+<p>The standard approach to modeling dichotomous/binary variables (so \(y \in \{0, 1\} \)) is to estimate a generalized linear model under the assumption that \( y \) follows some form of Bernoulli distribution. Thus the expected value of \( y \) becomes, </p><p class="formulaDsp">
+\[ y = G(X' \beta), \]
+</p>
+<p>where G is the specified binomial distribution. For logistic regression, the function \( G \) represents the inverse logit function.</p>
+<p>In logistic regression: </p><p class="formulaDsp">
+\[ P = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x_1 + \dots \beta_j x_j)}} = \frac{1}{1 + e^{-z}} \implies \frac{\partial P}{\partial X_k} = \beta_k \cdot \frac{1}{1 + e^{-z}} \cdot \frac{e^{-z}}{1 + e^{-z}} \\ = \beta_k \cdot P \cdot (1-P) \]
+</p>
+<p>There are several methods for calculating the marginal effects for dichotomous dependent variables. This package uses the average of the marginal effects at every sample observation.</p>
+<p>This is calculated as follows: </p><p class="formulaDsp">
+\[ \frac{\partial y}{\partial x_k} = \beta_k \frac{\sum_{i=1}^n P(y_i = 1)(1-P(y_i = 1))}{n}, \\ \text{where}, P(y_i=1) = g(X^{(i)}\beta) \]
+</p>
+<p>We use the delta method for calculating standard errors on the marginal effects.</p>
+<p><a class="anchor" id="literature"></a></p><dl class="section user"><dt>Literature</dt><dd></dd></dl>
+<p>[1] mfx function in STATA: <a href="http://www.stata.com/help.cgi?mfx_option">http://www.stata.com/help.cgi?mfx_option</a></p>
+<p><a class="anchor" id="related"></a></p><dl class="section user"><dt>Related Topics</dt><dd></dd></dl>
+<p>File <a class="el" href="marginal_8sql__in.html" title="SQL functions for linear regression. ">marginal.sql_in</a> documenting the SQL functions.</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 Mon Jul 27 2015 20:37:45 for MADlib by
+ <a href="http://www.doxygen.org/index.html">
+ <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
+ </ul>
+</div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-madlib-site/blob/7258f51a/docs/latest/group__grp__matrix.html
----------------------------------------------------------------------
diff --git a/docs/latest/group__grp__matrix.html b/docs/latest/group__grp__matrix.html
new file mode 100644
index 0000000..9af2aa1
--- /dev/null
+++ b/docs/latest/group__grp__matrix.html
@@ -0,0 +1,556 @@
+<!-- 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.10"/>
+<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: Matrix Operations</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);
+ $(window).load(resizeHeight);
+</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 src="../mathjax/MathJax.js"></script>
+<!-- hack in the navigation tree -->
+<script type="text/javascript" src="navtree_hack.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 id="projectlogo"><a href="http://madlib.incubator.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.8</span>
+ </div>
+ <div id="projectbrief">User Documentation for 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.10 -->
+<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__matrix.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">Matrix Operations<div class="ingroups"><a class="el" href="group__grp__datatrans.html">Data Types and Transforms</a> » <a class="el" href="group__grp__arraysmatrix.html">Arrays and Matrices</a></div></div> </div>
+</div><!--header-->
+<div class="contents">
+<div class="toc"><b>Contents</b> </p><ul>
+<li class="level1">
+<a href="#description">Description</a> </li>
+<li class="level1">
+<a href="#operations">Matrix Operations</a> </li>
+<li class="level1">
+<a href="#glossary">Glossary of arguments</a> </li>
+<li class="level1">
+<a href="#examples">Examples</a> </li>
+<li class="level1">
+<a href="#related">Related Topics</a> </li>
+</ul>
+</div><p><a class="anchor" id="description"></a>This module provides a set of basic matrix operations for matrices that are too big to fit in memory. We provide two storage formats for a matrix:</p>
+<ul>
+<li>Dense: The matrix is represented as a distributed collection of 1-D arrays. An example 3x10 matrix would be the below table: <pre>
+ row_id | row_vec
+--------+-------------------------
+ 1 | {9,6,5,8,5,6,6,3,10,8}
+ 2 | {8,2,2,6,6,10,2,1,9,9}
+ 3 | {3,9,9,9,8,6,3,9,5,6}
+</pre></li>
+</ul>
+<p>A '<em>row</em>' column (called as <em>row_id</em> above) provides the row number of each row and a '<em>val</em>' column (called as <em>row_vec</em> above) provides each row as an array. <b>The <em>row</em> column should contain a series of integers from 1 to <em>N</em> with no duplicates, where <em>N</em> is the row dimensionality</b>.</p>
+<ul>
+<li>Sparse: The matrix is represented using the row and column indices for each non-zero entry of the matrix. This representation is useful for sparse matrices, containing multiple zero elements. Given below is an example of a sparse 4x7 matrix with just 6 out of 28 entries being non-zero. The dimensionality of the matrix is inferred using the max value in <em>row</em> and <em>col</em> columns. Note the last entry is included (even though it is 0) to provide the dimensionality of the matrix (indicating that the 4th row and 7th column contain all zeros). <pre>
+ row_id | col_id | value
+--------+--------+-------
+ 1 | 1 | 9
+ 1 | 5 | 6
+ 1 | 6 | 6
+ 2 | 1 | 8
+ 3 | 1 | 3
+ 3 | 2 | 9
+ 4 | 7 | 0
+(6 rows)
+</pre></li>
+</ul>
+<p><b>For sparse matrices, the <em>row</em> and <em>col</em> columns together should not contain a duplicate entry and the <em>val</em> column should be of scalar (non-array) data type</b>. <br />
+ For comparison, the dense representation of this matrix is shown below. Note the dimensionality of the dense matrix is 4 x 7 since the max value of <em>row</em> and <em>col</em> is 4 and 7 respectively, leading to all zeros in the last row and last column.   </p><pre>
+ row_id | row_vec
+--------+-------------------------
+ 1 | {9,0,0,0,6,6,0}
+ 2 | {8,0,0,0,0,0,0}
+ 3 | {3,9,0,0,0,0,0}
+ 4 | {0,0,0,0,0,0,0}
+</pre><dl class="section note"><dt>Note</dt><dd>The functions below support several numeric types (unless otherwise noted) including SMALLINT, INTEGER, BIGINT, DOUBLE PRECISION (FLOAT8), NUMERIC (internally casted into FLOAT8, loss of precision can happen).</dd></dl>
+<p><a class="anchor" id="operations"></a></p><dl class="section user"><dt>Matrix Operations</dt><dd></dd></dl>
+<p>Given below are the supported matrix operations. The meaning of the arguments and other terms are common to all functions and provided at the end of the list as a glossary.</p>
+<ul>
+<li><b>Representation</b> <pre class="syntax">
+-- Convert to sparse representation
+  <b>matrix_sparsify</b>( matrix_in, in_args, matrix_out, out_args)
+ 
+-- Convert to dense representation
+  <b>matrix_densify</b>( matrix_in, in_args, matrix_out, out_args)
+</pre></li>
+<li><b>Mathematical operations</b> <pre class="syntax">
+-- Matrix transposition
+  <b>matrix_trans</b>( matrix_in, in_args, matrix_out, out_args)
+ 
+-- Matrix addition
+  <b>matrix_add</b>( matrix_a, a_args, matrix_b, b_args, matrix_out, out_args)
+ 
+-- Matrix subtraction
+  <b>matrix_sub</b>( matrix_a, a_args, matrix_b, b_args, matrix_out, out_args)
+ 
+-- Matrix multiplication
+  <b>matrix_mult</b>( matrix_a, a_args, matrix_b, b_args, matrix_out, out_args)
+ 
+-- Element-wise matrix multiplication
+  <b>matrix_elem_mult</b>( matrix_a, a_args, matrix_b, b_args, matrix_out, out_args)
+ 
+-- Multiply matrix with scalar.
+  <b>matrix_scalar_mult</b>( matrix_in, in_args, scalar, matrix_out, out_args)
+ 
+-- Multiply matrix with vector.
+  <b>matrix_vec_mult</b>( matrix_in, in_args, vector)
+</pre></li>
+<li><b>Extraction/visitor methods</b> <pre class="syntax">
+-- Extract row from matrix given row index
+  <b>matrix_extract_row</b>( matrix_in, in_args, index)
+ 
+-- Extract column from matrix given column index
+  <b>matrix_extract_col</b>( matrix_in, in_args, index)
+</pre></li>
+<li><b>Reduction operations (aggregate across specific dimension)</b> <pre class="syntax">
+-- Get max value along dim. Also returns corresponding index if <em>fetch_index</em> = True
+  <b>matrix_max</b>( matrix_in, in_args, dim, matrix_out, fetch_index)
+ 
+-- Get min value along dim. Also returns corresponding index if <em>fetch_index</em> = True
+  <b>matrix_min</b>( matrix_in, in_args, dim, matrix_out, fetch_index)
+ 
+-- Get sum value along dimension from matrix.
+  <b>matrix_sum</b>( matrix_in, in_args, dim)
+ 
+-- Get mean value along dimension from matrix.
+  <b>matrix_mean</b>( matrix_in, in_args, dim)
+</pre></li>
+</ul>
+<p><a class="anchor" id="glossary"></a><b>Glossary</b> </p>
+<p>The table below provides a glossary of the terms used in the matrix operations.</p>
+<dl class="arglist">
+<dt>matrix_in, matrix_a, matrix_b </dt>
+<dd><p class="startdd">TEXT. Name of the table containing the input matrix.</p><ul>
+<li>For functions accepting one matrix, <em>matrix_in</em> denotes the input matrix.</li>
+<li>For functions accepting two matrices, <em>matrix_a</em> denotes the first matrix and <em>matrix_b</em> denotes the second matrix. These two matrices can <b>independently</b> be in either dense or sparse format. </li>
+</ul>
+<p class="enddd"></p>
+</dd>
+<dt>in_args, a_args, b_args </dt>
+<dd><p class="startdd">TEXT. A comma-delimited string containing multiple named arguments of the form "name=value". This argument is used as a container for multiple parameters related to a single matrix.</p>
+<p>The following parameters are supported for this string argument: </p><table class="output">
+<tr>
+<th>row </th><td>(Default: 'row_num') Name of the column containing row index of the matrix. </td></tr>
+<tr>
+<th>col </th><td>(Default: 'col_num') Name of the column containing column index of the matrix. </td></tr>
+<tr>
+<th>val </th><td>(Default: 'val') Name of the column containing the entries of the matrix. </td></tr>
+<tr>
+<th>trans </th><td>(Default: False) Boolean flag to indicate if the matrix should be transposed before the operation. This is currently functional only for <em>matrix_mult</em>. </td></tr>
+</table>
+<p>For example, the string argument with default values will be 'row=row_num, col=col_num, val=val, trans=False'. Alternatively, the string argument can be set to <em>NULL</em> or be blank ('') if default values are to be used. </p>
+<p class="enddd"></p>
+</dd>
+<dt>matrix_out </dt>
+<dd><p class="startdd">TEXT. Name of the table to store the result matrix. </p>
+<p class="enddd"></p>
+</dd>
+<dt>out_args </dt>
+<dd><p class="startdd">TEXT. A comma-delimited string containing named arguments of the form "name=value". This is an <b>optional parameter</b> and the default value is set as follows:</p><ul>
+<li>For functions with one input matrix, default = <em>in_args</em></li>
+<li>For functions with two input matrices, default = <em>a_args</em>.</li>
+</ul>
+<p>The following parameters are supported for this string argument: </p><table class="output">
+<tr>
+<th>row </th><td>Name of the column containing row index of the matrix. </td></tr>
+<tr>
+<th>col </th><td>Name of the column containing column index of the matrix. </td></tr>
+<tr>
+<th>val </th><td>Name of the column containing the entries of the matrix. </td></tr>
+</table>
+<p class="enddd"></p>
+</dd>
+<dt>index </dt>
+<dd><p class="startdd">INTEGER. An integer representing a row or column index of the matrix. Should be a number from 1 to <em>N</em>, where <em>N</em> is the maximum size of the dimension.</p>
+<p class="enddd"></p>
+</dd>
+<dt>dim </dt>
+<dd><p class="startdd">INTEGER. Should either be 1 or 2. This value indicates the dimension to operate along for the reduction/aggregation operations. <b>The value of <em>dim</em> should be interpreted as the dimension to be flattened i.e. whose length reduces to 1 in the result.</b> <br />
+ For <em>dim=1</em>, a reduction function on an <em>NxM</em> matrix operates on successive elements in each column and returns a single vector with <em>M</em> elements (i.e. matrix with just 1 row and <em>M</em> columns). <br />
+ For <em>dim=2</em>, a single vector is returned with <em>N</em> elements (i.e. matrix with just 1 column and <em>N</em> rows). </p>
+<p class="enddd"></p>
+</dd>
+</dl>
+<p><a class="anchor" id="examples"></a></p><dl class="section user"><dt>Examples</dt><dd></dd></dl>
+<ul>
+<li>Create some random data tables in dense format. <pre class="syntax">
+CREATE TABLE "mat_A" (
+ row_id integer,
+ row_vec integer[]
+);
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (1, '{9,6,5,8,5,6,6,3,10,8}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (2, '{8,2,2,6,6,10,2,1,9,9}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (3, '{3,9,9,9,8,6,3,9,5,6}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (4, '{6,4,2,2,2,7,8,8,0,7}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (5, '{6,8,9,9,4,6,9,5,7,7}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (6, '{4,10,7,3,9,5,9,2,3,4}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (7, '{8,10,7,10,1,9,7,9,8,7}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (8, '{7,4,5,6,2,8,1,1,4,8}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (9, '{8,8,8,5,2,6,9,1,8,3}');
+INSERT INTO "mat_A" (row_id, row_vec) VALUES (10, '{4,6,3,2,6,4,1,2,3,8}');
+
+CREATE TABLE "mat_B" (
+ row_id integer,
+ vector integer[]
+);
+INSERT INTO "mat_B" (row_id, vector) VALUES (1, '{9,10,2,4,6,5,3,7,5,6}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (2, '{5,3,5,2,8,6,9,7,7,6}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (3, '{0,1,2,3,2,7,7,3,10,1}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (4, '{2,9,0,4,3,6,8,6,3,4}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (5, '{3,8,7,7,0,5,3,9,2,10}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (6, '{5,3,1,7,6,3,5,3,6,4}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (7, '{4,8,4,4,2,7,10,0,3,3}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (8, '{4,6,0,1,3,1,6,6,9,8}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (9, '{6,5,1,7,2,7,10,6,0,6}');
+INSERT INTO "mat_B" (row_id, vector) VALUES (10, '{1,4,4,4,8,5,2,8,5,5}');
+</pre></li>
+<li>Transpose a matrix <pre class="syntax">
+SELECT madlib.matrix_trans('"mat_B"', 'row=row_id, val=vector',
+ 'mat_r');
+SELECT * FROM mat_r ORDER BY row_id;
+</pre> <pre class="result">
+-- Note the result matrix has inherited 'vector' as the name of value column
+ row_id | vector
+--------+-------------------------
+ 1 | {9,5,0,2,3,5,4,4,6,1}
+ 2 | {10,3,1,9,8,3,8,6,5,4}
+ 3 | {2,5,2,0,7,1,4,0,1,4}
+ 4 | {4,2,3,4,7,7,4,1,7,4}
+ 5 | {6,8,2,3,0,6,2,3,2,8}
+ 6 | {5,6,7,6,5,3,7,1,7,5}
+ 7 | {3,9,7,8,3,5,10,6,10,2}
+ 8 | {7,7,3,6,9,3,0,6,6,8}
+ 9 | {5,7,10,3,2,6,3,9,0,5}
+ 10 | {6,6,1,4,10,4,3,8,6,5}
+(10 rows)
+</pre></li>
+<li>Add the two matrices <pre class="syntax">
+SELECT madlib.matrix_add('"mat_A"', 'row=row_id, val=row_vec',
+ '"mat_B"', 'row=row_id, val=vector',
+ 'mat_r', 'val=vector');
+SELECT * FROM mat_r ORDER BY row_id;
+</pre> <pre class="result">
+ row_id | vector
+--------+-------------------------------
+ 1 | {18,16,7,12,11,11,9,10,15,14}
+ 2 | {13,5,7,8,14,16,11,8,16,15}
+ 3 | {3,10,11,12,10,13,10,12,15,7}
+ 4 | {8,13,2,6,5,13,16,14,3,11}
+ 5 | {9,16,16,16,4,11,12,14,9,17}
+ 6 | {9,13,8,10,15,8,14,5,9,8}
+ 7 | {12,18,11,14,3,16,17,9,11,10}
+ 8 | {11,10,5,7,5,9,7,7,13,16}
+ 9 | {14,13,9,12,4,13,19,7,8,9}
+ 10 | {5,10,7,6,14,9,3,10,8,13}
+(10 rows)
+</pre></li>
+<li>Multiply the two matrices <pre class="syntax">
+DROP TABLE IF EXISTS mat_r;
+SELECT madlib.matrix_mult('"mat_A"', 'row=row_id, val=row_vec',
+ '"mat_B"', 'row=row_id, val=vector, trans=true',
+ 'mat_r');
+SELECT * FROM mat_r ORDER BY row_id;
+</pre> <pre class="result">
+ row_id | row_vec
+--------+-------------------------------------------
+ 1 | {380,373,251,283,341,303,302,309,323,281}
+ 2 | {318,318,222,221,269,259,236,249,264,248}
+ 3 | {382,366,216,300,397,276,277,270,313,338}
+ 4 | {275,284,154,244,279,183,226,215,295,204}
+ 5 | {381,392,258,319,394,298,342,302,360,300}
+ 6 | {321,333,189,276,278,232,300,236,281,250}
+ 7 | {443,411,282,365,456,318,360,338,406,330}
+ 8 | {267,240,150,186,270,194,210,184,233,193}
+ 9 | {322,328,234,264,291,245,317,253,291,219}
+ 10 | {246,221,109,173,222,164,167,185,181,189}
+(10 rows)
+</pre></li>
+<li>Extract row and column from matrix given index <pre class="syntax">
+SELECT madlib.matrix_extract_row('"mat_A"', 'row=row_id, val=row_vec', 2) as row,
+ madlib.matrix_extract_col('"mat_A"', 'row=row_id, val=row_vec', 3) as col;
+</pre> <pre class="result">
+ row | col
+------------------------+-----------------------
+ {8,2,2,6,6,10,2,1,9,9} | {5,2,9,2,9,7,7,5,8,3}
+(1 rows)
+</pre></li>
+<li>Get min and max values along a specific dimension as well as corresponding indicies. Note that <em>dim=2</em> implies that the min and max is computed on each row returning a column vector i.e. the column (dim=2) is flattened. <pre class="syntax">
+SELECT madlib.matrix_max('"mat_A"', 'row=row_id, val=row_vec', 2, 'mat_max_r', true),
+ madlib.matrix_min('"mat_A"', 'row=row_id, val=row_vec', 2, 'mat_min_r', true);
+SELECT * from mat_max_r;
+SELECT * from mat_min_r;
+</pre> <pre class="result">
+ index | max
+-----------------------+---------------------------
+ {8,5,1,6,2,1,1,5,6,9} | {10,10,9,8,9,10,10,8,9,8}
+(1 rows)
+ 
+ index | min
+-----------------------+-----------------------
+ {7,7,0,8,4,7,4,6,7,6} | {3,1,3,0,4,2,1,1,1,1}
+(1 rows)
+</pre></li>
+<li>Element-wise multiplication between two matrices <pre class="syntax">
+SELECT madlib.matrix_elem_mult('"mat_A"', 'row=row_id, val=row_vec',
+ '"mat_B"', 'val=vector',
+ 'mat_r', 'val=vector');
+SELECT * FROM mat_r ORDER BY row_id;
+</pre> <pre class="result">
+ row_id | vector
+--------+---------------------------------
+ 1 | {81,60,10,32,30,30,18,21,50,48}
+ 2 | {40,6,10,12,48,60,18,7,63,54}
+ 3 | {0,9,18,27,16,42,21,27,50,6}
+ 4 | {12,36,0,8,6,42,64,48,0,28}
+ 5 | {18,64,63,63,0,30,27,45,14,70}
+ 6 | {20,30,7,21,54,15,45,6,18,16}
+ 7 | {32,80,28,40,2,63,70,0,24,21}
+ 8 | {28,24,0,6,6,8,6,6,36,64}
+ 9 | {48,40,8,35,4,42,90,6,0,18}
+ 10 | {4,24,12,8,48,20,2,16,15,40}
+</pre></li>
+<li>Get sum values along dimension. Sum is computed for each row (i.e. column is flattened since dim=2) <pre class="syntax">
+SELECT madlib.matrix_sum('"mat_A"', 'row=row_id, val=row_vec', 2);
+</pre> <pre class="result">
+ matrix_sum
+---------------------------------
+ {66,55,67,46,70,56,76,46,58,39}
+(1 rows)
+</pre></li>
+<li>Multiply matrix with a scalar <pre class="syntax">
+DROP TABLE IF EXISTS mat_r;
+SELECT madlib.matrix_scalar_mult('"mat_A"', 'row=row_id, val=row_vec', 3, 'mat_r');
+SELECT * FROM mat_r ORDER BY row_id;
+</pre> <pre class="result">
+ row_id | row_vec
+--------+---------------------------------
+ 0 | {27,18,15,24,15,18,18,9,30,24}
+ 1 | {24,6,6,18,18,30,6,3,27,27}
+ 2 | {9,27,27,27,24,18,9,27,15,18}
+ 3 | {18,12,6,6,6,21,24,24,0,21}
+ 4 | {18,24,27,27,12,18,27,15,21,21}
+ 5 | {12,30,21,9,27,15,27,6,9,12}
+ 6 | {24,30,21,30,3,27,21,27,24,21}
+ 7 | {21,12,15,18,6,24,3,3,12,24}
+ 8 | {24,24,24,15,6,18,27,3,24,9}
+ 9 | {12,18,9,6,18,12,3,6,9,24}
+(10 rows)
+</pre></li>
+<li>Multiply matrix with a vector <pre class="syntax">
+SELECT madlib.matrix_vec_mult('"mat_A"', 'row=row_id, val=row_vec',
+ array[1,2,3,4,5,6,7,8,9,10]);
+</pre> <pre class="result">
+ matrix_vec_mult
+-------------------------------------------
+ {365,325,358,270,377,278,411,243,287,217}
+(10 rows)
+</pre></li>
+<li><b>Examples with sparse representation</b>. The function calls are the same as before. <pre class="syntax">
+SELECT madlib.matrix_sparsify('"mat_B"', 'row=row_id, val=vector',
+ '"mat_B_sparse"', 'col=col_id, val=val');
+</pre></li>
+<li>Create a matrix in sparse format. <pre class="syntax">
+CREATE TABLE "mat_A_sparse" (
+ "rowNum" integer,
+ col_num integer,
+ entry integer
+);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (1, 1, 9);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (1, 2, 6);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (1, 7, 3);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (1, 8, 10);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (1, 9, 8);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (2, 1, 8);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (2, 2, 2);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (2, 3, 6);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (3, 5, 6);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (3, 6, 3);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (7, 1, 7);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (8, 2, 8);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (8, 3, 5);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (9, 1, 6);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (9, 2, 3);
+INSERT INTO "mat_A_sparse" ("rowNum", col_num, entry) VALUES (10, 10, 0);
+</pre></li>
+<li>Transpose a matrix in sparse format <pre class="syntax">
+-- Note the double quotes for '"rowNum"' required per PostgreSQL rules
+SELECT madlib.matrix_trans('"mat_A_sparse"', 'row="rowNum", val=entry',
+ 'matrix_r_sparse');
+SELECT "rowNum", col_num, entry FROM matrix_r_sparse ORDER BY col_num;
+</pre> <pre class="result">
+ rowNum | col_num | entry
+--------+---------+-------
+ 1 | 1 | 9
+ 2 | 1 | 6
+ 7 | 1 | 3
+ 8 | 1 | 10
+ 9 | 1 | 8
+ 1 | 2 | 8
+ 2 | 2 | 2
+ 3 | 2 | 6
+ 5 | 3 | 6
+ 6 | 3 | 3
+ 1 | 7 | 7
+ 2 | 8 | 8
+ 3 | 8 | 5
+ 1 | 9 | 6
+ 2 | 9 | 3
+ 10 | 10 | 0
+(16 rows)
+</pre></li>
+<li>Add two sparse matrices <pre class="syntax">
+SELECT madlib.matrix_add('"mat_A_sparse"', 'row="rowNum", val=entry',
+ '"mat_B_sparse"', 'row=row_id, col=col_id, val=val',
+ 'matrix_r_sparse', 'col=col_out');
+SELECT madlib.matrix_densify('matrix_r_sparse', 'row="rowNum", col=col_out, val=entry',
+ 'matrix_r');
+SELECT * FROM matrix_r ORDER BY "rowNum";
+</pre> <pre class="result">
+ rowNum | entry
+--------+---------------------------
+ 1 | {18,16,2,4,6,5,6,17,13,6}
+ 2 | {13,5,11,2,8,6,9,7,7,6}
+ 3 | {0,1,2,3,8,10,7,3,10,1}
+ 4 | {2,9,0,4,3,6,8,6,3,4}
+ 5 | {3,8,7,7,0,5,3,9,2,10}
+ 6 | {5,3,1,7,6,3,5,3,6,4}
+ 7 | {11,8,4,4,2,7,10,0,3,3}
+ 8 | {4,14,5,1,3,1,6,6,9,8}
+ 9 | {12,8,1,7,2,7,10,6,0,6}
+ 10 | {1,4,4,4,8,5,2,8,5,5}
+(10 rows)
+</pre></li>
+<li>Multiply two sparse matrices <pre class="syntax">
+SELECT madlib.matrix_mult('"mat_A_sparse"', 'row="rowNum", col=col_num, val=entry',
+ '"mat_B_sparse"', 'row=row_id, col=col_id, val=val, trans=true',
+ 'matrix_r');
+SELECT * FROM matrix_r ORDER BY "rowNum";
+</pre> <pre class="result">
+ rowNum | entry
+--------+-------------------------------------------
+ 1 | {260,216,137,180,190,156,138,222,174,159}
+ 2 | {104,76,14,34,82,52,72,44,64,40}
+ 3 | {51,66,33,36,15,45,33,21,33,63}
+ 4 | {0,0,0,0,0,0,0,0,0,0}
+ 5 | {0,0,0,0,0,0,0,0,0,0}
+ 6 | {0,0,0,0,0,0,0,0,0,0}
+ 7 | {63,35,0,14,21,35,28,28,42,7}
+ 8 | {90,49,18,72,99,29,84,48,45,52}
+ 9 | {84,39,3,39,42,39,48,42,51,18}
+ 10 | {0,0,0,0,0,0,0,0,0,0}
+(10 rows)
+</pre></li>
+</ul>
+<p><a class="anchor" id="related"></a></p><dl class="section user"><dt>Related Topics</dt><dd></dd></dl>
+<p>File <a class="el" href="array__ops_8sql__in.html" title="implementation of array operations in SQL ">array_ops.sql_in</a> documenting the array operations <a class="el" href="group__grp__array.html">Array Operations</a></p>
+<p>File <a class="el" href="matrix__ops_8sql__in.html" title="Implementation of matrix operations in SQL. ">matrix_ops.sql_in</a> for list of functions and usage. </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 Mon Jul 27 2015 20:37:45 for MADlib by
+ <a href="http://www.doxygen.org/index.html">
+ <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
+ </ul>
+</div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-madlib-site/blob/7258f51a/docs/latest/group__grp__matrix__factorization.html
----------------------------------------------------------------------
diff --git a/docs/latest/group__grp__matrix__factorization.html b/docs/latest/group__grp__matrix__factorization.html
new file mode 100644
index 0000000..8b2a4cc
--- /dev/null
+++ b/docs/latest/group__grp__matrix__factorization.html
@@ -0,0 +1,142 @@
+<!-- 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.10"/>
+<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: 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);
+ $(window).load(resizeHeight);
+</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 src="../mathjax/MathJax.js"></script>
+<!-- hack in the navigation tree -->
+<script type="text/javascript" src="navtree_hack.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 id="projectlogo"><a href="http://madlib.incubator.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.8</span>
+ </div>
+ <div id="projectbrief">User Documentation for 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.10 -->
+<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__matrix__factorization.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="summary">
+<a href="#groups">Modules</a> </div>
+ <div class="headertitle">
+<div class="title">Matrix Factorization<div class="ingroups"><a class="el" href="group__grp__datatrans.html">Data Types and Transforms</a> » <a class="el" href="group__grp__arraysmatrix.html">Arrays and Matrices</a></div></div> </div>
+</div><!--header-->
+<div class="contents">
+<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
+<table class="memberdecls">
+<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
+Modules</h2></td></tr>
+<tr class="memitem:group__grp__lmf"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__grp__lmf.html">Low-rank Matrix Factorization</a></td></tr>
+<tr class="memdesc:group__grp__lmf"><td class="mdescLeft"> </td><td class="mdescRight">Performs low-rank matrix factorization for an incomplete matrix. <br /></td></tr>
+<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
+<tr class="memitem:group__grp__svd"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="group__grp__svd.html">Singular Value Decomposition</a></td></tr>
+<tr class="memdesc:group__grp__svd"><td class="mdescLeft"> </td><td class="mdescRight">Performs factorization of dense, sparse, and block matrices. <br /></td></tr>
+<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
+</table>
+</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 Mon Jul 27 2015 20:37:45 for MADlib by
+ <a href="http://www.doxygen.org/index.html">
+ <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
+ </ul>
+</div>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-madlib-site/blob/7258f51a/docs/latest/group__grp__matrix__factorization.js
----------------------------------------------------------------------
diff --git a/docs/latest/group__grp__matrix__factorization.js b/docs/latest/group__grp__matrix__factorization.js
new file mode 100644
index 0000000..51d5bbd
--- /dev/null
+++ b/docs/latest/group__grp__matrix__factorization.js
@@ -0,0 +1,5 @@
+var group__grp__matrix__factorization =
+[
+ [ "Low-rank Matrix Factorization", "group__grp__lmf.html", null ],
+ [ "Singular Value Decomposition", "group__grp__svd.html", null ]
+];
\ No newline at end of file