spark-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject spark git commit: [SPARK-11959][SPARK-15484][DOC][ML] Document WLS and IRLS
Date Fri, 27 May 2016 20:16:41 GMT
Repository: spark
Updated Branches:
  refs/heads/branch-2.0 5dd1423f4 -> e6e2f293d

[SPARK-11959][SPARK-15484][DOC][ML] Document WLS and IRLS

## What changes were proposed in this pull request?
* Document ```WeightedLeastSquares```(normal equation) and ```IterativelyReweightedLeastSquares```.
* Copy ```L-BFGS``` documents from ```spark.mllib``` to ``````.

Due to the session ```Optimization of linear methods``` is used for developers, I think we
should provide the brief introduction of the optimization method, necessary references and
how it implements in Spark. It's not necessary to paste all mathematical formula and derivation
here. If developers/users want to learn more, they can track reference.

## How was this patch tested?
Document update, no tests.

Author: Yanbo Liang <>

Closes #13262 from yanboliang/spark-15484.

(cherry picked from commit a3550e3747e21c79a5110132dc127ee83879062a)
Signed-off-by: Joseph K. Bradley <>


Branch: refs/heads/branch-2.0
Commit: e6e2f293d6830ce118050e789773a09b3888fd30
Parents: 5dd1423
Author: Yanbo Liang <>
Authored: Fri May 27 13:16:22 2016 -0700
Committer: Joseph K. Bradley <>
Committed: Fri May 27 13:16:37 2016 -0700

 docs/                             | 85 ++++++++++++++++++--
 .../IterativelyReweightedLeastSquares.scala     |  2 +-
 2 files changed, 81 insertions(+), 6 deletions(-)
diff --git a/docs/ b/docs/
index 91731d7..1c5f844 100644
--- a/docs/
+++ b/docs/
@@ -4,10 +4,85 @@ title: Advanced topics -
 displayTitle: Advanced topics -
-# Optimization of linear methods
+* Table of contents
+# Optimization of linear methods (developer)
+## Limited-memory BFGS (L-BFGS)
+[L-BFGS]( is an optimization 
+algorithm in the family of quasi-Newton methods to solve the optimization problems of the
+`$\min_{\wv \in\R^d} \; f(\wv)$`. The L-BFGS method approximates the objective function locally
as a 
+quadratic without evaluating the second partial derivatives of the objective function to
construct the 
+Hessian matrix. The Hessian matrix is approximated by previous gradient evaluations, so there
is no 
+vertical scalability issue (the number of training features) unlike computing the Hessian
+explicitly in Newton's method. As a result, L-BFGS often achieves faster convergence compared
+other first-order optimizations.
-The optimization algorithm underlying the implementation is called
 [Orthant-Wise Limited-memory
-(OWL-QN). It is an extension of L-BFGS that can effectively handle L1
-regularization and elastic net.
+(OWL-QN) is an extension of L-BFGS that can effectively handle L1 and elastic net regularization.
+L-BFGS is used as a solver for [LinearRegression](api/scala/,
+and [MultilayerPerceptronClassifier](api/scala/
+MLlib L-BFGS solver calls the corresponding implementation in [breeze](
+## Normal equation solver for weighted least squares
+MLlib implements normal equation solver for [weighted least squares](
by [WeightedLeastSquares](
+Given $n$ weighted observations $(w_i, a_i, b_i)$:
+* $w_i$ the weight of i-th observation
+* $a_i$ the features vector of i-th observation
+* $b_i$ the label of i-th observation
+The number of features for each observation is $m$. We use the following weighted least squares
+minimize_{x}\frac{1}{2} \sum_{i=1}^n \frac{w_i(a_i^T x -b_i)^2}{\sum_{k=1}^n w_k} + \frac{1}{2}\frac{\lambda}{\delta}\sum_{j=1}^m(\sigma_{j}
+where $\lambda$ is the regularization parameter, $\delta$ is the population standard deviation
of the label
+and $\sigma_j$ is the population standard deviation of the j-th feature column.
+This objective function has an analytic solution and it requires only one pass over the data
to collect necessary statistics to solve.
+Unlike the original dataset which can only be stored in a distributed system,
+these statistics can be loaded into memory on a single machine if the number of features
is relatively small, and then we can solve the objective function through Cholesky factorization
on the driver.
+WeightedLeastSquares only supports L2 regularization and provides options to enable or disable
regularization and standardization.
+In order to make the normal equation approach efficient, WeightedLeastSquares requires that
the number of features be no more than 4096. For larger problems, use L-BFGS instead.
+## Iteratively reweighted least squares (IRLS)
+MLlib implements [iteratively reweighted least squares (IRLS)](
by [IterativelyReweightedLeastSquares](
+It can be used to find the maximum likelihood estimates of a generalized linear model (GLM),
find M-estimator in robust regression and other optimization problems.
+Refer to [Iteratively Reweighted Least Squares for Maximum Likelihood Estimation, and some
Robust and Resistant Alternatives]( for more information.
+It solves certain optimization problems iteratively through the following procedure:
+* linearize the objective at current solution and update corresponding weight.
+* solve a weighted least squares (WLS) problem by WeightedLeastSquares.
+* repeat above steps until convergence.
+Since it involves solving a weighted least squares (WLS) problem by WeightedLeastSquares
in each iteration,
+it also requires the number of features to be no more than 4096.
+Currently IRLS is used as the default solver of [GeneralizedLinearRegression](api/scala/
diff --git a/mllib/src/main/scala/org/apache/spark/ml/optim/IterativelyReweightedLeastSquares.scala
index 6ed193c..d732f53 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/optim/IterativelyReweightedLeastSquares.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/optim/IterativelyReweightedLeastSquares.scala
@@ -38,7 +38,7 @@ private[ml] class IterativelyReweightedLeastSquaresModel(
  * Implements the method of iteratively reweighted least squares (IRLS) which is used to
  * certain optimization problems by an iterative method. In each step of the iterations,
- * involves solving a weighted lease squares (WLS) problem by [[WeightedLeastSquares]].
+ * involves solving a weighted least squares (WLS) problem by [[WeightedLeastSquares]].
  * It can be used to find maximum likelihood estimates of a generalized linear model (GLM),
  * find M-estimator in robust regression and other optimization problems.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message